-
-
Notifications
You must be signed in to change notification settings - Fork 965
feat: spec-compliant PUT method #4996
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
fad7755
feat: spec-compliant PUT method
soyuka 2256c61
add allowCreate on the put operation and deprecate non standard_put
soyuka b22fd15
fix deprec
soyuka 0d1dcf3
fix tests
soyuka d594ed1
deprec
soyuka 63603db
phpstan
soyuka 4b7204f
fix mongodb
soyuka 2fae6a3
fix mongodb
soyuka 5167555
t
soyuka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
feat: spec-compliant PUT method
- Loading branch information
commit fad77550082f6bd7ecc1a277f0e6efa4de3bbd70
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| Feature: Spec-compliant PUT support | ||
| As a client software developer | ||
| I need to be able to create or replace resources using the PUT HTTP method | ||
|
|
||
| @createSchema | ||
| Scenario: Create a new resource | ||
| When I add "Content-Type" header equal to "application/ld+json" | ||
| And I send a "PUT" request to "/standard_puts/5" with body: | ||
| """ | ||
| { | ||
| "foo": "a", | ||
| "bar": "b" | ||
| } | ||
| """ | ||
| Then the response status code should be 201 | ||
| And the response should be in JSON | ||
| And the JSON should be equal to: | ||
| """ | ||
| { | ||
| "@context": "/contexts/StandardPut", | ||
| "@id": "/standard_puts/5", | ||
| "@type": "StandardPut", | ||
| "id": 5, | ||
| "foo": "a", | ||
| "bar": "b" | ||
| } | ||
| """ | ||
|
|
||
| Scenario: Replace an existing resource | ||
| When I add "Content-Type" header equal to "application/ld+json" | ||
| And I send a "PUT" request to "/standard_puts/5" with body: | ||
| """ | ||
| { | ||
| "foo": "c" | ||
| } | ||
| """ | ||
| Then the response status code should be 200 | ||
| And the response should be in JSON | ||
| And the JSON should be equal to: | ||
| """ | ||
| { | ||
| "@context": "/contexts/StandardPut", | ||
| "@id": "/standard_puts/5", | ||
| "@type": "StandardPut", | ||
| "id": 5, | ||
| "foo": "c", | ||
| "bar": "" | ||
| } | ||
| """ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ | |
| use ApiPlatform\Api\UriVariablesConverterInterface; | ||
| use ApiPlatform\Exception\InvalidIdentifierException; | ||
| use ApiPlatform\Exception\InvalidUriVariableException; | ||
| use ApiPlatform\Metadata\HttpOperation; | ||
| use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface; | ||
| use ApiPlatform\Serializer\SerializerContextBuilderInterface; | ||
| use ApiPlatform\State\ProviderInterface; | ||
|
|
@@ -38,10 +39,12 @@ final class ReadListener | |
| use OperationRequestInitiatorTrait; | ||
| use UriVariablesResolverTrait; | ||
|
|
||
| public const OPERATION_ATTRIBUTE_KEY = 'read'; | ||
|
|
||
| public function __construct(private readonly ProviderInterface $provider, ?ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory = null, private readonly ?SerializerContextBuilderInterface $serializerContextBuilder = null, UriVariablesConverterInterface $uriVariablesConverter = null) | ||
| { | ||
| public function __construct( | ||
| private readonly ProviderInterface $provider, | ||
| ?ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory = null, | ||
| private readonly ?SerializerContextBuilderInterface $serializerContextBuilder = null, | ||
| UriVariablesConverterInterface $uriVariablesConverter = null, | ||
| ) { | ||
| $this->resourceMetadataCollectionFactory = $resourceMetadataCollectionFactory; | ||
| $this->uriVariablesConverter = $uriVariablesConverter; | ||
| } | ||
|
|
@@ -90,7 +93,13 @@ public function onKernelRequest(RequestEvent $event): void | |
| throw new NotFoundHttpException('Invalid identifier value or configuration.', $e); | ||
| } | ||
|
|
||
| if (null === $data) { | ||
| if ( | ||
| null === $data && | ||
| ( | ||
| HttpOperation::METHOD_PUT !== $operation->getMethod() || | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why using a constant here and not elsewhere? |
||
| !($operation->getExtraProperties()['allow_create'] ?? false) | ||
| ) | ||
| ) { | ||
| throw new NotFoundHttpException('Not Found'); | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 thought we didn't want to have multiple lines in the constructor?
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.
Now that we have constructor promotion and the ability to add a comma after the last parameter, I think we should use multiple lines for clarity and to reduce merge conflicts.
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.
Good to know, it would be great to add it in the CS fixer.