8000 Entity fields typed with PHP 8.1 enums are incorrectly displayed on swagger. · Issue #2234 · api-platform/api-platform · GitHub
[go: up one dir, main page]

Skip to content
Entity fields typed with PHP 8.1 enums are incorrectly displayed on swagger.  #2234
@wa12rior

Description

@wa12rior

API Platform version(s) affected: 2.6.8

Description
Entity fields typed with PHP 8.1 enums are incorrectly displayed on swagger.

Default display:
public FooEnum $bar;
"bar": { "@context": "string", "@id": "string", "@type": "string" },

Display with ApiProperty attribute:
Attribute:

#[ApiProperty(
        attributes: [
            'openapi_context' => [
                'type' => 'string',
                'enum' => [
                    FooEnum::FOO,
                    FooEnum::BAR,
                ],
            ],
        ],
    )]

schema:

[ OrderedMap { "name": "FOO", "value": "FOO" }, OrderedMap { "name": "BAR", "value": "BAR" }]

This approach with the ApiProperty attribute is much better than the first. 5BB5 It gives some information at least. But it's really confusing. Is there a better approach or am I missing something? According to OpenAPI specification enums should display as array:
https://swagger.io/docs/specification/data-models/enums/

How to reproduce

  1. Make entity with field type of enum.
  2. Add API platform attributes, serialization groups etc.
  3. Add serialization group to field type of enum.
  4. Check swagger schema and example value on resource you just created.

Possible Solution
I don't know.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0