OpenAPITools / OpenAPITools/openapi-generator

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

Open
#1,713 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug Server: Spring
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with api.yaml and schema.yaml using the documented OpenAPI Generator command and Spring generator. Compare the generated models with the referenced Animal, Cat, and Dog schemas, then review the related swagger-api/swagger-parser#970 report. Done means generation includes Cat and Dog when AnimalFarm is referenced through the root API definition.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi, spring
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.