-
-
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
Changes from 4 commits
288c41e
6eadfc0
cb2e831
2d511a9
57be724
77ba643
0e355a2
71ae524
f008db5
d5caed3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# 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 commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
`api_platform.swagger.normalizer.documentation` | ||
|
||
1. declare the decorator and class | ||
|
||
```yaml | ||
# app/config/services.yml | ||
|
||
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 commentThe 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) |
||
arguments: ['@app.swagger.swagger_decorator.inner'] | ||
``` | ||
|
||
```php | ||
<?php | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a comment with the path of the |
||
|
||
namespace AppBundle\Swagger; | ||
|
||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface; | ||
|
||
/** | ||
* Class SwaggerDecorator. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Useless, can be remove (or replaced by an explicit description). |
||
*/ | ||
class SwaggerDecorator implements NormalizerInterface | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
{ | ||
/** | ||
* @var NormalizerInterface | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Useless, will be inferred by the IDE, can be removed. |
||
*/ | ||
private $decorated; | ||
|
||
public function __construct(NormalizerInterface $decorated) | ||
{ | ||
$this->decorated = $decorated; | ||
} | ||
|
||
public function normalize($object, $format = null, array $context = []) | ||
{ | ||
$docs = $this->decorated->normalize($object, $format, $context); | ||
|
||
// Your code | ||
|
||
return $docs; | ||
} | ||
|
||
public function supportsNormalization($data, $format = null) | ||
{ | ||
return $this->decorated->supportsNormalization($data, $format); | ||
} | ||
} | ||
``` | ||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. no space before the colon |
||
|
||
`$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 commentThe reason will be displayed to describe this comment to others. Learn more. you can do it in the |
||
|
||
```php | ||
unset($docs['paths']['/foos']['get']); | ||
``` | ||
|
||
|
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 titleSwagger Support
.