-
-
Notifications
You must be signed in to change notification settings - Fork 906
Add support for PATCH, refactor formats detection #2895
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
Conversation
As noted before,
So having it not be "popular" doesn't mean it might not become so if well supported here. Not saying you should implement it in this PR, of course. |
I'll be glad to merge support for it if someone contribute it (it's why the new system is designed to support several patch formats)! To clarify: it's not on my todo list (yet)! |
5e84a32
to
f63b3b3
Compare
how would you prevent a BC break here? |
Do you think implement the Header Accept-Patch ? That's just the new |
yes it should be implemented in API Platform, but in a follow up PR (and maybe not in 2.5). |
It would be opt-in in 2.x, and opt-out in 3.x. But currently I struggle to find a god way to implement this: https://twitter.com/dunglas/status/1148578034787782656 |
$errorFormats = $this->getFormats($config['error_formats']); | ||
|
||
$this->registerCommonConfiguration($container, $config, $loader, $formats, $errorFormats); | ||
// Backward Compatibility layer | ||
if (isset($formats['jsonapi']) && !isset($patchFormats['jsonapi'])) { |
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.
I really think we should deprecate specifying the format keys, and just use the mime type directly.
EDIT: Hmm... I see it's more complicated than that.
@@ -163,6 +163,7 @@ public function getConfigTreeBuilder() | |||
'json' => ['mime_types' => ['application/json']], // Swagger support | |||
'html' => ['mime_types' => ['text/html']], // Swagger UI support | |||
]); | |||
$this->addFormatSection($rootNode, 'patch_formats', []); |
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.
This doesn't seem like a good default?
*/ | ||
public function __construct(Negotiator $negotiator, /* FormatsProviderInterface */ $formatsProvider) | ||
public function __construct(Negotiator $negotiator, $resourceMetadataFactory, array $formats = []) |
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.
I think we need to do something like this in so many places. Otherwise we'll end up with lots of holes in our arguments in 3.0 😆
@@ -63,33 +65,54 @@ public function __construct(Negotiator $negotiator, /* FormatsProviderInterface | |||
public function onKernelRequest(GetResponseEvent $event): void | |||
{ | |||
$request = $event->getRequest(); | |||
if (!($request->attributes->has('_api_resource_class') || $request->attributes->getBoolean('_api_respond', false) || $request->attributes->getBoolean('_graphql', false))) { | |||
if ( | |||
!($request->attributes->has('_api_resource_class') |
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.
This is indented too much.
@@ -130,37 +153,29 @@ private function addRequestFormats(Request $request, array $formats): void | |||
} | |||
|
|||
/** | |||
* Populates the $mimeTypes property. | |||
* Retries the flattened list of MIME types. |
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.
Retries -> Retrieves
*/ | ||
public function __construct(SerializerInterface $serializer, SerializerContextBuilderInterface $serializerContextBuilder, /* FormatsProviderInterface */$formatsProvider, ResourceMetadataFactoryInterface $resourceMetadataFactory = null) | ||
public function __construct(SerializerInterface $serializer, SerializerContextBuilderInterface $serializerContextBuilder, $resourceMetadataFactory, ResourceMetadataFactoryInterface $legacyResourceMetadataFactory = null) |
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.
We should remove the typehint for $legacyResourceMetadataFactory
, right? And check that in the constructor body?
Add proper support for partial modifications using the
PATCH
HTTP method. The first supported format will be JSON Merge Patch (RFC 7386), while JSON:API Patch will keep working. Supporting JSON Patch (RFC 6902) isn't a a goal as this format is not very popular in the wild, but could be done by leveraging the new infrastructure I'm building.This PR also deprecates
FormatsProviderInterface
andOperationMethodResolverInterface
and all there implementation in favor of populating the appropriate metadata. This approach as several benefits:TODO:
skip_null_values
to true when appropriate (always when PATCH is enabled?)PUT
(I've no clue of how to that for now, but actually it could be some documentation telling that there is no guarantees than doing that will work).