[JsonSchema] Only build schemas which can be serialized / deserialied
| Q | A |
|---|---|
| Branch? | main |
| Tickets | None |
| License | MIT |
| Doc PR | None |
Hello,
This PR is a first step for a discussion about a bugfix.
Given the following ApiResource:
#[ApiResource(operations: [new Delete()])]
class MyResource
{
}
If I generate the OpenAPI documentation using php bin/console api:openapi:export, the ApiPlatform\OpenApi\Factory\OpenApiFactory will generate a doc including the components "MyResource" whereas no operation references it (request / response -> no content).
Futhermore, it exposes all MyResource properties which should stay internal as it is not part of our API.
I would expect that the OpenApiFactory only builds schemas that operation can deserialize / serialize and this is what this PR does.
Now, to fix my OpenAPI doc, I can just do the following:
#[ApiResource(operations: [new Delete(
deserialize: false,
serialize: false,
)])]
class MyResource
{
}
WDYT ?
use openapi: false?
@soyuka Using the flag openapi: false would remove the operation from the OpenAPI spec.
What I want is to keep the operation in the OpenAPI spec but skip the associated schema as my DELETE operation does not have request body as well as no response body (204).
Currenlty, it includes the schema of the class tagged as ApiResource in the OpenAPI spec.
Futhermore, it exposes all MyResource properties which should stay internal as it is not part of our API.
This is quite wrong if a class is marked as a resource it is a public API. I like your patch though, is it possible to add a test on that though?
@soyuka I mean it exposes unwanted properties as I use deserialization / serialization groups everywhere on this ApiResource for all its operations except for the delete operation. Then, it ends by adding the "root" resource (not specific to a (de)serializer group) with all is properties, something I don't want.
I will complete this PR with some tests.
@soyuka @GwendolenLynch I'm not familiar with the project test suite. Can you point me where / how I can add tests about this feature ?