Skip to content

[BUG] [python-fastapi] model-name-prefix and suffix generate broken code #22146

@gianmarcocalbi

Description

@gianmarcocalbi

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • 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 using --model-name-prefix or suffix, the generated code has two issues:

  1. when models are used within other models the suffix is duplicated
  2. when models are used within other models the models are not imported (imports are not present)
class ApiObj(BaseModel):
    """
    ApiObj
    """ # noqa: E501
    prop1: Optional[ApiApiProp1] = None
    prop2: Optional[ApiApiProp2] = None
    __properties: ClassVar[List[str]] = ["prop1", "prop2"]

The generator outputs these warnings:

[main] WARN  o.o.c.l.AbstractPythonCodegen - Failed to lookup model in createImportMapOfSet ApiApiProp1
[main] WARN  o.o.c.l.AbstractPythonCodegen - Failed to lookup model in createImportMapOfSet ApiApiProp2
[main] ERROR o.o.c.l.AbstractPythonCodegen - Failed to look up ApiApiProp1 from the imports (map of set) of models.
[main] ERROR o.o.c.l.AbstractPythonCodegen - Failed to look up ApiApiProp1 from the imports (map of set) of models.
[main] ERROR o.o.c.l.AbstractPythonCodegen - Failed to look up ApiApiProp2 from the imports (map of set) of models.
[main] ERROR o.o.c.l.AbstractPythonCodegen - Failed to look up ApiApiProp2 from the imports (map of set) of models.
...
openapi-generator version

generator cli 7.14.0

OpenAPI declaration file content or url
openapi: 3.0.1
info:
  title: ''
  version: ''
paths: {}
  
components:
  schemas:
    Obj:
      type: object
      properties: 
        prop1:
          $ref: '#/components/schemas/Prop1'
        prop2:
          $ref: '#/components/schemas/Prop2'
    
    Prop1:
      type: object
      properties:
        name:
          type: string

    Prop2:
      type: object
      properties:
        name:
          type: string
Generation Details
npx @openapitools/openapi-generator-cli generate -g python-fastapi -i api2.yaml --model-name-prefix Api -o ./packages/python-fastapi2

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions