swagger-api / swagger-api/swagger-codegen
Inline objects are not being generated
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Hello
We are attempting to generate a set of API java classes from a spec document provided by the client. In this file there are many models which are being defined directly inline the parent object instead of in the "definitions" section.
We are trying to generate Java classes.
Below is an example of typical case in the spec file.
{
"FareDetailsBySegment": {
"title": "FareDetailsBySegment",
"description": "Fare details of the segment",
"required": [
"segmentId"
],
"properties": {
"segmentId": {
"type": "string",
"example": "1",
"description": "Id of the segment"
},
"isAllotment": {
"description": "True if the corresponding booking class is in an allotment",
"type": "boolean",
"example": true
},
"allotmentDetails": {
"title": "AllotmentDetails",
"type": "object",
"properties": {
"tourName": {
"type": "string"
},
"tourReference": {
"type": "string"
}
}
},
"sliceDiceIndicator": {
"$ref": "#/definitions/SliceDiceIndicator"
},
"additionalServices": {
"type": "object",
"title": "AdditionalServicesRequest",
"properties": {
"chargeableCheckedBags": {
"title": "chargeableCheckedBags",
"$ref": "#/definitions/BaggageAllowance",
"description": "Details of chargeable checked bags"
},
"chargeableSeatNumber": {
"type": "string",
"description": "seat number",
"example": "33D",
"pattern": "[1-9][0-9]{0,2}[A-Z]?"
},
"otherServices": {
"type": "array",
"description": "Other services to add",
"items": {
"$ref": "#/definitions/ServiceName"
},
"example": [
"PRIORITY_BOARDING"
]
}
}
}
}
}
}
From the example above, the generated Java code for allotmentDetails and additionalServices looks like:
@JsonProperty("allotmentDetails")
private Object allotmentDetails = null;
@JsonProperty("additionalServices")
private Object additionalServices = null;
and none of the classes: AllotmentDetails or AdditionalServices is being generated.
Is there anyway to get the generator to create these inline classes? Or the only solution is to define those objects in the "definitions" section and then use refs to it ?
thanks a lot
Javier
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
Start with the generator's handling of inline object schemas in the supplied OpenAPI example, comparing the generated Java fields with equivalent schemas placed in the definitions section. Done means inline allotmentDetails and additionalServices produce named Java classes instead of Object fields, while referenced definitions continue to generate correctly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100