Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Backed Enum as model in Symfony Forms #2104

Open
nikola-jovanovic-php opened this issue May 26, 2023 · 0 comments · May be fixed by #2105
Open

Add support for Backed Enum as model in Symfony Forms #2104

nikola-jovanovic-php opened this issue May 26, 2023 · 0 comments · May be fixed by #2105

Comments

@nikola-jovanovic-php
Copy link

Currently, there is support for Backed Enum in Entity that is creating component and referencing it in in open api specification.

But when adding EnumType in symfony form, it's specified as simple enum and not a reusable component, same as ChoiceType, and this is creating a lot of duplicate enum types when generating api clients, one per each form where it's used.

I guess the update should be happening here (but i'm not sure).

Current State:

Enum:

enum ExampleEnum: string
{
    case ONE = 'one';
    case TWO = 'two';
    case THREE = 'three';
}

Form:

->add('formField', EnumType::class, ['class' => ExampleEnum::class])

generated specs:

formField:
    type: string
    enum: ['one', 'two', 'three']

Requested state and wanted changes:

components:
  schemas:
    ExampleEnum:
      type: string
      enum:
        - one
        - two
        - three
formField:
    $ref: '#/components/schemas/ExampleEnum'

or if form field is array of enums (multiple = true):

formField:
    type: array
    items:
        $ref: '#/components/schemas/ExampleEnum'
@nikola-jovanovic-php nikola-jovanovic-php changed the title Add support for Backed Enum as model in Synfony Forms Add support for Backed Enum as model in Symfony Forms May 29, 2023
nikola-jovanovic-php added a commit to nikola-jovanovic-php/NelmioApiDocBundle that referenced this issue May 29, 2023
nikola-jovanovic-php added a commit to nikola-jovanovic-php/NelmioApiDocBundle that referenced this issue May 29, 2023
nikola-jovanovic-php added a commit to nikola-jovanovic-php/NelmioApiDocBundle that referenced this issue May 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant