OpenAPITools / OpenAPITools/openapi-generator
[BUG][typescript-angular] Schemas with allOf and Schemas using required and additionalProperties fails to generate models
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
I use Typescript-Angular generator. I have a specific use case of OpenApi that doesn't generate models
openapi-generator version
- cli 2.23
- generator 7.15
OpenAPI declaration file content or url
{
"openapi": "3.1.0",
"info": {
"title": "Demo bug allOf",
"version": "1.0.0"
},
"servers": [
{
"url": "http://localhost:3000"
}
],
"security": [],
"paths": {
"/v1/demo": {
"get": {
"operationId": "getDemoV1",
"summary": "Get demo",
"responses": {
"200": {
"description": "successful operation",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/DemoV1"
}
}
}
},
"400": {
"description": "bad request"
}
}
}
}
},
"components": {
"schemas": {
"DemoV1": {
"type": "object",
"additionalProperties": false,
"required": [
"demoId",
"status"
],
"properties": {
"demoId": {
"type": "string"
},
"status": {
"type": "string",
"enum": [
"new",
"in_progress",
"completed"
]
},
"extra": {
"type": "object",
"description": "extra data",
"required": [
"data"
],
"additionalProperties": false,
"properties": {
"data": {
"type": "string"
}
}
}
},
"allOf": [
{
"if": {
"properties": {
"status": {
"enum": [
"new"
]
}
}
},
"then": {
"required": [
"extra"
]
}
}
]
}
}
}
}
Generation Details
OpenApi Generator Config
{
"additionalProperties": {
"disallowAdditionalPropertiesIfNotPresent": false,
"fileNaming": "kebab-case",
"enumPropertyNaming": "camelCase",
"modelPropertyNaming": "original",
"queryParamObjectFormat": "json",
"modelFileSuffix": "-dto.model",
"modelSuffix": "Dto",
"serviceFileSuffix": ".gateway",
"serviceSuffix": "Gateway"
}
}
OpenApi Tools
{
"$schema": "./node_modules/@openapitools/openapi-generator-cli/config.schema.json",
"spaces": 2,
"generator-cli": {
"version": "7.15.0"
}
}
Package.json to reproduce problem
{
"name": "demo-bug-allof",
"version": "0.0.0",
"scripts": {
"generate:gateway": "openapi-generator-cli generate -g typescript-angular --global-property skipFormModel=false -i ./openapi.json -o ./gateway -c ./openapi-config.json"
},
"devDependencies": {
"@openapitools/openapi-generator-cli": "^2.18.4",
"ts-node": "^10.9.2",
"typescript": "~5.7.2"
}
}
Steps to reproduce
- npm install where you put the package.json
- run
npm generate:gateway
Open gateway/models/models.ts : it's empty
- remove properties required and additionalProperties from object 'extra' and rerun the previous steps
Open gateway/models/models.ts : it references 2 other DTO files
Related issues/PRs
Suggest a fix
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 minimal OpenAPI declaration, openapi-config.json, and the npm generation command in package.json. Inspect generated gateway/models/models.ts and compare the output with and without required and additionalProperties on extra. Done means the typescript-angular generator produces the expected DTO model references for the reproduced schema.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- angular, java, openapi, typescript
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100