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.89k stars 6.03k forks source link

[SPRING]Missing JsonTypeInfo Annotations with Swagger Generator 3.0.19 #10198

Closed rajeswarikolluri closed 3 years ago

rajeswarikolluri commented 4 years ago
Description

Issue noticed in generated models for inherited classes while using Swagger Code Generator version 3.0.19.

Swagger-codegen version

3.0.19

Swagger declaration file content or url

openapi: "3.0.0" info: description: "This is a sample server Petstore server. You can find out more about Swagger at http://swagger.io or on irc.freenode.net, #swagger. For this sample, you can use the api key special-key to test the authorization filters." version: "1.0.0" title: "Swagger Petstore" tags:

Suggest a fix/enhancement

Same works with Swagger Generator 3.0.16

rajeswarikolluri commented 4 years ago

model_3.0.19.zip model_3.0.16.zip

openapi: "3.0.0" info: description: "This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api keyspecial-key` to test the authorization filters." version: "1.0.0" title: "Swagger Petstore" tags:

rajeswarikolluri commented 4 years ago

Model of PET with Swagger Generator 3.0.16

@Validated @javax.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.SpringCodegen", date = "2020-04-23T11:28:27.017+05:30[Asia/Calcutta]") @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "pet_type", visible = true ) @JsonSubTypes({ @JsonSubTypes.Type(value = Cat.class, name = "Cat"), @JsonSubTypes.Type(value = Dog.class, name = "Dog"), }) public class Pet {

Model of PET with Swagger Generator 3.0.19 @Validated @javax.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.SpringCodegen", date = "2020-04-23T11:32:12.263+05:30[Asia/Calcutta]") public class Pet {

lucianogalvaodesousa commented 4 years ago

The same issue happens with me. Until version 3.0.18 the @JsonTypeInfo was put into the class, after this version, not is putting.

Version: 3.0.18

@Validated @javax.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.SpringCodegen", date = "2020-07-02T15:12:56.488-03:00[America/Sao_Paulo]") @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "tipoPessoa", visible = true ) @JsonSubTypes({ @JsonSubTypes.Type(value = PessoaJuridica.class, name = "PessoaJuridica"), @JsonSubTypes.Type(value = PessoaFisica.class, name = "PessoaFisica"), }) public class Pessoa { ...

===============================================================================

Version: 3.0.19

@Validated @javax.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.SpringCodegen", date = "2020-07-02T15:00:31.725-03:00[America/Sao_Paulo]") public class Pessoa { /**

openapi: 3.0.0 servers:

pablo-ml commented 4 years ago

The same happened to me. It works in version 3.0.18, but fails in versions 3.0.19 and 3.0.20.

rajeswarikolluri commented 3 years ago

Similar issue raised - https://github.com/swagger-api/swagger-codegen-generators/issues/686

mike03081972 commented 3 years ago

Hi all,

For me no codegen cli v3 version are generating the jackson @JsonTypeInfo

I have tested version : 17 -> 21

Using this command line :

java -Dmodels -jar swagger-codegen-cli-3.0.18.jar generate -l java -i rest-api-v3-light.yaml -o generated

 or

java -Dmodels -jar swagger-codegen-cli-3.0.18.jar generate -l spring -i rest-api-v3-light.yaml -o generated

Any idea ?

`openapi: 3.0.2 info: version: 1.0.0 title: Sample API components: schemas:

FloatKeyframeParameter:
  type: object
  required:
    - offset
    - value
  properties:
    offest:
      type: string
      format: int64
    value:
      type: number
      format: float

Shape:
  type: object
  properties:
    shape:
      oneOf:
        - $ref: '#/components/schemas/RectangleShape'
        - $ref: '#/components/schemas/CircularShape'
      discriminator:
        propertyName: objectType

RectangleShape:
  type: object
  required:
    - objectType
    - offset
    - value
  properties:
    objectType:
      type: string
      default: RectangleShape
    x:
      type: array
      items:
        $ref: '#/components/schemas/FloatKeyframeParameter'
    y:
      type: array
      items:
        $ref: '#/components/schemas/FloatKeyframeParameter'
    w:
      type: array
      items:
        $ref: '#/components/schemas/FloatKeyframeParameter'
    h:
      type: array
      items:
        $ref: '#/components/schemas/FloatKeyframeParameter'

CircularShape:
  type: object
  required:
    - objectType
    - offset
    - value
  properties:
    objectType:
      type: string
      default: CircularShape
    x:
      type: array
      items:
        $ref: '#/components/schemas/FloatKeyframeParameter'
    y:
      type: array
      items:
        $ref: '#/components/schemas/FloatKeyframeParameter'
    r:
      type: array
      items:
        $ref: '#/components/schemas/FloatKeyframeParameter'

`