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
  • Merge requests
  • !4488

[PHP] Fully support referenced enums

  • Review changes

  • Download
  • Email patches
  • Plain diff
Open Administrator requested to merge github/fork/hinrik/php_fix_referenced_enums into master Nov 14, 2019
  • Overview 0
  • Commits 9
  • Pipelines 1
  • Changes 44

Created by: hinrik

Resolves issue #4328 and allows full use of referenced enums for PHP. This change might also make it easier to address the issue discussed in #3186.

Without this change, referenced enums are not fully usable in PHP (and possibly other languages which don't have native enums). This is because the setter for such a property would expect an instance of the external enum class as the value, and that class has no state (and was therefore a meaningless value) (see #4328).

On properties which reference enum schemas, CodegenProperty has a new field (referencedEnumType) which contains the enum value data type of a referenced schema. This allows generators for languages that don't have native enums to easily work with the primitive type instead.

I adjusted the PHP model template to make use of this new variable, so that it now generates very similar code for referenced enum properties as it does for inline ones: the setter accepts a primitive type and validates the value. The only difference is that the allowed values are stored on the external enum class rather than inline on the model.

There was also some syntactically invalid PHP code being generated for referenced enums containing purely numeric values. To account for the differences in code generation between inline and referenced enums, the toEnumVarName() method now receives an extra parameter indicating whether the enum is on its own model class. In the case of PHP this allows selectively prefixing the name with an underscore (while avoiding a superfluous underscore on inline enums, which already have a prefix).

Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/hinrik/php_fix_referenced_enums