Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #4420
Closed
Open
Issue created Nov 08, 2019 by Administrator@rootContributor

[BUG] [Kotlin-Client] Strange DefaultApi import when mapping custom types

Created by: sivieri

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

Assignee
Assign to
Time tracking