Skip to content

Commit 7e478c2

Browse files
committed
Merge branch 'master' into 5.x
# Conflicts: # src/DependencyInjection/NelmioApiDocExtension.php # src/ModelDescriber/Annotations/AnnotationsReader.php # src/ModelDescriber/ObjectModelDescriber.php # tests/Functional/Controller/ApiController81.php # tests/Functional/Controller/JMSController81.php # tests/Functional/ControllerTest.php
2 parents 6b09469 + 5972e02 commit 7e478c2

39 files changed

+872
-213
lines changed

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
# CHANGELOG
22

3+
## 4.38.0
4+
* Added a `#[Ignore]` attribute that allows a property to be excluded from the generated schema.
5+
```php
6+
<?php
7+
8+
use Nelmio\ApiDocBundle\Attribute\Ignore;
9+
10+
class Foo
11+
{
12+
#[Ignore]
13+
private string $ignoredProperty;
14+
}
15+
```
16+
* Added support for the `#[MapUploadedFile]` symfony controller argument attribute
17+
18+
## 4.37.0
19+
* Added Stoplight as an alternative UI option. https://stoplight.io/open-source/elements.
20+
321
## 4.36.1
422
- Passing an array key `value` with a list of strings to the `Areas` annotation/attribute is deprecated. Pass the list of strings directly.
523
```diff

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
NelmioApiDocBundle
22
==================
33

4-
[![Build Status](https://img.shields.io/github/actions/workflow/status/nelmio/NelmioApiDocBundle/continuous-integration.yml?branch=master&style=flat-square)](https://github.com/nelmio/NelmioApiDocBundle/actions?query=workflow:CI)
5-
[![Total Downloads](https://poser.pugx.org/nelmio/api-doc-bundle/downloads)](https://packagist.org/packages/nelmio/api-doc-bundle)
6-
[![Latest Stable
7-
Version](https://poser.pugx.org/nelmio/api-doc-bundle/v/stable)](https://packagist.org/packages/nelmio/api-doc-bundle)
4+
[![Build Status](https://img.shields.io/github/actions/workflow/status/nelmio/NelmioApiDocBundle/continuous-integration.yml?branch=master&style=flat-square)](https://github.com/nelmio/NelmioApiDocBundle/actions?query=workflow:CI)
5+
[![Codecov](https://img.shields.io/codecov/c/github/nelmio/NelmioApiDocBundle?branch=master&style=flat-square)](https://app.codecov.io/gh/nelmio/NelmioApiDocBundle)
6+
[![Total Downloads](https://img.shields.io/packagist/dt/nelmio/api-doc-bundle?style=flat-square)](https://packagist.org/packages/nelmio/api-doc-bundle)
7+
[![Latest Stable Version](https://img.shields.io/packagist/v/nelmio/api-doc-bundle?label=stable&style=flat-square)](https://packagist.org/packages/nelmio/api-doc-bundle)
8+
[![PHP Version](https://img.shields.io/packagist/dependency-v/nelmio/api-doc-bundle/PHP?style=flat-square)](https://packagist.org/packages/nelmio/api-doc-bundle)
89

910
The **NelmioApiDocBundle** bundle allows you to generate a decent documentation
1011
for your APIs.

config/services.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
<argument type="string">redocly</argument>
2222
</service>
2323

24+
<service id="nelmio_api_doc.controller.stoplight" class="Nelmio\ApiDocBundle\Controller\SwaggerUiController" public="true">
25+
<argument type="service" id="nelmio_api_doc.render_docs" />
26+
<argument type="string">stoplight</argument>
27+
</service>
28+
2429
<service id="nelmio_api_doc.controller.swagger" alias="nelmio_api_doc.controller.swagger_json" public="true" />
2530

2631
<service id="nelmio_api_doc.controller.swagger_json" class="Nelmio\ApiDocBundle\Controller\DocumentationController" public="true">

docs/areas.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ Then update your routing to be able to access your different documentations:
5353
# methods: GET
5454
# defaults: { _controller: nelmio_api_doc.controller.redocly, area: default }
5555
56+
# With Stoplight
57+
# app/config/routing.yaml
58+
#app.stoplight:
59+
# path: /api/doc/{area}
60+
# methods: GET
61+
# defaults: { _controller: nelmio_api_doc.controller.stoplight, area: default }
62+
5663
# To expose them as JSON
5764
#app.swagger.areas:
5865
# path: /api/doc/{area}.json

docs/commands.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ or configure UI configuration, use the ``--html-config`` option.
3838
- ``swagger_ui_config`` - `configure Swagger UI`_
3939
- ``"supportedSubmitMethods":[]`` disables the sandbox
4040
- ``redocly_config`` - `configure Redocly`_
41+
- ``stoplight_config`` - `configure Stoplight`_
4142

4243
.. code-block:: bash
4344

docs/configuration_reference.rst

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ The bundle configuration is stored under the ``nelmio_api_doc`` key in your appl
4040
swagger_ui_config: []
4141
# https://redocly.com/docs/redoc/config/
4242
redocly_config: []
43+
# https://docs.stoplight.io/docs/elements/b074dc47b2826-elements-configuration-options
44+
stoplight_config: []
4345
# Filter the routes that are documented
4446
areas:
4547
default:
@@ -157,7 +159,7 @@ html_config
157159

158160
**type**: ``dictionary``
159161
**default**: ``[]``
160-
**allowed keys**: ``assets_mode``, ``swagger_ui_config``, ``redocly_config``
162+
**allowed keys**: ``assets_mode``, ``swagger_ui_config``, ``redocly_config``, ``stoplight_config``
161163

162164
UI configuration options.
163165

@@ -172,6 +174,12 @@ UI configuration options.
172174
swagger_ui_config: []
173175
# https://redocly.com/docs/redoc/config/
174176
redocly_config: []
177+
# https://docs.stoplight.io/docs/elements/b074dc47b2826-elements-configuration-options
178+
stoplight_config: []
179+
180+
.. versionadded:: 4.37
181+
182+
The `stoplight_config` option was added in 4.37.
175183

176184
areas
177185
~~~~~

docs/index.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ By default, only routes under ``/api`` are documented. Update the regexp at ``ne
7373
methods: GET
7474
defaults: { _controller: nelmio_api_doc.controller.redocly }
7575
76+
.. code-block:: yaml
77+
78+
# config/routes.yaml
79+
app.stoplight:
80+
path: /api/doc
81+
methods: GET
82+
defaults: { _controller: nelmio_api_doc.controller.stoplight }
83+
7684
If you also want to expose it in JSON, register this route:
7785

7886
.. code-block:: yaml

docs/symfony_attributes.rst

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,35 @@ Customizing the documentation of the request body can be done by adding the ``#[
6161
groups: ["create"],
6262
)
6363
64+
MapUploadedFile
65+
-------------------------------
66+
67+
Using the `Symfony MapUploadedFile`_ attribute allows NelmioApiDocBundle to automatically generate your request body documentation for your endpoint.
68+
69+
.. versionadded:: 4.37
70+
71+
The :class:`Symfony\\Component\\HttpKernel\\Attribute\\MapUploadedFile` attribute was introduced in Symfony 7.1.
72+
73+
74+
Modify generated documentation
75+
~~~~~~~
76+
77+
Customizing the documentation of the uploaded file can be done by adding the ``#[OA\RequestBody]`` attribute with the corresponding ``#[OA\MediaType]`` and ``#[OA\Schema]`` to your controller method.
78+
79+
.. code-block:: php-attributes
80+
81+
#[OA\RequestBody(
82+
description: 'Describe the body',
83+
content: [
84+
new OA\MediaType('multipart/form-data', new OA\Schema(
85+
properties: [new OA\Property(
86+
property: 'file',
87+
description: 'Describe the file'
88+
)],
89+
)),
90+
],
91+
)]
92+
6493
Complete example
6594
----------------------
6695

@@ -90,6 +119,10 @@ Complete example
90119
use AppBundle\UserDTO;
91120
use AppBundle\UserQuery;
92121
use OpenApi\Attributes as OA;
122+
use Symfony\Component\HttpKernel\Attribute\MapQueryParameter;
123+
use Symfony\Component\HttpKernel\Attribute\MapQueryString;
124+
use Symfony\Component\HttpKernel\Attribute\MapRequestPayload;
125+
use Symfony\Component\HttpKernel\Attribute\MapUploadedFile;
93126
use Symfony\Component\Routing\Annotation\Route;
94127
95128
class UserController
@@ -133,6 +166,26 @@ Complete example
133166
{
134167
// ...
135168
}
169+
170+
/**
171+
* Upload a profile picture
172+
*/
173+
#[Route('/api/users/picture', methods: ['POST'])]
174+
#[OA\RequestBody(
175+
description: 'Content of the profile picture upload request',
176+
content: [
177+
new OA\MediaType('multipart/form-data', new OA\Schema(
178+
properties: [new OA\Property(
179+
property: 'file',
180+
description: 'File containing the profile picture',
181+
)],
182+
)),
183+
],
184+
)]
185+
public function createUser(#[MapUploadedFile] UploadedFile $picture)
186+
{
187+
// ...
188+
}
136189
}
137190
138191
Customization
@@ -183,4 +236,5 @@ Make sure to use at least php 8.1 (attribute support) to make use of this functi
183236
.. _`Symfony MapQueryString`: https://symfony.com/doc/current/controller.html#mapping-the-whole-query-string
184237
.. _`Symfony MapQueryParameter`: https://symfony.com/doc/current/controller.html#mapping-query-parameters-individually
185238
.. _`Symfony MapRequestPayload`: https://symfony.com/doc/current/controller.html#mapping-request-payload
239+
.. _`Symfony MapUploadedFile`: https://symfony.com/doc/current/controller.html#mapping-uploaded-files
186240
.. _`RouteArgumentDescriberInterface`: https://github.com/DjordyKoert/NelmioApiDocBundle/blob/master/src/RouteDescriber/RouteArgumentDescriber/RouteArgumentDescriberInterface.php

phpstan-baseline.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ parameters:
77

88
-
99
message: "#^Call to method render\\(\\) on an unknown class Twig_Environment\\.$#"
10-
count: 2
10+
count: 3
1111
path: src/Render/Html/HtmlOpenApiRenderer.php
1212

1313
-

phpstan.dist.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ parameters:
2929
universalObjectCratesClasses:
3030
- OpenApi\Context
3131
treatPhpDocTypesAsCertain: false
32-
checkGenericClassInNonGenericObjectType: false
3332
ignoreErrors:
33+
- identifier: missingType.generics
3434
- '#^Property class@anonymous/tests/.* has no type specified.$#'

0 commit comments

Comments
 (0)