fix(jsonapi): add missing "included" schema parts#6277
Conversation
496f1d4 to
4751a83
Compare
41aa9e5 to
42d718a
Compare
|
@soyuka I have had to proof-of-concept a slightly different approach in a junk commit for review & discussion on where to go from here 🌞 Problem Approach
Questions
Advice and guidance warmly welcomed! Edit: I've started breaking out more of the logic in the trait/ |
8f12a2a to
1cdb34a
Compare
soyuka
left a comment
There was a problem hiding this comment.
Nice refactoring actually I think that it's a good idea to have a Trait to share the logic, not sure about adding a new interface though as buildDefinitionName is private anyways. Can that work only using the Trait?
Also don't put another author then yourself (no author phpdoc is also fine) and I think that the trait should be @internal so that we can make updates to it in the future without breaking userland.
| return $schema; | ||
| return $this->schemaFactory->buildSchema($className, $format, $type, $operation, $schema, $serializerContext, $forceCollection); | ||
| } | ||
| $schema = $this->schemaFactory->buildSchema($className, $format, $type, $operation, $schema, [], $forceCollection); |
There was a problem hiding this comment.
I was hoping you'd bring this up 👍
I haven't mapped it out fully yet, but the JSON:API serializer seems to mostly ignore normalization groups (c.f. include query parameter.
So if it is not a jsonapi format, just pass it on as-is, else generate the schema without groups. Hadn't gotten past that so far. I got distracted with enums.
There was a problem hiding this comment.
can you mention the json:api specification in a comment (e.g: the JSON:API serializer ignores normalization groups and uses an include parameter)?
side note I've come accross:
core/src/OpenApi/Factory/OpenApiFactory.php
Line 402 in 93f8b5f
Looks like we don't send the context from the openapi factory but I'm not sure why.
04107af to
0d141a5
Compare
It can. I chose to externalise it as a guess as to what you'd choose … plus the thought that definition name generation becomes implementation override-able. Your call 👍 |
|
Indeed but as long as you use the shortName the extension point exists no? If you are in a weird case you need to decorate the SchemaFactory. |
|
As I understand it, it depends on how Assume you have the resource If you set, for example, one format in the api_platform:
formats:
jsonapi: ['application/vnd.api+json']… then
However, if you configure a non api_platform:
formats:
jsonapi: ['application/vnd.api+json']
patch_formats:
jsonapi: ['application/vnd.api+json']… you will end up with one definition:
Now if you add (de)normalization groups all bets are off. Hence the refactoring in this PR. I did not know all that a couple of weeks ago, so yeah 😇 |
e06b7df to
1e7d6a3
Compare
|
One other thing that came to mind with having it separate is unit testing. It makes that part of the process distinctly testable. Disclaimer: I can be overly obsessive about unit tests and the "…one thing well" principle. 😊 |
ab0e57a to
823d8d3
Compare
823d8d3 to
748b1da
Compare
e47c42d to
6eacdcc
Compare
|
Thanks @soyuka! |
Per https://jsonapi.org/format/#fetching-includes which the serializer already handles beautifully.