[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