Skip to content
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

Add swagger_ui_extra_configuration to Swagger configuration #3731

Merged
merged 4 commits into from
Feb 23, 2021

Conversation

dvc
Copy link
Contributor

@dvc dvc commented Sep 21, 2020

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tickets fixes #3730
License MIT
Doc PR api-platform/docs/pull/1168

@dvc dvc marked this pull request as ready for review September 22, 2020 09:34
@dvc
Copy link
Contributor Author

dvc commented Sep 22, 2020

Code quality breaks in other files: https://insight.symfony.com/projects/92d78899-946c-4282-89a3-ac92344f9a93/analyses/6895

Do i need to fix it? And how? :)

@soyuka
Copy link
Member

soyuka commented Sep 29, 2020

Nice work, as it's a new feature could you target the master branch please?

I'll add some comments. Don't worry about the symfony insight.

@@ -300,6 +300,20 @@ private function addSwaggerSection(ArrayNodeDefinition $rootNode): void
->end()
->end()
->end()
->arrayNode('display')
Copy link
Member

Choose a reason for hiding this comment

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

What do you think about using ui instead of display?

swagger:
    ui:
        doc_expansion: 'full'

@@ -344,6 +344,8 @@ private function registerSwaggerConfiguration(ContainerBuilder $container, array
$container->setParameter('api_platform.enable_swagger_ui', $config['enable_swagger_ui']);
$container->setParameter('api_platform.enable_re_doc', $config['enable_re_doc']);
$container->setParameter('api_platform.swagger.api_keys', $config['swagger']['api_keys']);
$container->setParameter('api_platform.swagger.doc_expansion', $config['swagger']['display']['doc_expansion']);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
$container->setParameter('api_platform.swagger.doc_expansion', $config['swagger']['display']['doc_expansion']);
$container->setParameter('api_platform.swagger_ui.doc_expansion', $config['swagger']['display']['doc_expansion']);

@@ -344,6 +344,8 @@ private function registerSwaggerConfiguration(ContainerBuilder $container, array
$container->setParameter('api_platform.enable_swagger_ui', $config['enable_swagger_ui']);
$container->setParameter('api_platform.enable_re_doc', $config['enable_re_doc']);
$container->setParameter('api_platform.swagger.api_keys', $config['swagger']['api_keys']);
$container->setParameter('api_platform.swagger.doc_expansion', $config['swagger']['display']['doc_expansion']);
$container->setParameter('api_platform.swagger.filter', $config['swagger']['display']['filter']);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
$container->setParameter('api_platform.swagger.filter', $config['swagger']['display']['filter']);
$container->setParameter('api_platform.swagger_ui.filter', $config['swagger']['display']['filter']);

@dvc dvc changed the base branch from 2.5 to master September 30, 2020 08:48
@dvc
Copy link
Contributor Author

dvc commented Sep 30, 2020

@soyuka , thank you for review. I've fix it.

ApiPlatform\Core\Bridge\Symfony\Bundle\Action\SwaggerUiAction is deprecated in master.

@dvc
Copy link
Contributor Author

dvc commented Dec 12, 2020

@soyuka , hello!

I've update this PR. Can you review it?

@@ -139,6 +151,8 @@ private function getContext(Request $request, Documentation $documentation): arr

$swaggerData = [
'url' => $this->urlGenerator->generate('api_doc', ['format' => 'json']),
'docExpansion' => $this->swaggerDocExpansion,
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we just add an extra_config key or something like this allowing to pass a variable map to Swagger UI. So we'll support all possible options and we will be future-proof.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not shure.
There are some already used config values. Merging testing required.
What about config validation? Is it user's responsibility? Should any options to be blacklisted for any reason?

Base automatically changed from master to main January 23, 2021 21:59
@alanpoulain alanpoulain force-pushed the swagger_ui_config_patch branch from 8147cfb to a0b9149 Compare February 19, 2021 16:37
@alanpoulain alanpoulain changed the title WIP: add docExpansion and filter to swagger.display config Add ui_extra_configuration to Swagger configuration Feb 19, 2021
@alanpoulain
Copy link
Member

alanpoulain commented Feb 19, 2021

Now uses a ui_extra_configuration key, like @dunglas asked.
Tested on the demo, with:

api_platform:
    swagger:
        versions: [3, 2]
        api_keys:
            apiKey:
                name: Authorization
                type: header
        swagger_ui_extra_configuration:
            filter: true
            docExpansion: none

It shows:
image

@alanpoulain alanpoulain changed the title Add ui_extra_configuration to Swagger configuration Add swagger_ui_extra_configuration to Swagger configuration Feb 23, 2021
@alanpoulain alanpoulain merged commit 930c930 into api-platform:main Feb 23, 2021
@alanpoulain
Copy link
Member

Thank you @dvc!

camohob pushed a commit to camohob/core that referenced this pull request Mar 25, 2021
camohob pushed a commit to camohob/core that referenced this pull request Mar 25, 2021
camohob added a commit to camohob/core that referenced this pull request Mar 25, 2021
camohob pushed a commit to camohob/core that referenced this pull request Mar 25, 2021
camohob pushed a commit to camohob/core that referenced this pull request Apr 7, 2021
camohob added a commit to camohob/core that referenced this pull request Apr 7, 2021
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.

expand/collapce tags/operations, filter by tags and other swagger ui config options support
4 participants