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

Spring Model POJOs not being generated for matching schemas with different titles. #5171

Open rmharris157 opened 7 years ago

rmharris157 commented 7 years ago
Description

Not sure why, but when I create two path that have identical structures other than the name of the title, only the first titled object is generated.

Swagger-codegen version

Codegen 2.2.2:

Swagger declaration file content or url

swagger: '2.0'

info:
  title: API
  version: "0.0.1"

paths:
  /app/alive:
    get:
      responses:
        '200':
          description: OK
          schema:
            title: AppHealthCheckResult
            properties:
              header:
                $ref: '#/definitions/ResponseHeader'
              result:
                $ref: '#/definitions/GenericKeyValue'

  /app/config:
    get:
      responses:
        '200':
          description: OK
          schema:
            title: GetAppConfigKeyResponse
            properties:
              header:
                $ref: '#/definitions/ResponseHeader'
              result:
                $ref: '#/definitions/GenericKeyValue'

definitions:

  ResponseHeader:
    type: object
    properties:
      request-id:
        type: string
        description: Header for all response

  GenericKeyValue:
    type: object
    properties:
      name:
        type: string
        description: something
Command line used for generation
java -jar ../tools/swagger-codegen-cli-2.2.2.jar generate -i missing-models.yaml -l spring
Steps to reproduce

Using above the following is rendered...

I would also expect a model for GetAppConfigKeyResponse.java to be created.


[main] INFO io.swagger.parser.Swagger20Parser - reading from missing-models.yaml
[main] WARN io.swagger.codegen.ignore.CodegenIgnoreProcessor - Directory does not exist, or is inaccessible. No file will be evaluated.
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /Users/roberhr/demo/codegen-bug/target/src/main/java/io/swagger/model/AppHealthCheckResult.java
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /Users/roberhr/demo/codegen-bug/target/src/main/java/io/swagger/model/GenericKeyValue.java
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /Users/roberhr/demo/codegen-bug/target/src/main/java/io/swagger/model/ResponseHeader.java
[main] WARN io.swagger.codegen.DefaultCodegen - Empty operationId found for path: get /app/alive. Renamed to auto-generated operationId: appAliveGet
[main] WARN io.swagger.codegen.DefaultCodegen - Empty operationId found for path: get /app/config. Renamed to auto-generated operationId: appConfigGet
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /Users/roberhr/demo/codegen-bug/target/src/main/java/io/swagger/api/AppApiController.java
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /Users/roberhr/demo/codegen-bug/target/src/main/java/io/swagger/api/AppApi.java
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /Users/roberhr/demo/codegen-bug/target/pom.xml
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /Users/roberhr/demo/codegen-bug/target/README.md
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /Users/roberhr/demo/codegen-bug/target/src/main/java/io/swagger/configuration/HomeController.java
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /Users/roberhr/demo/codegen-bug/target/src/main/java/io/swagger/Swagger2SpringBoot.java
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /Users/roberhr/demo/codegen-bug/target/src/main/java/io/swagger/RFC3339DateFormat.java
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /Users/roberhr/demo/codegen-bug/target/src/main/resources/application.properties
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /Users/roberhr/demo/codegen-bug/target/src/main/java/io/swagger/api/ApiException.java
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /Users/roberhr/demo/codegen-bug/target/src/main/java/io/swagger/api/ApiResponseMessage.java
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /Users/roberhr/demo/codegen-bug/target/src/main/java/io/swagger/api/NotFoundException.java
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /Users/roberhr/demo/codegen-bug/target/src/main/java/io/swagger/api/ApiOriginFilter.java
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /Users/roberhr/demo/codegen-bug/target/src/main/java/io/swagger/configuration/SwaggerDocumentationConfig.java
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /Users/roberhr/demo/codegen-bug/target/.swagger-codegen-ignore

##### Suggest a Fix
I'm not sure but it seems to me like there is a map collision or something.
wing328 commented 7 years ago

Not sure why, but when I create two path that have identical structures other than the name of the title, only the first titled object is generated.

I think that's because there are some logics in code gen to name the inline model with the same name if the properties are the same.

In your case, please try to define the models in a separate section instead of doing it inline.

rmharris157 commented 7 years ago

I thought that was supposed to be overridden by the title property.

On Apr 5, 2017, at 10:14 AM, wing328 notifications@github.com wrote:

Not sure why, but when I create two path that have identical structures other than the name of the title, only the first titled object is generated.

I think that's because there are some logics in code gen to name the inline model with the same name if the properties are the same.

In your case, please try to define the models in a separate section instead of doing it inline.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/swagger-api/swagger-codegen/issues/5171#issuecomment-291874762, or mute the thread https://github.com/notifications/unsubscribe-auth/AMQSR8-7_ee_opwlzwoOwaslIInpX3oLks5rs6HjgaJpZM4MlscN.

wing328 commented 7 years ago

Agree with you it's a bug. Please use the workaround for the time being.

If you've time to contribute a fix, I can show you some good starting points.