Skip to content

Conversation

@VincentLanglet
Copy link
Contributor

Q A
Branch? 4.2 for bug
Tickets Closes #7457
License MIT
Doc PR api-platform/docs#...

@VincentLanglet VincentLanglet changed the title Declare properties as required for Output fix(jsonSchema): Declare properties as required for Output Oct 23, 2025
@VincentLanglet VincentLanglet force-pushed the requiredOutput branch 4 times, most recently from 5ae2b67 to 0e35815 Compare October 23, 2025 18:13
$propertyMetadata = $this->propertyMetadataFactory->create($inputOrOutputClass, $propertyName, $options);

if (false === $propertyMetadata->isReadable() && false === $propertyMetadata->isWritable()) {
if (
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the implementation of OpenApiFactory, there is

$this->jsonSchemaFactory->buildSchema($resourceClass, $operationFormat, Schema::TYPE_OUTPUT, $operation, $schema, null, $forceSchemaCollection);

for the output of an api call (for instance GET)

and

$this->jsonSchemaFactory->buildSchema($resourceClass, $operationFormat, Schema::TYPE_INPUT, $operation, $schema, null, $forceSchemaCollection);

for the input of an api call PATCH/PUT/POST

Therefore I think

  • We should expose in the input schema only Writable properties
  • We should expose in the output schema only Readable properties (and declare them required)

It makes no sens to me to add writable property in the GET schema (or the opposite). Am i misunderstandind ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should not expose required in my opinion as it locks the schema (for example with the PropertyFilter or GroupFilter, results can be altered).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I understand the issue then. it's hard to document both

  • call which doesn't use any propertyFilter
  • and calls which are using some

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still it means that we shouldn't use the same schema for input and output and therefor the same cache key.

Should we start with a different cache key without changing anything?

@VincentLanglet
Copy link
Contributor Author

Looking at the number of the test to update, I think it will be better to get your opinion on this first @soyuka
Am I misunderstanding everything or shouldn't the schema be different for the input and for the output ?

@VincentLanglet VincentLanglet requested a review from soyuka October 23, 2025 18:41
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.

OpenApi json schema is lacking of required property

2 participants