OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.64k stars 6.53k forks source link

[BUG] [Spring] Externally defined subtypes are not resolved when referenced through the root #1713

Open ErikGrimes opened 5 years ago

ErikGrimes commented 5 years ago
Description

Given the setup below, the generator only generates Animal and AnimalFarmEntry. The should also generate Cat and Dog.

openapi-generator version

3.3.4

OpenAPI declaration file content or url

api.yaml

openapi: 3.0.0
info:
  title: Sample API
  description: API description in Markdown.
  version: 1.0.0
paths:
  /animals:
    get:
      summary: Get an animal.
      description: Optional extended description in Markdown.
      responses:
        200:
          description: OK
          content:
            application/json:
              schema:
                $ref: 'schema.yaml#/components/schemas/AnimalFarm'

schema.yaml

components:
  schemas:
    Dog:
      allOf:
        - $ref: '#/components/schemas/Animal'
        - type: object
          properties:
            breed:
              type: string
    Cat:
      allOf:
        - $ref: '#/components/schemas/Animal'
        - type: object
          properties:
            breed:
              type: string
    Animal:
      type: object
      discriminator:
        propertyName: className
      required:
        - className
      properties:
        className:
          type: string
        color:
          type: string
          default: red
    AnimalFarm:
      type: array
      items:
        $ref: '#/components/schemas/AnimalFarmEntry'
    AnimalFarmEntry:
      type: object
      properties:
        animal:
          $ref: "#/components/schemas/Animal"
Command line used for generation

openapi-generate generate -g spring -i api.yaml -i generated

Steps to reproduce

Invoke the generator above using the provided inputs.

Suggest a fix

This is appears to be an issue with the Swagger parser. I've filed swagger-api/swagger-parser#970.

auto-labeler[bot] commented 5 years ago

👍 Thanks for opening this issue! 🏷 I have applied any labels matching special text in your issue.

Please review the labels and make any necessary changes.

keenanpepper commented 4 years ago

See https://github.com/swagger-api/swagger-parser/pull/1333 for a PR to fix this issue if the discriminator has a mapping defined.