Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #4328
Closed
Open
Issue created Oct 30, 2019 by Administrator@rootContributor

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

Created by: 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).

Assignee
Assign to
Time tracking