Skip to content

Comments

Improve serialization groups filter doc#3007

Closed
fredericbarthelet wants to merge 1 commit intoapi-platform:mainfrom
fredericbarthelet:add-serialization-group-query-param-doc
Closed

Improve serialization groups filter doc#3007
fredericbarthelet wants to merge 1 commit intoapi-platform:mainfrom
fredericbarthelet:add-serialization-group-query-param-doc

Conversation

@fredericbarthelet
Copy link
Contributor

@fredericbarthelet fredericbarthelet commented Aug 20, 2019

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #2891
License MIT
Doc PR -

@dunglas @teohhanhui, I got inspired by existing getDescription function of FilterProperty to add 'enum' information to generated documentation.
https://github.com/api-platform/core/blob/master/src/Serializer/Filter/PropertyFilter.php#L73-L105

However, I was wondering if I should not use your newly created TypeFactory to enrich generated array. I would do that by :

  • creating a new Schema in FilterProperty::getDescription method with one unique enum property set to the withlisted serialization groups.
  • return description array with a new schema key
  • update https://github.com/api-platform/core/blob/master/src/Swagger/Serializer/DocumentationNormalizer.php#L690 to pass optional schema value found in parameter data as last getType argument
  • update TypeFactory::getType method to use provided schema to improve returned type (not only for BUILTIN_TYPE_OBJECT as it is the case right now)

What do you think ? This could be ported as well on #2971, which is currently relying on a new Schema property defined without the Schema::class type.

#hackdayparis

@fredericbarthelet fredericbarthelet force-pushed the add-serialization-group-query-param-doc branch from 86745bd to 8ee86b0 Compare August 20, 2019 16:48
@teohhanhui
Copy link
Contributor

teohhanhui commented Aug 20, 2019

The filter's description should not be tied to the serialization formats. As I've tried to explain before in #2971, converting the filter description to whichever appropriate documentation format is the job of the DocumentationNormalizer.

But it might be a good idea to use a Schema object instead of an array. Hmm... Maybe not. It does not actually encapsulate anything.

@dunglas
Copy link
Member

dunglas commented Aug 20, 2019

I agree with @teohhanhui, the filter should be agnostic of the documentation format (Swagger/OpenAPI/Hydra etc). However, describing it with a JSON Schema looks OK to me. Formats relying on JSON Schema (such as OpenAPI/Swagger) can use it directly, and others (such as Hydra) will have to convert it. As JSON Schema is kind of a standard (an Internet Draft actually, but that should become a RFC at some point), using it looks better to me than creating another custom format of our own.

So the filter should only provide a schema key (instead of swagger and openapi).

@dunglas
Copy link
Member

dunglas commented Aug 20, 2019

Using a plain array (following the JSON Schema semantic) looks better to me than using a Schema instance (easier for the end user). It's easy to transform an array in a Schema instance in DocumentationNormalizer. We could also support both (array|\ArrayObject, as Schema is just a specialized ArrayObject).

@fredericbarthelet
Copy link
Contributor Author

fredericbarthelet commented Aug 21, 2019

@teohhanhui @dunglas understood, no Schema use in getDescription return value.

As of now we than have 2 strategy to "enrich" generated plain array description, that will then be eventually used by the DocumentationNormalizer :

Which one do you prefer in order to ensure consistency in this array ?
Should I add a Description object to standardize and ensure getDescription returns are all consistent and avoid this discussion in the future ?

@fredericbarthelet
Copy link
Contributor Author

@teohhanhui @dunglas I made a small concept PR to show you what I mean by Description object : https://github.com/fredericbarthelet/core/pull/2/files

This would ensure :

  • normalization of getDescription output (thus avoiding the above conversation). PHPdoc on the Filter interface did not prevent me from introducing additional keys (which is bad i guess ?)
  • cleaner fetching of additional parameters based on current documentation version (swagger or openapi)

WDYT ?

@teohhanhui
Copy link
Contributor

Uhh... I didn't realize we have swagger and openapi keys in the filter's description. 😞

