Skip to content
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

feat(jsonschema): make all required properties optional in PATCH operation with 'json' format #6395

Closed

Conversation

ttskch
Copy link
Contributor

@ttskch ttskch commented May 29, 2024

Note

Is this a bug? If so, we can close this PR and go to #6394.

Q A
Branch? main
Tickets N/A
License MIT
Doc PR N/A

In the schema for the request body of application/merge-patch+json PATCH operation, all required properties should be output as optional.

See here: https://datatracker.ietf.org/doc/html/rfc7386#section-3

This PR fixes the SchemaFactory for the 'json' format to output required properties as optional only for input context of PATCH operations.

For example, for the following entity, the output of the OpenAPI document will change as follows:

#[ORM\Entity(repositoryClass: TodoRepository::class)]
#[ApiResource]
class Todo
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column]
    private ?int $id = null;

    #[ORM\Column(length: 255)]
    #[Assert\NotBlank]
    #[Assert\Length(max: 255)]
    private ?string $title = null;

    #[ORM\Column(type: Types::TEXT, nullable: true)]
    private ?string $description = null;

    #[ORM\Column]
    #[Assert\NotNull]
    private ?bool $done = null;
Before After
PATCH Operation image image
Schemas image

@ttskch ttskch force-pushed the feat/jsonschema-json-merge-patch branch from 30ce240 to 31beb2f Compare May 29, 2024 06:17
@ttskch ttskch changed the title fix(jsonschema): make all required properties optional in PATCH operation with 'json' format feat(jsonschema): make all required properties optional in PATCH operation with 'json' format May 29, 2024
@ttskch
Copy link
Contributor Author

ttskch commented May 30, 2024

This PR was integrated into #6394.

refs: #6394 (comment)

@ttskch ttskch closed this May 30, 2024
@ttskch ttskch deleted the feat/jsonschema-json-merge-patch branch May 30, 2024 08:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant