swagger-api / swagger-api/swagger-codegen

Wrong generation with allOf if $ref is last

Open
#12,224 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

With this little change in test/resources/3_0_0/petstore.yaml

    Dog:
      allOf:
        - type: object
          properties:
            bark:
              type: boolean
            breed:
              type: string
              enum: [Dingo, Husky, Retriever, Shepherd]
        - $ref: '#/components/schemas/Pet'
    Cat:
      allOf:
        - $ref: '#/components/schemas/Pet'
        - type: object
          properties:
            hunts:
              type: boolean
            age:
              type: integer

it generates

public class Cat extends Pet implements OneOfAllPetsResponseItems, OneOfSinglePetResponsePet {

but

public class Dog implements OneOfAllPetsResponseItems, OneOfSinglePetResponsePet {

Semantically, both are the same, so there is no reason for this difference. Same time, docs for this variant is generating fine.

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

Read test/resources/3_0_0/petstore.yaml and reproduce generation with the two allOf variants shown in the issue. Compare the generated Java for Dog and Cat; done means equivalent schemas generate consistent inheritance while the existing documentation output remains correct.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
backend-api-design, devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.