-
-
Notifications
You must be signed in to change notification settings - Fork 878
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
[JsonSchema] Only build schemas which can be serialized / deserialied #6276
base: main
Are you sure you want to change the base?
[JsonSchema] Only build schemas which can be serialized / deserialied #6276
Conversation
use |
@soyuka Using the flag What I want is to keep the operation in the OpenAPI spec but skip the associated schema as my Currenlty, it includes the schema of the class tagged as |
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. |
src/JsonSchema/SchemaFactory.php
Outdated
@@ -65,6 +65,14 @@ public function buildSchema(string $className, string $format = 'json', string $ | |||
|
|||
[$operation, $serializerContext, $validationGroups, $inputOrOutputClass] = $metadata; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To save you digging too hard, and easing the rebase, after my last PR these are now assigned here:
core/src/JsonSchema/SchemaFactory.php
Lines 62 to 70 in 678eb4f
if (!$this->isResourceClass($className)) { | |
$operation = null; | |
$inputOrOutputClass = $className; | |
$serializerContext ??= []; | |
} else { | |
$operation = $this->findOperation($className, $type, $operation, $serializerContext); | |
$inputOrOutputClass = $this->findOutputClass($className, $type, $operation, $serializerContext); | |
$serializerContext ??= $this->getSerializerContext($operation, $type); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I just rebase my PR
@soyuka @GwendolenLynch I'm not familiar with the project test suite. Can you point me where / how I can add tests about this feature ? |
6e9c3d9
to
97093c0
Compare
Hello,
This PR is a first step for a discussion about a bugfix.
Given the following ApiResource:
If I generate the OpenAPI documentation using
php bin/console api:openapi:export
, theApiPlatform\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:
WDYT ?