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

Example documentation is ignored for Enum resources #6317

Open
gnito-org opened this issue Apr 15, 2024 · 2 comments · May be fixed by #6309
Open

Example documentation is ignored for Enum resources #6317

gnito-org opened this issue Apr 15, 2024 · 2 comments · May be fixed by #6309

Comments

@gnito-org
Copy link

API Platform version(s) affected: 3.2.20

Description

When using a Backed Enum class as an API resource, any example value provided in the ApiProperty attribute is ignored and does not appear in the OpenAPI documentation.

This is true for example: 'foo' and openapiContext: ['example' => 'foo'].

On API resources that are Doctrine entities, the supplied example values appear in the OpenAPI documentation.

How to reproduce

https://github.com/gnito-org/problem-replicator-api-platform-enum-example

Possible Solution

Additional Context

@GwendolenLynch
Copy link
Contributor

Linking this as I'm working on backed enum resources in #6309.

@GwendolenLynch
Copy link
Contributor

I think this is where the breakage occurs.

if ($reflectionEnum) {
if ($reflectionEnum->hasCase($property)) {
$reflectionCase = $reflectionEnum->getCase($property);
if ($attributes = $reflectionCase->getAttributes(ApiProperty::class)) {
return $this->createMetadata($attributes[0]->newInstance(), $parentPropertyMetadata);
}
}
return $this->handleNotFound($parentPropertyMetadata, $resourceClass, $property);
}

Removing the return, and handling $reflectionEnum below works (caveat emptor).

@GwendolenLynch GwendolenLynch linked a pull request Apr 19, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants