Skip to content

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

Merged
merged 10 commits into from
Aug 22, 2017

Conversation

Timherlaud
Copy link
Contributor

Hello,
I see some issues(questions) about the modification of the swagger documentation, i did a pull request

@@ -0,0 +1,70 @@
# Override Swagger documentation
Copy link
Member

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.

# Override Swagger documentation


Symfony allow to [decorates services](https://symfony.com/doc/current/service_container/service_decoration.html), here we need to decorate the
Copy link
Member

Choose a reason for hiding this comment

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

allows to decorate

services:
app.swagger.swagger_decorator:
decorates: api_platform.swagger.normalizer.documentation
class: AppBundle\Swagger\SwaggerDecorator
Copy link
Member

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)

```

```php
<?php
Copy link
Member

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?

use Symfony\Component\Serializer\Normalizer\NormalizerInterface;

/**
* Class SwaggerDecorator.
Copy link
Member

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).

/**
* Class SwaggerDecorator.
*/
class SwaggerDecorator implements NormalizerInterface
Copy link
Member

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)

class SwaggerDecorator implements NormalizerInterface
{
/**
* @var NormalizerInterface
Copy link
Member

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.


2. In Swagger decorator you can acces to the docs

the variable `docs` is an array compose by paths :
Copy link
Member

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


`$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
Copy link
Member

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

@dunglas
Copy link
Member

dunglas commented Aug 22, 2017

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.

@Timherlaud
Copy link
Contributor Author

Timherlaud commented Aug 22, 2017

@dunglas maybe something like that ?
Do you think a new section with ApiNormaliser decoration in other PR may be interesting ?

Copy link
Member

@dunglas dunglas left a 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
Copy link
Member

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
Copy link
Member

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
{

Copy link
Member

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
Copy link
Member

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
}
```


Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

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

Swagger Support (title case)

@Timherlaud
Copy link
Contributor Author

@dunglas , it's update :)

Do you think a new section with ApiNormaliser decoration in other PR may be interesting ?

@dunglas
Copy link
Member

dunglas commented Aug 22, 2017

Do you think a new section with ApiNormaliser decoration in other PR may be interesting ?

Yes, definitely :D

@dunglas dunglas merged commit 0d0dfac into api-platform:master Aug 22, 2017
@dunglas
Copy link
Member

dunglas commented Aug 22, 2017

Thank you @tim59

@Timherlaud
Copy link
Contributor Author

@dunglas you're welcome, about the ApiNormaliser decorator do you have advice (Title section, new file?)

@dunglas
Copy link
Member

dunglas commented Aug 22, 2017

The Serialization Process in serialization.md? We cloud explain the overall process, list the available serializers and what they do, point to the Symfony's serializer docs and add a section about decorators. WDYT?

@Timherlaud
Copy link
Contributor Author

Yes i'm agree with that, I will make a PR with what i know because i'm not expert in that section :)
Thx for your help

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.

2 participants