Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allOf is not appearing properly in generated schema #3197

Closed
zaverrabadiya opened this issue Apr 30, 2019 · 2 comments
Closed

allOf is not appearing properly in generated schema #3197

zaverrabadiya opened this issue Apr 30, 2019 · 2 comments

Comments

@zaverrabadiya
Copy link

I am using io.swagger.core.v3 2.0.8 to generate OpenAPI Schema. I am using inheritance with polymorphism to define my models. When I generate the schema, subtype models are not generated properly. allOf should have model definition as child of it (inline) but in my schema allOf and rest of the subtype schema are siblings. Which breaks generation of client, particularly properties are not generated.

For example,
my subtype RaceCar looks like: RaceCar: required: - carMetaData type: object properties: id: type: integer format: int64 model: type: string allOf: - $ref: '#/components/schemas/Car'

which has allOf, type and properties as siblings.

It supposed to be: RaceCar: allOf: - $ref: '#/components/schemas/Car' - type: object required: - id properties: id: type: integer format: int64 model: type: string x-translation: - model

Complete Example

My java models

@Schema(discriminatorProperty = "type", discriminatorMapping = {
        @DiscriminatorMapping(value = "RaceCar", schema = RaceCar.class),
        @DiscriminatorMapping(value = "SportCar", schema = SportCar.class)
},
oneOf = {
        RaceCar.class,
        SportCar.class
})
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME,
        property = "type")
@JsonSubTypes({
    @JsonSubTypes.Type(value = RaceCar.class),
    @JsonSubTypes.Type(value = SportCar.class)
})
public abstract class Car {

    private CarMetaData carMetaData;

    public CarMetaData getCarMetaData() { return carMetaData; }
}

public class RaceCar extends Car {

    @JsonProperty(required = true)
    public Long id;

    public String model;

    @Schema(required = true)
    public CarMetaData carMetaData;
}

public class SportCar extends Car {

    @JsonProperty(required = true)
    public Long id;

    public String model;
}

Actual generated schema

schemas:
    Car:
      type: object
      properties:
        carMetaData:
          $ref: '#/components/schemas/CarMetaData'
      discriminator:
        propertyName: type
        mapping:
          RaceCar: '#/components/schemas/RaceCar'
          SportCar: '#/components/schemas/SportCar'
      oneOf:
      - $ref: '#/components/schemas/RaceCar'
      - $ref: '#/components/schemas/SportCar'
    CarMetaData:
      required:
      - translation
      type: object
      properties:
        translation:
          type: array
          items:
            type: string
    RaceCar:
      required:
      - carMetaData
      type: object
      properties:
        id:
          type: integer
          format: int64
        model:
          type: string
      allOf:
      - $ref: '#/components/schemas/Car'
    SportCar:
      required:
      - id
      type: object
      properties:
        id:
          type: integer
          format: int64
        model:
          type: string
      allOf:
      - $ref: '#/components/schemas/Car'

Expected schema

...
RaceCar:
      allOf:
        - $ref: '#/components/schemas/Car'
        - type: object
          required:
            - id
          properties:
            id:
              type: integer
              format: int64
            model:
              type: string
          x-translation:
            - model

    SportCar:
      allOf:
        - $ref: '#/components/schemas/Car'
        - type: object
          properties:
            id:
              type: integer
              format: int64
            model:
              type: string
@nitinjavakid
Copy link

Same issue faced by me too

@frantuma
Copy link
Member

thanks for reporting this, also duplicates #3030 and #3063; fixed in #3262

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants