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

feat(openapi): add error resources schemes #6332

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

JacquesDurand
Copy link
Contributor

Q A
Branch? main
Tickets Closes #6003
License MIT
Doc PR api-platform/docs#TODO

Allow linking ErrorResources to ApiResources to automatically generate openapi documentation for errors:

#[ApiResource(operations: [
    new GetCollection(errors: [MyDomainException::class])
])]
class Greeting
{
...
}

with the following Exception (currently needs to be an ErrorResource and to implement ProblemExceptionInterface):

#[ErrorResource]
class MyDomainException extends \Exception implements ProblemExceptionInterface
{
    public function getType(): string
    {
        return 'Teapot';
    }
    public function getTitle(): ?string
    {
        return null;
    }
    public function getStatus(): ?int
    {
        return 418;
    }
    public function getDetail(): ?string
    {
        return 'My specific Domain Exception';
    }
    public function getInstance(): ?string
    {
        return null;
    }
}

would allow the following:

image

Do you think it might be an interesting feature ?

There might still be a few things I am not too familiar with, any advice is more than welcome !

Allow linking ErrorResources to ApiResources to automatically generate
openapi documentation for errors
@soyuka
Copy link
Member

soyuka commented Apr 23, 2024

This is nuts! Love it! Will review shortly.

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 this pull request may close these issues.

Add ErrorResource Schemes to OpenAPI documentation
2 participants