core icon indicating copy to clipboard operation
core copied to clipboard

feat(openapi): add error resources schemes

Open JacquesDurand opened this issue 1 year ago • 4 comments

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 !

JacquesDurand avatar Apr 23 '24 14:04 JacquesDurand

This is nuts! Love it! Will review shortly.

soyuka avatar Apr 23 '24 19:04 soyuka

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jul 23 '24 23:07 stale[bot]

Please don't close this, this is a much needed feature.

danielhomer avatar Jul 26 '24 09:07 danielhomer

I'm so sorry I completely forgot about this, I'll get back to it ASAP

JacquesDurand avatar Jul 29 '24 13:07 JacquesDurand

Cool feature!

dunglas avatar Aug 31 '24 05:08 dunglas

Many thanks @JacquesDurand ! We need some documentation for that awesome feature!

soyuka avatar Sep 09 '24 07:09 soyuka