Skip to content

Commit

Permalink
Add OpenAPI docs (#1)
Browse files Browse the repository at this point in the history
* Install nelmio api doc bundle

* Add openapi docs

* cq

* Move nelmio apidoc bundle configurations to dev configs
  • Loading branch information
sonnymilton committed May 7, 2024
1 parent 9a3608a commit ec31766
Show file tree
Hide file tree
Showing 12 changed files with 325 additions and 8 deletions.
6 changes: 1 addition & 5 deletions backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/.env.local.php
/.env.*.local
/config/secrets/prod/prod.decrypt.private.php
/public/bundles/
/public/api/assets/bundles
/var/
/vendor/
###< symfony/framework-bundle ###
Expand All @@ -26,7 +26,3 @@ phpstan.neon
/phpunit.xml
###< symfony/phpunit-bridge ###

###> phpunit/phpunit ###
/phpunit.xml
.phpunit.result.cache
###< phpunit/phpunit ###
5 changes: 4 additions & 1 deletion backend/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,24 @@
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.54",
"nelmio/api-doc-bundle": "^4.26",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-doctrine": "^1.3",
"phpstan/phpstan-symfony": "^1.3",
"phpunit/phpunit": "^11.1",
"symfony/asset": "6.4.*",
"symfony/browser-kit": "6.4.*",
"symfony/css-selector": "6.4.*",
"symfony/debug-bundle": "6.4.*",
"symfony/phpunit-bridge": "^7.0",
"symfony/stopwatch": "6.4.*",
"symfony/twig-bundle": "6.4.*",
"symfony/web-profiler-bundle": "6.4.*"
},
"scripts": {
"auto-scripts": {
"cache:clear": "symfony-cmd",
"assets:install %PUBLIC_DIR%": "symfony-cmd"
"assets:install %PUBLIC_DIR%/api/assets": "symfony-cmd"
},
"post-install-cmd": [
"@auto-scripts"
Expand Down
267 changes: 266 additions & 1 deletion backend/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions backend/config/bundles.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true],
Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true],
Symfony\Bundle\DebugBundle\DebugBundle::class => ['dev' => true],
Nelmio\ApiDocBundle\NelmioApiDocBundle::class => ['dev' => true],
];
3 changes: 3 additions & 0 deletions backend/config/packages/dev/assets.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
framework:
assets:
base_path: /api/assets
11 changes: 11 additions & 0 deletions backend/config/packages/dev/nelmio_api_doc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
nelmio_api_doc:
html_config:
assets_mode: cdn
documentation:
info:
title: Flexhub
description: Private storage for symfony/flex recipes
version: 0.x.x
areas: # to filter documented areas
path_patterns:
- ^\/api(?!\/doc$|\/_wdt\/|\/_profiler\/) # Accepts routes under /api except /api/doc, /api/_wdt/*, /api/_profiler/*
12 changes: 12 additions & 0 deletions backend/config/routes/dev/nelmio_api_doc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Expose your documentation as JSON swagger compliant
app.swagger:
path: /api/doc.json
methods: GET
defaults: { _controller: nelmio_api_doc.controller.swagger }

## Requires the Asset component and the Twig bundle
## $ composer require twig asset
app.swagger_ui:
path: /api/doc
methods: GET
defaults: { _controller: nelmio_api_doc.controller.swagger_ui }
Empty file.
2 changes: 2 additions & 0 deletions backend/src/Controller/Api/FlexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace App\Controller\Api;

use App\Flex\Index\IndexLoaderInterface;
use OpenApi\Attributes as OA;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
Expand All @@ -13,6 +14,7 @@
* @phpstan-import-type FlexIndex from IndexLoaderInterface
*/
#[Route('/flex')]
#[OA\Tag('Flex')]
final class FlexController extends AbstractController
{
/** @return FlexIndex */
Expand Down
Loading

0 comments on commit ec31766

Please sign in to comment.