That's bad and should be deprecated.

@fredericbarthelet
Copy link
Contributor Author

@teohhanhui, noted, I removed swagger and openapi keys in my Description proposal. It is OK then to normalize this output using an object like described in https://github.com/fredericbarthelet/core/pull/2/files ? If so, I will update this PR replacing all occurrences of swagger and openapi keys with new Description object.

@teohhanhui
Copy link
Contributor

No, sorry. My comment is about those keys in the existing implementation.

As for your suggestion of using a class, I don't think we'll do it. (Personally, I'd like to see everything being well-defined classes, but I understand it's not what we'd like to do in this project. That's why you see array $context = [] a lot.)

@fredericbarthelet fredericbarthelet force-pushed the add-serialization-group-query-param-doc branch 2 times, most recently from 2d694ae to dee7d46 Compare August 23, 2019 12:59
@fredericbarthelet
Copy link
Contributor Author

@teohhanhui I updated FilterInterface PHPDoc to reflect decision not to use swagger and openapi keys. I added non-existing schema, items and description keys in the description. I updated my PR to match this "interface" and remove remaining swagger and openapi usage on PropertyFilter.

For my knowledge, what is the advantage of using plain arrays instead of object to describe "options" arguments ? Is something like src/JsonSchema/Schema.php a sort of compromise, allowing for requirement in construction of certain arguments, but leaving free the possibility to add properties not initially defined on the object ?

@fredericbarthelet fredericbarthelet force-pushed the add-serialization-group-query-param-doc branch from dee7d46 to 2da52d9 Compare September 9, 2019 17:57
@fredericbarthelet fredericbarthelet force-pushed the add-serialization-group-query-param-doc branch from 2da52d9 to 40f7abf Compare September 24, 2019 07:30
@fredericbarthelet
Copy link
Contributor Author

Hi @teohhanhui, I updated my PR with latest changes from master. Did you see my previous message :) ? Is there any remaining modification to be made on this PR ?

@fredericbarthelet fredericbarthelet force-pushed the add-serialization-group-query-param-doc branch from 40f7abf to c90f350 Compare October 1, 2019 07:54
@fredericbarthelet
Copy link
Contributor Author

Hello @teohhanhui, sorry to insist, but could you let me know if this PR is fine for you now :) ?

@fredericbarthelet fredericbarthelet force-pushed the add-serialization-group-query-param-doc branch 10 times, most recently from 93acf83 to a1b09dd Compare November 4, 2019 13:09
@fredericbarthelet fredericbarthelet force-pushed the add-serialization-group-query-param-doc branch from a1b09dd to e59bfe8 Compare November 16, 2019 19:17
@teohhanhui
Copy link
Contributor

Sorry, I've somehow missed this one. 🙇‍♂️

I'm going to take a look now.

Comment on lines +41 to +42
* - swagger (optional/deprecated): additional parameters for the path operation
* - openapi (optional/deprecated): additional parameters for the path operation in the version 3
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* - swagger (optional/deprecated): additional parameters for the path operation
* - openapi (optional/deprecated): additional parameters for the path operation in the version 3
* - swagger (optional) (deprecated): additional parameters for the path operation
* - openapi (optional) (deprecated): additional parameters for the path operation in the version 3

];

if ($this->whitelist) {
$description['schema'] = ['type' => 'array', 'items' => ['type' => 'string', 'enum' => $this->whitelist]];
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
$description['schema'] = ['type' => 'array', 'items' => ['type' => 'string', 'enum' => $this->whitelist]];
$description['schema'] = [
'type' => 'array',
'items' => [
'type' => 'string',
'enum' => $this->whitelist,
],
];

}
}

/** @deprecated schema key should be used instead */
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to trigger deprecation errors instead. This phpdoc is unnecessary.

@stale
Copy link

stale bot commented Nov 5, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Nov 5, 2022
@stale
Copy link

stale bot commented Jan 4, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jan 4, 2023
@stale stale bot closed this Jan 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants