OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
20.76k stars 6.32k forks source link

[BUG] Enum default values do not work in Python when enum is a `$ref` #18843

Closed welshm closed 1 month ago

welshm commented 1 month ago

Bug Report Checklist

Description

Then using a $ref to refer to an enum (with a default value) the default value is not applied for the Python generators. The default value is applied if it is an inline enum.

openapi-generator version

7.6.0

OpenAPI declaration file content or url
components:
  schemas:
    TestEnum:
      type: string
      enum:
        - ONE
        - TWO
        - THREE
        - foUr
    TestEnumWithDefault:
      type: string
      enum:
        - EIN
        - ZWEI
        - DREI
      default: ZWEI
    TestModel:
      type: object
      required:
        - test_enum
      properties:
        test_enum:
          $ref: "#/components/schemas/TestEnum"
        test_string:
          type: string
          example: "Just some string"
        test_enum_with_default:
          $ref: "#/components/schemas/TestEnumWithDefault"
        test_string_with_default:
          type: string
          example: "More string"
          default: "ahoy matey"
        test_inline_defined_enum_with_default:
          type: string
          enum:
            - A
            - B
            - C
          default: B
Generation Details
Steps to reproduce

Generate Python client or server and look at the generated test_model.py and test_enum_with_default.py

Related issues/PRs

https://github.com/OpenAPITools/openapi-generator/pull/18796

Suggest a fix

Add better support for default values for Python with respect to enums

https://github.com/OpenAPITools/openapi-generator/pull/18796

welshm commented 1 month ago

Closed by https://github.com/OpenAPITools/openapi-generator/pull/18796