Skip to content

Commit

Permalink
code challenge 10 solution
Browse files Browse the repository at this point in the history
  • Loading branch information
jschaedl committed Sep 30, 2023
1 parent 1098a2c commit 3fbb6c6
Show file tree
Hide file tree
Showing 34 changed files with 1,297 additions and 44 deletions.
6 changes: 6 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,9 @@ DATABASE_URL=sqlite:///%kernel.project_dir%/var/data.db
# DATABASE_URL="mysql://db_user:[email protected]:3306/db_name?serverVersion=5.7"
# DATABASE_URL="postgresql://db_user:[email protected]:5432/db_name?serverVersion=13&charset=utf8"
###< doctrine/doctrine-bundle ###

###> lexik/jwt-authentication-bundle ###
JWT_SECRET_KEY=%kernel.project_dir%/config/jwt/private.pem
JWT_PUBLIC_KEY=%kernel.project_dir%/config/jwt/public.pem
JWT_PASSPHRASE=cde703ea51cc6b270df31f4c8232d98f23da500b8b232252758dcd1b33b22c5b
###< lexik/jwt-authentication-bundle ###
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ composer.lock
/phpunit.xml
.phpunit.cache
###< phpunit/phpunit ###

###> lexik/jwt-authentication-bundle ###
/config/jwt/*.pem
###< lexik/jwt-authentication-bundle ###
30 changes: 30 additions & 0 deletions CODING-CHALLENGE-11.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# RESTful Webservices in Symfony

## Coding Challenge 11 - API Documentation

### Tasks

Let's document our API using the Nelmio ApiDocBundle.

### Solution

- require Nelmio's ApiDocBundle: `composer req nelmio/api-doc-bundle`
- adjust the bundle's configuration:

```yaml
nelmio_api_doc:
documentation:
info:
title: RESTful Webservices in Symfony
description: "Workshop: RESTful Webservices in Symfony!"
version: 1.0.0
areas:
path_patterns:
- ^/api(?!/doc$) # Accepts routes under /api except /api/doc
- ^/workshops
- ^/attendees
```
- add some annotation to your controllers, check https://github.com/zircote/swagger-php/tree/master/Examples for examples
- to be able to see the api documentation website, you need to install Twig and the Asset component `composer require twig asset`
- and adjust the routing configuration for the `nelmio/api-doc-bundle` in `config/routes/nelmio_api_doc.yaml`
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ dev-init: #
$(SYMFONY_CMD) doctrine:database:create
$(SYMFONY_CMD) doctrine:schema:create
$(SYMFONY_CMD) hautelook:fixtures:load -n --no-bundles
$(SYMFONY_CMD) lexik:jwt:generate-keypair --overwrite -q

fixtures: ## load fixtures
$(SYMFONY_CMD) hautelook:fixtures:load -n -vvv --no-bundles
Expand Down
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"doctrine/doctrine-bundle": "^2.10",
"doctrine/doctrine-migrations-bundle": "^3.2",
"doctrine/orm": "^2.16",
"lexik/jwt-authentication-bundle": "^2.19",
"phpdocumentor/reflection-docblock": "^5.3",
"phpstan/phpdoc-parser": "^1.24",
"ramsey/uuid": "*",
Expand All @@ -22,6 +23,7 @@
"symfony/property-access": "6.3.*",
"symfony/property-info": "6.3.*",
"symfony/runtime": "6.3.*",
"symfony/security-bundle": "6.3.*",
"symfony/serializer": "6.3.*",
"symfony/validator": "6.3.*",
"symfony/yaml": "6.3.*",
Expand Down
Loading

0 comments on commit 3fbb6c6

Please sign in to comment.