Skip to content

[BUG][PHP] Setters for referenced enums are unusable #4328

Open
@hinrik

Description

@hinrik

I'm using version 4.1.3.

Consider this definition:

components:
  schemas:
    Foo:
      type: object
      properties:
        inline_enum:
          type: string
          enum: [one, two, three]
        referenced_enum:
            $ref: '#/components/schemas/ReferencedEnum'
    ReferencedEnum:
      type: string
      enum: [one, two, three]

For inline_enum, Foo's setInlineEnum() method accepts a string, the enum values are constants on the Foo class, and the value being set is validated to be one of the constants.

However, for referenced_enum, setReferencedEnum() accepts a ReferencedEnum object. But that class only has the constants along with a getAllowableEnumValues() function. It carries no state, making it impossible to call setReferencedEnum() with a meaningful value.

I've seen that at least the Java generator handles the referenced_enum case correctly, as it uses a real enum type just like it does for inline_enum.

I would very much like to use the referenced_enum style in my project because it would allow using the same enum definition in multiple places. This is especially handy when one of the consumers of the API definition is a Java application, where this would mean a single enum class instead of multiple duplicate ones where you might have to convert values between each.

Was this just an oversight? If so I can try to whip up a PR to make setReferencedEnum() accept a string, and include the same validation that setInlineEnum() has (but using the values from the ReferencedEnum class).

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