Description
Description
When generating a Kotlin client with an API that uses custom types, I would prefer to use my own data classes instead of the ones generated by OpenAPI.
However, when specifying these classes in the configuration, the import clauses in DefaultApi are wrong, and I am not sure if my configuration is wrong or if there is a problem in OpenApi.
I have tried different combinations of adding or omitting the full package in the configuration both for typeMapping and for importMapping, and the results are varied (e.g., a configuration adds the wrong import, another creates the data class even with the mapping specified, another collapses the package and class name removing the dots...).
Let me know if there is a correct combination of typeMapping and importMapping that eludes me, to obtain the expected result, or if there is a problem with OpenApi.
openapi-generator version
The problem was found with version 4.2.0, and it remains if using master.
OpenAPI declaration
openapi: 3.0.1
paths:
/operations/{operationId}:
get:
summary: Retrieve the descriptor of an operation.
operationId: getOperation
parameters:
- name: operationId
in: path
description: Id of the operation.
required: true
schema:
type: integer
format: int32
example: 1
responses:
200:
content:
application/json:
schema:
$ref: '#/components/schemas/CustomType'
404:
description: Operation not found
components:
schemas:
CustomType:
type: object
properties:
name:
type: string
format: uuid
Configuration
{
"packageName": "some.package",
"groupId": "mygroup",
"artifactId": "myclient",
"artifactVersion": "1.0",
"enumPropertyNaming": "UPPERCASE",
"serializationLibrary": "gson",
"serializableModel": "true",
"dateLibrary": "java8",
"collectionType": "list",
"library": "jvm-okhttp3",
"typeMappings": {
"CustomType": "CustomType"
},
"importMappings": {
"CustomType": "some.other.package.CustomType"
}
}
Command line used for generation
java -jar openapi-generator-cli.jar generate -g kotlin -o xxx -i sample-api.yaml -c sample-config.json --skip-validate-spec
Expected behavior
Import declaration:
import some.other.package.CustomType
Method signature:
fun getOperation(operationId: kotlin.Int) : CustomType
Actual behavior
Import declaration:
import some.package.models.some.other.package.CustomType
Method signature:
fun getOperation(operationId: kotlin.Int) : some.other.package.CustomType