swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
16.88k stars 6.03k forks source link

[JAVA] requestBody's with multiple options for content generate duplicate methods in Java classes #11848

Open carlisom opened 2 years ago

carlisom commented 2 years ago
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.

dacr commented 1 year ago

we have exactly the same issue

manoj14581 commented 10 months ago

@carlisom We are facing the same issue, did you get any solution?

aabdelli03 commented 5 months ago

is there any solution plzz ?? i'm blocked with that