openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

[BUG] [Python] 6.1.x Import missing for models with string pattern

Open jtvmatos opened this issue 3 years ago • 8 comments

Bug Report Checklist

  • [x] Have you provided a full/minimal spec to reproduce the issue?
  • [x] Have you validated the input using an OpenAPI validator (example)?
  • [x] Have you tested with the latest master to confirm the issue still exists?
  • [x] Have you searched for related issues/PRs?
  • [x] What's the actual output vs expected output?
  • [ ] [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

After the last minor relase (6.1.0) the python sdk is broken when a component schema with a string pattern is provided as reference for a endpoint parameter. In this scenario, in the api files is a missing import for the openapi_types.

In practice, using the openapi spec yaml below, in the 6.0.1 version, even though the model/uuid_component.py file was created is not used, and the openapi_type in the api file is a string:

                'openapi_types': {
                    'pattern_value':
                        (str,),
                },

Hopwever, in the new release, 6.1.0, the openapi_type is now described as UuidComponent but there is no model import in the file:

                'openapi_types': {
                    'pattern_value':
                        (UuidComponent,),
                },

image

openapi-generator version

6.1.0

OpenAPI declaration file content or url
---
openapi: 3.0.3
info:
  title: Test pattern
  version: 0.0.0
servers:
- url: localhost
paths:
  /api/{pattern_value}:
    get:
      tags:
      - test1
      operationId: test1
      parameters:
      - name: pattern_value
        in: path
        required: true
        schema:
          $ref: '#/components/schemas/uuid_component'
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: string
components:
  schemas:
    uuid_component:
      pattern: "/[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}/"
      type: string
Generation Details

Python Language without additional configurations.

Steps to reproduce

Generate openapi 6.1.0 spec - python

Related issues/PRs
Suggest a fix

jtvmatos avatar Sep 15 '22 12:09 jtvmatos