[BUG][tyescript-axios] withSeparateModelsAndApi option throws exception
Created by: boenrobot
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
withSeparateModelsAndApi
totrue
in the--config
file. - 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.