swagger-api / swagger-api/swagger-codegen
Schemas using `allOf` and `required` do not generate properly in Java
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
If you have a schema that uses allOf like so:
allOf:
- $ref: '#/definitions/Base'
properties:
uuidProp:
type: string
format: uuid
stringProp:
type: string
required:
- uuidProp
- stringProp
where Base
properties:
baseProp:
type: string
required:
- baseProp
The generated code only respects the required property on the base schema and not the child schema. This generates code in java where the required property on the schema property in the child is false when it should be true.
Swagger-codegen version
3.0.22
Swagger declaration file content or url
allOf:
- $ref: '#/definitions/Base'
properties:
uuidProp:
type: string
format: uuid
stringProp:
type: string
required:
- uuidProp
- stringProp
where Base
properties:
baseProp:
type: string
required:
- baseProp
Command line used for generation
Steps to reproduce
generate swagger code targeting java using the above yaml using javax bean validation.
note that the pojo validation for the generated schema objects are not properly including the @NotNull validation annotation.
Related issues/PRs
Suggest a fix/enhancement
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce Java generation with the supplied allOf/required YAML and javax bean validation settings, then inspect the generated schema objects for the child properties. Confirm the issue by checking whether uuidProp and stringProp lack @NotNull while baseProp is handled. Done means child-schema required properties generate the expected @NotNull validation annotations.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100