OpenAPITools / OpenAPITools/openapi-generator
[BUG][TYPESCRIPT] Inconsistent handling of required property by $ref
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
When generating the TypeScript models from the following OpenAPI spec, the type property of CriterionGenericConjunction is marked as optional (type?), even though it is defined as required in the referenced CriterionResidenceCriteriaHandmadeEnumResidenceCriteriaFieldEnum schema.
This causes a TypeScript error because the type property should be required, not optional.
Error :
openapi-generator version
"@openapitools/openapi-generator-cli": "^2.13.13",
OpenAPI declaration file content or url
"CriterionGenericConjunction": {
"type": "object",
"allOf": [
{
"$ref": "#/components/schemas/CriterionResidenceCriteriaHandmadeEnumResidenceCriteriaFieldEnum"
},
{
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": [
"AND",
"CONTAINS",
"ENDS_WITH",
"EQUALS",
"GREATER_THAN",
"GREATER_THAN_OR_EQUALS",
"IN",
"IS_NOT_NULL",
"IS_NULL",
"LESS_THAN",
"LESS_THAN_OR_EQUALS",
"LIKES",
"NOT",
"NOT_EQUALS",
"OR",
"STARTS_WITH"
]
},
"criteria": {
"type": "array",
"items": {
"$ref": "#/components/schemas/CriterionCriteriaHandmadeEnumCriteriaFieldEnum"
}
}
}
}
]
},
"CriterionResidenceCriteriaHandmadeEnumResidenceCriteriaFieldEnum": {
"required": [
"type"
],
"type": "object",
"properties": {
"type": {
"type": "string"
}
},
"discriminator": {
"propertyName": "type"
}
}
Generation Details
openapi-generator-cli generate -i http://localhost:5000/api/v3/api-docs/Aic -g typescript-fetch -o ./src/api/generated --skip-validate-spec --additional-properties=supportsES6=true,typescriptThreePlus=true
Related issues/PRs
Not found
Suggest a fix
Ensure that the type property in CriterionGenericConjunction is generated as required (type: string) based on the $ref to CriterionResidenceCriteriaHandmadeEnumResidenceCriteriaFieldEnum, which defines type as required.
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 the issue with the provided OpenAPI declaration and the openapi-generator-cli typescript-fetch command. Inspect how the TypeScript generator handles required properties across allOf and $ref, then add or update a regression test if the relevant test area is found. Done means CriterionGenericConjunction generates type as required rather than type?.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, typescript
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100