swagger-api / swagger-api/swagger-codegen
[Java] Inherited properties are evicted when using oneOf.
@gracekarina is already working on this.
Since Apr 22, 2020.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
IF Pet object defines a petType property
AND Cat and Dog include Pet through the allOf
AND APet object includes both Cat and Dog through the oneOf
THEN property petType is missing from the object APet
Swagger-codegen version
Online version AND swagger-codegen-cli-3.0.0-20180717.153005-90.jar
Swagger declaration
openapi: 3.0.0
info:
version: 0.0.0
title: Example
paths:
/randomPet:
get:
responses:
'200':
description: Random pet
content:
application/json:
schema:
$ref: '#/components/schemas/APet'
components:
schemas:
APet:
oneOf:
- $ref: '#/components/schemas/Cat'
- $ref: '#/components/schemas/Dog'
discriminator:
propertyName: petType
Pet:
type: object
required:
- petType
properties:
petType: { type: string }
Dog:
allOf:
- $ref: '#/components/schemas/Pet'
- type: object
properties:
bark: { type: boolean }
Cat:
allOf:
- $ref: '#/components/schemas/Pet'
- type: object
properties:
age: { type: number }
Resulting Java Bean
(with everything else stripped)
public class APet {
private BigDecimal age = null;
private Boolean bark = null;
}
Expected Java Bean
This part is tricky. In principle, I'd rather have just a Pet object that could be further casted into a Cat or a Dog. In this case the object APet should not even exist. But at the very minimum, the property must not be lost:
public class APet {
private BigDecimal age = null;
private Boolean bark = null;
private String petType = null;
}
or
public class APet extends Pet {
private BigDecimal age = null;
private Boolean bark = null;
}
Command line used for generation
java -jar swagger-codegen-cli-3.0.0-20180717.153005-90.jar generate -DhideGenerationTimestamp=true -l java -i openapi.yaml
Related issue:
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.
Assessment
This issue has not been assessed yet.