swagger-api / swagger-api/swagger-core

@Schema oneOf config is ignored when generate the api-docs

Open
#4,732 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

backlog
Dominant language
Java
Stars
7.5k
Forks
2.3k
Avg merge
18h 1m
Merged PRs (30d)
10

Description

    @Schema(oneOf = {Child1.class, Child2.class})
    private Parent obj;

The result is something like this

                    "MyPojo": {
                        "oneOf": [
                            {
                                "$ref": "#/components/schemas/Child1"
                            },
                            {
                                "$ref": "#/components/schemas/Child2"
                            },
                            {
                                "$ref": "#/components/schemas/Child3"
                            }
                        ]
                    },

Seems the result does not come from my config.

Also I think oneOf should take string($ref) instead class?

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

Use the Java @Schema(oneOf = {Child1.class, Child2.class}) example as a reproducer and trace how the schema generator combines annotation configuration with discovered subtypes. Compare the generated api-docs output with the declared classes, including whether Child3 is added and how oneOf references are represented. Done means the configured oneOf behavior is covered and the generated output matches the intended references.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.