swagger-api / swagger-api/swagger-codegen
Ignore repeated ContentType and Accept header generation in specific API code generation
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
Follow Global Content and Accept Types and only add content/accept types if global types are overridden
Swagger-codegen version
2.4.0
Swagger declaration file content or url
https://github.com/OAI/OpenAPI-Specification/blob/master/examples/v2.0/yaml/petstore.yaml
Yaml Code
post:
summary: Create a pet
operationId: createPets
tags:
- pets
responses:
"201":
description: Null response
default:
description: unexpected error
schema:
$ref: '#/definitions/Error'
Generated Code
public ApiResponse<Object> CreatePets ()
{
...
// to determine the Content-Type header
String[] httpContentTypes = new String[] {
"application/json"
};
String httpContentType = this.Configuration.ApiClient.SelectHeaderContentType(httpContentTypes);
if (httpContentType != null)
request.SetHeader("Accept", httpContentType);
// to determine the Accept header
String[] httpHeaderAccepts = new String[] {
"application/json"
};
String httpHeaderAccept = this.Configuration.ApiClient.SelectHeaderAccept(httpHeaderAccepts);
if (httpHeaderAccept != null)
request.SetHeader("Accept", httpHeaderAccept);
...
}
Command line used for generation
java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate
-i https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v2.0/yaml/petstore.yaml
-l csharp
-o ./tmp/DefaultGeneration \
Steps to reproduce
Just generare with csharp as language
Suggest a fix/enhancement
Please consider only if the content types are overriden in specific API. Else, there is lot of code that is getting bloated which isn't required. As there will be a global Accept/Content-type's defined, it can be ignored in each api code generation. If there is specific data defined with in api, it can be generated.
Please consider it similar to authMethods tag in DefaultGenerator.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 with DefaultGenerator.java and the csharp generation path, using the petstore.yaml example and the reported generated CreatePets method as the reference case. Check how global and operation-level content and Accept types are represented, then verify that generation omits repeated per-operation header code unless an operation overrides the global types.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, java
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100