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
  • #13648
Closed
Open
Issue created Oct 09, 2022 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[BUG][Python][Client] Incorrect import path if packageName is nested

Created by: chebykinn

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • 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

When I generate a client with --package-name some.nested.path the dots will be replaced with slashes in a generated endpoint file. So expected generated import line is:

from pysvc1.generated.openapi.clients.service1.models.resp import Resp

Actual:

from pysvc1/generated/openapi/clients/service1.models.resp import Resp

I've narrowed it down to this method: https://github.com/OpenAPITools/openapi-generator/blob/02916822f73be0939caf7a360ead5342e1b07b75/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java#L890-L893 Here it uses packagePath which explicitly replaces dots with slashes: https://github.com/OpenAPITools/openapi-generator/blob/02916822f73be0939caf7a360ead5342e1b07b75/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java#L2620-L2622

openapi-generator version

6.2.0

OpenAPI declaration file content or url
openapi: "3.0.0"
info:
  version: 1.0.0
  title: service1
  description: Service description
  contact:
    name: Maintainer name
    email: Maintainer email
servers:
  - url: service1.company.com
paths:
  /path/to/api:
    get:
      summary: sample handler
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Resp'
components:
  schemas:
    Resp:
      type: object
      properties:
        prop1:
          type: string
        prop2:
          type: string
      required:
        - prop2
Generation Details
openapi-generator generate -g python  -i ./api.yaml -o ./out --package-name pysvc1.generated.openapi.clients.service1
Steps to reproduce

Run client generation with a nested package name parameter.

Related issues/PRs
  • https://github.com/OpenAPITools/openapi-generator/issues/1302
  • https://github.com/OpenAPITools/openapi-generator/issues/1110
  • https://github.com/OpenAPITools/openapi-generator/issues/2722
Suggest a fix

Looks like we just need to remove the use of packagePath from toModelImport

Assignee
Assign to
Time tracking