looking at: https://www.drupal.org/project/openapi/issues/2894623, suggested a way to add description to parameters.
Resources are expected to implement getPluginDefinition with 're_annotation' of the resource parameters.
public function getPluginDefinition() {
return NestedArray::mergeDeep(
parent::getPluginDefinition(),
['re_annotation' => [
"GET" => [
"id" => 'ID of the resource',
],
"PUT" => [
"id" => 'An array with the payload',
],
]]
);
}| Comment | File | Size | Author |
|---|---|---|---|
| #15 | 3116760-15.patch | 7.74 KB | grathbone |
| #14 | openapi_rest-parameter_description-3116760-14.patch | 5.23 KB | kasperg |
| #10 | openapi_rest-parameter_description-3116760-10.patch | 4.94 KB | kevinvb |
| #8 | interdiff_7-8.txt | 1.38 KB | kevinvb |
| #8 | openapi_rest-parameter_description-3116760-8.patch | 4.87 KB | kevinvb |
Issue fork openapi_rest-3116760
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
alianov commentedComment #3
alianov commentedComment #4
alianov commentedComment #5
alianov commentedextending parameter description as per OpenAPI Specification.
expecting resources to implement
Comment #6
marco-sThanks for the patch alianov!
I would recommend to name the array key 'parameters' instead of 'openapi'.
I have also optimized your patch a bit.
Example usage:
Comment #7
marco-sI added a payload option. Also I renamed the array key from 'parameters' to 'route_parameters', because they are only for the route parameters (resp. 'in' => 'path').
Example usage:
Comment #8
kevinvb commentedHi,
It's nice to see the work already done for this so describing parameters is possible.
I do had however one use case which wasn't covered yet (could be I'm just missing documentation) but my rest resource can handle a offset query parameter.
To make sure modules like swagger_ui can handle those parameters and display them in the documentation I've added a small functionality to this generator.
Example usage:
Use 'query_params' in your rest resource.
Comment #9
kevinvb commentedAdded simple is_array check around the extra query_params option so rest resources with paths not having any query arguments described won't throw warnings.
Comment #10
kevinvb commentedAnd now with a working patch, sorry.
Comment #11
kasperg commentedI agree with #8 that the implementation in #7 does not support query parameters. However I did not like the implementation in #10 which adds a new way to specify query parameters in getBaseRoute() compared to the original implementation which does the work in the plugin definition and thus also support defining parameters in the @RestResource annotation.
I have attached an alternate approach to adding support for query parameters which is based on the work in #7. Sorry, no interdiff. For some reason it is not working.
Example usage:
Comment #12
kasperg commentedThe patch in #11 produces an invalid specification as parameters for a path must be an array. With the patch in #11 it can become an object an object when using strings for keys e.g. with
offsetin the example above.The updated patch strips the keys.
Comment #13
kasperg commentedComment #14
kasperg commentedThe patch in #12 fails if there are no route parameters defined. Here is an updated patch which fixes that.
Comment #15
grathbone commentedThe Payload functionality doesn't work when it comes to different payloads per method. Modified the payload functionality to accept a nested method.
Comment #16
anybodyI think this should use MRs instead to make it easier for maintainers to review and merge.
Comment #19
immaculatexavier commentedComment #20
jeffschulerI struggled for awhile trying to figure out how to specify that a param for a custom REST resource should be in the query.
I was able to do so using the patch from #15. (#14 worked for my purposes too.)
After applying the patch, I modified my @RestResource annotation to include the info about the query param like this:
Setting status to Needs work for somebody to take @anybody's advice in turning this into a MR.
Comment #21
jeffschulerSorry @immaculatexavier!
I totally missed that you had already made this a MR. :-p
Comment #22
jeffschulerMR !8 is working as well for my purpose of defining a query-based endpoint param.