Skip to content

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

Description

@welshm

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?
    • Default types should be supported
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
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

#18796

Suggest a fix

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

#18796

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions