Skip to content

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

Open

Description

@carlisom
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.

Activity

  1. dacr commented on Dec 13, 2022

    @dacr

    we have exactly the same issue

  2. manoj14581 commented on Oct 22, 2023

    @manoj14581

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

  3. aabdelli03 commented on Apr 8, 2024

    @aabdelli03

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

  4. b-smets commented on Dec 30, 2024

    @b-smets

    +1 on this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions