fix(jsonschema): make all required properties optional in PATCH operation with 'json' format#6478
Closed
soyuka wants to merge 1 commit intoapi-platform:3.4from
Closed
fix(jsonschema): make all required properties optional in PATCH operation with 'json' format#6478soyuka wants to merge 1 commit intoapi-platform:3.4from
soyuka wants to merge 1 commit intoapi-platform:3.4from
Conversation
…ation with 'json' format by @ttskch see api-platform#6394
vincentchalamon
requested changes
Jul 19, 2024
| return $schema; | ||
| } | ||
|
|
||
| $isJsonMergePatch = 'json' === $format && 'PATCH' === $operation->getMethod() && Schema::TYPE_INPUT === $type; |
Contributor
There was a problem hiding this comment.
Suggested change
| $isJsonMergePatch = 'json' === $format && 'PATCH' === $operation->getMethod() && Schema::TYPE_INPUT === $type; | |
| $isJsonMergePatch = 'json' === $format && 'PATCH' === $method && Schema::TYPE_INPUT === $type; |
| } | ||
|
|
||
| if (true === $skipRequiredProperties) { | ||
| $definitionName .= self::PATCH_SCHEMA_POSTFIX; |
Contributor
There was a problem hiding this comment.
Undefined constant
Contributor
There was a problem hiding this comment.
Also, I think if we add this postfix here on Patch operations, it should also be added on other operations (Post, Put, Delete, Get, GetCollection, etc.)
Comment on lines
+95
to
+96
| if (null === ($skipRequiredProperties = $operation->getExtraProperties()['patch_skip_schema_required_properties'] ?? null)) { | ||
| trigger_deprecation('api-platform/core', '3.4', "Set 'patch_skip_schema_required_properties' on extra properties as API Platform 4 will remove required properties from the JSON Schema on Patch request."); |
Contributor
There was a problem hiding this comment.
Suggested change
| if (null === ($skipRequiredProperties = $operation->getExtraProperties()['patch_skip_schema_required_properties'] ?? null)) { | |
| trigger_deprecation('api-platform/core', '3.4', "Set 'patch_skip_schema_required_properties' on extra properties as API Platform 4 will remove required properties from the JSON Schema on Patch request."); | |
| if (null === ($skipRequiredProperties = $operation->getExtraProperties()['skip_patch_json_schema_required_properties'] ?? null)) { | |
| trigger_deprecation('api-platform/core', '3.4', "Set 'skip_patch_json_schema_required_properties' on extra properties as API Platform 4 will remove "required" JSON Schema node on Patch requests."); |
Comment on lines
+338
to
+349
| /** | ||
| * @group legacy | ||
| * TODO: find a way to keep required properties if needed | ||
| */ | ||
| public function testPatchSchemaRequiredProperties(): void | ||
| { | ||
| $this->tester->run(['command' => 'api:json-schema:generate', 'resource' => 'ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\PatchRequired\PatchMe', '--format' => 'json']); | ||
| $result = $this->tester->getDisplay(); | ||
| $json = json_decode($result, associative: true); | ||
|
|
||
| $this->assertEquals(['b'], $json['definitions']['PatchMe']['required']); | ||
| } |
Contributor
There was a problem hiding this comment.
Please also add a test when a user wants to force required on a property on a Patch operation with "skip_patch_json_schema_required_properties" => true.
Member
Author
|
See #6485 (comment) for this PR's resolution |
Contributor
Member
Author
|
its possible that this is actually fixed but indeed it'll be way easier using the 4. version |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
by @ttskch see #6394