-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add documentation for override Swagger docs #236
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
Conversation
core/swagger-decorator.md
Outdated
@@ -0,0 +1,70 @@ | |||
# Override Swagger documentation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll suggest to add a new documentation entry for Swagger.
I'll call the file swagger.md
and the title Swagger Support
.
core/swagger-decorator.md
Outdated
# Override Swagger documentation | ||
|
||
|
||
Symfony allow to [decorates services](https://symfony.com/doc/current/service_container/service_decoration.html), here we need to decorate the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
allows to decorate
core/swagger-decorator.md
Outdated
services: | ||
app.swagger.swagger_decorator: | ||
decorates: api_platform.swagger.normalizer.documentation | ||
class: AppBundle\Swagger\SwaggerDecorator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you put the class name into single quotes (sometimes can cause problem to not escape it)
core/swagger-decorator.md
Outdated
``` | ||
|
||
```php | ||
<?php |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a comment with the path of the .php
file?
core/swagger-decorator.md
Outdated
use Symfony\Component\Serializer\Normalizer\NormalizerInterface; | ||
|
||
/** | ||
* Class SwaggerDecorator. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Useless, can be remove (or replaced by an explicit description).
core/swagger-decorator.md
Outdated
/** | ||
* Class SwaggerDecorator. | ||
*/ | ||
class SwaggerDecorator implements NormalizerInterface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final
(according to our CS)
core/swagger-decorator.md
Outdated
class SwaggerDecorator implements NormalizerInterface | ||
{ | ||
/** | ||
* @var NormalizerInterface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Useless, will be inferred by the IDE, can be removed.
core/swagger-decorator.md
Outdated
|
||
2. In Swagger decorator you can acces to the docs | ||
|
||
the variable `docs` is an array compose by paths : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no space before the colon
core/swagger-decorator.md
Outdated
|
||
`$docs['paths']['{path}']['{method}']['parameters']` | ||
|
||
for example if you want to remove all references to your path ’/foos’ in method GET in the swagger you can make in the normalize function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can do it in the normalize
method
Thank you for handling this @tim59, it's definitely useful! What do you think about introducing a real life example (like changing the path as you do in the end of this article) instead of an abstract one? It will make it easier to understand for newcomers. |
@dunglas maybe something like that ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! I just left a few minor comments.
core/swagger.md
Outdated
|
||
## Override Swagger documentation | ||
|
||
Symfony allows to [decorate services](https://symfony.com/doc/current/service_container/service_decoration.html), here we need to decorate the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the
should be removed, blank lines can be removed too
core/swagger.md
Outdated
|
||
### Example | ||
|
||
In the following example, we will see how to override Swagger title and add a custom filter in `/foos` path only for the `GET` method |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the title of the Swagger documentation
[...] for the
GEToperation of the
/foos path
.
core/swagger.md
Outdated
|
||
final class SwaggerDecorator implements NormalizerInterface | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra blank line to remove
core/swagger.md
Outdated
]; | ||
|
||
|
||
// e.g add a custom parameter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remove one level of indentation? And e.g.
(nitpicking)
core/swagger.md
Outdated
} | ||
``` | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra blank line to remove
core/swagger.md
Outdated
@@ -0,0 +1,71 @@ | |||
# Swagger support |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Swagger Support
(title case)
@dunglas , it's update :) Do you think a new section with ApiNormaliser decoration in other PR may be interesting ? |
Yes, definitely :D |
Thank you @tim59 |
@dunglas you're welcome, about the ApiNormaliser decorator do you have advice (Title section, new file?) |
|
Yes i'm agree with that, I will make a PR with what i know because i'm not expert in that section :) |
Hello,
I see some issues(questions) about the modification of the swagger documentation, i did a pull request