swagger-api / swagger-api/swagger-codegen

[Java] CodegenModel's discriminator property is not set for a model when it is composed using allOf

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

Nobody has claimed this yet.

Client: Java Feature: Composition / Inheritance Issue: Bug
Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

When a model A is composed from another model B, which has declared a discriminator,
discriminator field of CodegenModel for A should be value of discriminator field of model B.
But, it is set to null.

Consider test case "handle inheritance from composed model" in CodegenTest.java which uses
src/test/resources/2_0/allOfTest.yaml .
child.discriminator should be "disc". But it is null.

Swagger-codegen version

2.2.0

Swagger declaration file content or url

src/test/resources/2_0/allOfTest.yaml

Command line used for generation

client is java.

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 the “handle inheritance from composed model” test in CodegenTest.java and the fixture at src/test/resources/2_0/allOfTest.yaml. Run that test and trace how the composed model’s discriminator is represented in CodegenModel. Done means the child model’s discriminator is "disc" rather than null.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.