swagger-api / swagger-api/swagger-codegen
[JAVA] requestBody's with multiple options for content generate duplicate methods in Java classes
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
Swagger-codegen is generating duplicate methods in a class when multiple request bodies are defined. This seems to only happen when the title and/or description is included in the scheme for the request body.
error output on packaging
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /Users/cisom/dev/workspace/swagger-codegen/samples/src/main/java/com/sample/api/DefaultApi.java:[183,37] method postDataCall(java.lang.Object,com.sample.ProgressResponseBody.ProgressListener,com.sample.ProgressRequestBody.ProgressRequestListener) is already defined in class com.sample.api.DefaultApi
[ERROR] /Users/cisom/dev/workspace/swagger-codegen/samples/src/main/java/com/sample/api/DefaultApi.java:[225,38] method postDataValidateBeforeCall(java.lang.Object,com.sample.ProgressResponseBody.ProgressListener,com.sample.ProgressRequestBody.ProgressRequestListener) is already defined in class com.sample.api.DefaultApi
[ERROR] /Users/cisom/dev/workspace/swagger-codegen/samples/src/main/java/com/sample/api/DefaultApi.java:[246,17] method postData(java.lang.Object) is already defined in class com.sample.api.DefaultApi
[ERROR] /Users/cisom/dev/workspace/swagger-codegen/samples/src/main/java/com/sample/api/DefaultApi.java:[257,30] method postDataWithHttpInfo(java.lang.Object) is already defined in class com.sample.api.DefaultApi
[ERROR] /Users/cisom/dev/workspace/swagger-codegen/samples/src/main/java/com/sample/api/DefaultApi.java:[270,37] method postDataAsync(java.lang.Object,com.sample.ApiCallback<java.lang.Void>) is already defined in class com.sample.api.DefaultApi
Swagger-codegen version
3.0.34 and 3.0.35-SNAPSHOT
Swagger declaration file content or url
sample.yaml
openapi: 3.0.2
info:
title: Sample Service
version: '1.0'
description: Sample yaml file to recreate bug
servers:
- url: 'http://127.0.0.1'
description: local
paths:
/sample/v1/paths:
post:
summary: post to path
operationId: post_data
responses:
'200':
description: received
description: Send data to the Sample Service
requestBody:
content:
sample.com/syslog:
schema:
type: string
title: SysSysloglog
description: "Syslog messages separated by `\\n`"
format: binary
sample.org/unified:
schema:
type: string
title: Unified
description: "Unified records"
format: binary
description: 'Request Body'
required: true
config file
{
"apiPackage": "com.sample.api",
"modelPackage": "com.sample.model",
"invokerPackage": "com.sample",
"useRuntimeException": "true",
"java11": "true",
"parcelableModel": "false"
}
Command line used for generation
swagger-codegen generate -i sample.yaml -l java -c config.json
Steps to reproduce
Copy the sample.yaml and config.json below and run the following command.
swagger-codegen generate -i sample.yaml -l java -c config.json
Once generated mnv package will generate the error above showing the duplicate methods in the class.
Related issues/PRs
N/A
Suggest a fix/enhancement
Please fix this to allow title and description to be added to the schema of multiple request bodies.
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 sample.yaml and config.json, then run swagger-codegen generate -i sample.yaml -l java -c config.json to reproduce the issue. Inspect the generated samples/src/main/java/com/sample/api/DefaultApi.java and verify that packaging no longer reports duplicate postData methods for the multiple request-body content options.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100