OpenAPITools / OpenAPITools/openapi-generator
[BUG][tyescript-axios] withSeparateModelsAndApi option throws exception
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 (example)?
- What's the version of OpenAPI Generator used?
- Have you search for related issues/PRs?
- What's the actual output vs expected output?
Description
I would like to generate a typescript-axios client with separate models. I can successfully generate one without separate ones, but with separate ones, an exception is thrown.
openapi-generator version
4.2.2
OpenAPI declaration file content or url
The spec is dynamically generated by a Nest application (the very reason I want to use a generator to begin with is to keep it in sync). Here's the one that produces this error:
{
"openapi": "3.0.0",
"info": {
"title": "Frontoffice",
"description": "API docs",
"version": "0.1",
"contact": {}
},
"tags": [],
"servers": [],
"components": {
"schemas": {
"RegisterRequestDto": {
"type": "object",
"properties": {
"username": {
"type": "string",
"pattern": "^[a-zA-Z0-9]+([a-zA-Z0-9][_\\-][a-zA-Z0-9])*[a-zA-Z0-9]+$"
},
"password": {
"type": "string",
"minLength": 8
},
"email": {
"type": "string",
"format": "email"
},
"phone": {
"type": "string",
"description": "Phone number. Can contain arbitrary symbols for readability, but only the digits, and an optional leading plus are accepted.",
"pattern": "[0-9]+"
}
},
"required": [
"username",
"password",
"email",
"phone"
]
},
"PlayerInsertResultDto": {
"type": "object",
"properties": {
"playerId": {
"type": "number"
}
},
"required": [
"playerId"
]
},
"ConflictException": {
"type": "object",
"properties": {}
},
"UnauthorizedException": {
"type": "object",
"properties": {}
}
}
},
"paths": {
"/": {
"get": {
"operationId": "ApiController-getIndex",
"responses": {
"200": {
"description": ""
}
}
}
},
"/register": {
"get": {
"operationId": "RegisterApiController-getIndex",
"responses": {
"200": {
"description": ""
}
}
},
"post": {
"operationId": "RegisterApiController-postIndex",
"parameters": [],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/RegisterRequestDto"
}
}
}
},
"responses": {
"201": {
"description": "",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/PlayerInsertResultDto"
}
}
}
},
"409": {
"description": "If the player already exists",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ConflictException"
}
}
}
}
}
}
},
"/login": {
"get": {
"operationId": "LoginApiController-getIndex",
"responses": {
"200": {
"description": ""
}
}
},
"post": {
"operationId": "LoginApiController-postIndex",
"responses": {
"201": {
"description": "A sanitized player object"
},
"401": {
"description": "On invalid credentials",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/UnauthorizedException"
}
}
}
}
}
}
},
"/_schema": {
"get": {
"operationId": "SwaggerApiController-getSchema",
"responses": {
"200": {
"description": ""
}
}
}
},
"/openapi.json": {
"get": {
"operationId": "SwaggerApiController-getDocument",
"responses": {
"200": {
"description": ""
}
}
}
}
}
}
Command line used for generation
npx openapi-generator generate -i openapi.json --config .\openapi-generate.json -g typescript-axios -o openapi
Steps to reproduce
- Set
withSeparateModelsAndApitotruein the--configfile. - Run the command above command.
Output in console:
Exception in thread "main" java.lang.RuntimeException: apiPackage and modelPackage must be defined
at org.openapitools.codegen.languages.TypeScriptAxiosClientCodegen.processOpts(TypeScriptAxiosClientCodegen.java:117)
at org.openapitools.codegen.DefaultGenerator.configureGeneratorProperties(DefaultGenerator.java:196)
at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:913)
at org.openapitools.codegen.cmd.Generate.run(Generate.java:416)
at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:61)
as opposed to withSeparateModelsAndApi set to false, which finishes with no errors.
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 at TypeScriptAxiosClientCodegen.java line 117, where the exception requires apiPackage and modelPackage, and inspect how withSeparateModelsAndApi is handled. Run the provided generator command with that option enabled; done means the typescript-axios client generates without the reported exception.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, typescript
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100