swagger-api / swagger-api/swagger-codegen
[C#] Bug generating client with application/x-www-form-urlencoded request body
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
Client SDK codegen generates an invalid C# ApiXXXX object that doesn't compile when the request body is configured to be application/x-www-form-urlencoded. The generated XXXXPostWithHttpInfo method does not contain arguments that are referenced within the method.
Swagger-codegen version
Version: SwaggerHub portal
Swagger declaration file content or url
Here is a sample endpoint, this is based off an example from the docs
openapi: 3.0.0
info:
version: 1.0.0
title: Bug Example
paths:
/example:
post:
requestBody:
required: true
content:
application/x-www-form-urlencoded:
schema:
type: object
properties:
name: # <!--- form field name
type: string
fav_number: # <!--- form field name
type: integer
required:
- name
- email
responses:
'200':
description: OK
It generates the following output, which does not compile, due to the request body parameters not being generated:
public ApiResponse<Object> ExamplePostWithHttpInfo ()
{
// omitted
// name and favNumber are not declared
if (name != null) localVarFormParams.Add("name", this.Configuration.ApiClient.ParameterToString(name)); // form parameter
if (favNumber != null) localVarFormParams.Add("fav_number", this.Configuration.ApiClient.ParameterToString(favNumber)); // form parameter
// omitted
}
Command line used for generation
This was generated using the SwaggerHub Export menu
Steps to reproduce
The following SwaggerHub codegen options were used:
- .NET 1.3 Standard Compatible
- netCoreProjectFile
- Custom package name
Related issues/PRs
This seems to be related to the issue reported at #8346 but this is different in that it is for application/x-www-form-urlencoded and C# instead of multipart/form-data and Java.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by generating the C# client from the supplied OpenAPI 3.0 example with the listed SwaggerHub options, then inspect the generated ApiXXXX object's XXXXPostWithHttpInfo method. Compare its form-parameter references with the method arguments; done means the generated client compiles without undeclared name or favNumber references.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, openapi
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100