swagger-api / swagger-api/swagger-codegen

Multiple anyOf implementations not supported

Open
#9,964 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

Description

My model has multiple anyOf implementations, however in any Codegen generator only the 'last' one is created as an interface.

Swagger-codegen version

3.0.14

Swagger declaration file content or url
openapi: 3.0.0
info:
  title: Sample Double Interface
  version: 0.0.1
paths:
components:
  schemas:
    PartOne:
      properties:
        name:
          type: string
          description: A test description
    PartTwo:
      properties:
        id:
          type: string
    PartThree:
      properties:
        otherId:
          type: string
    PartFour:
      properties:
        otherIdPart:
          type: string
    PartMaster:
      properties:
        origin:
          anyOf:
            - $ref: '#/components/schemas/PartThree'
            - $ref: '#/components/schemas/PartFour'
        otherOrigin:
          anyOf:
            - $ref: '#/components/schemas/PartThree'
            - $ref: '#/components/schemas/PartFour'
Command line used for generation

swagger-codegen generate -c java-generator-opts.json -i model/test.yaml -Dmodels --template-engine handlebars -l java

Suggest a fix/enhancement

I think whatever is building the map is using the same key

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

Start with model/test.yaml and java-generator-opts.json, then run the reported swagger-codegen generate command for the Java generator. Compare the generated representations of origin and otherOrigin, checking whether both anyOf implementations are retained rather than only the last one. Done means both properties generate the expected interfaces.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.