From 5d34f8bece7c3e9f6c66c156ce62c21d6221fb52 Mon Sep 17 00:00:00 2001 From: lutangar Date: Tue, 20 Jul 2021 10:34:15 +0200 Subject: [PATCH 01/17] fix(oas): remove invalid ref property --- src/OpenApi/Documenter/JwtDocumenter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenApi/Documenter/JwtDocumenter.php b/src/OpenApi/Documenter/JwtDocumenter.php index 0d1861e4..4541c55c 100644 --- a/src/OpenApi/Documenter/JwtDocumenter.php +++ b/src/OpenApi/Documenter/JwtDocumenter.php @@ -52,7 +52,7 @@ public function document(OpenApi $openApi, array $context = []): OpenApi ]); $jwt = new PathItem( - 'jwt', + null, '', '', null, From 9f1b9b73d37750d8dd9c54f8c1f1273c42b83099 Mon Sep 17 00:00:00 2001 From: lutangar Date: Thu, 22 Jul 2021 16:57:00 +0200 Subject: [PATCH 02/17] fix(oas): update api platform core this fix a bug where `requestBody` was set empty array whereas it's supposed to be string --- composer.lock | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/composer.lock b/composer.lock index a0a05381..754e51d5 100644 --- a/composer.lock +++ b/composer.lock @@ -8,23 +8,23 @@ "packages": [ { "name": "api-platform/core", - "version": "v2.6.3", + "version": "v2.6.5", "source": { "type": "git", "url": "https://github.com/api-platform/core.git", - "reference": "1ba77218dfe61ca9e6cff1bbb3e9a4a6658d4538" + "reference": "4e22a289e474db454480020ff37d20472668c11c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/api-platform/core/zipball/1ba77218dfe61ca9e6cff1bbb3e9a4a6658d4538", - "reference": "1ba77218dfe61ca9e6cff1bbb3e9a4a6658d4538", + "url": "https://api.github.com/repos/api-platform/core/zipball/4e22a289e474db454480020ff37d20472668c11c", + "reference": "4e22a289e474db454480020ff37d20472668c11c", "shasum": "" }, "require": { "doctrine/inflector": "^1.0 || ^2.0", "fig/link-util": "^1.0", "php": ">=7.1", - "psr/cache": "^1.0", + "psr/cache": "^1.0 || ^2.0 || ^3.0", "psr/container": "^1.0", "symfony/http-foundation": "^4.4 || ^5.1", "symfony/http-kernel": "^4.4 || ^5.1", @@ -36,17 +36,18 @@ }, "conflict": { "doctrine/common": "<2.7", - "doctrine/mongodb-odm": "<2.0", + "doctrine/mongodb-odm": "<2.2", "doctrine/persistence": "<1.3" }, "require-dev": { "behat/behat": "^3.1", "behat/mink": "^1.7", "doctrine/annotations": "^1.7", + "doctrine/cache": "^1.11", "doctrine/common": "^2.11 || ^3.0", "doctrine/data-fixtures": "^1.2.2", "doctrine/doctrine-bundle": "^1.12 || ^2.0", - "doctrine/mongodb-odm": "^2.0", + "doctrine/mongodb-odm": "^2.2", "doctrine/mongodb-odm-bundle": "^4.0", "doctrine/orm": "^2.6.4 || ^3.0", "elasticsearch/elasticsearch": "^6.0 || ^7.0", @@ -135,7 +136,7 @@ "authors": [ { "name": "Kévin Dunglas", - "email": "dunglas@gmail.com", + "email": "kevin@dunglas.fr", "homepage": "https://dunglas.fr" } ], @@ -152,13 +153,17 @@ "rest", "swagger" ], + "support": { + "issues": "https://github.com/api-platform/core/issues", + "source": "https://github.com/api-platform/core/tree/v2.6.5" + }, "funding": [ { "url": "https://tidelift.com/funding/github/packagist/api-platform/core", "type": "tidelift" } ], - "time": "2021-03-07T19:13:33+00:00" + "time": "2021-06-15T16:53:33+00:00" }, { "name": "beberlei/doctrineextensions", From 79e7206f0c391e5102cd9ccae0153387578df95b Mon Sep 17 00:00:00 2001 From: lutangar Date: Mon, 19 Jul 2021 14:47:41 +0200 Subject: [PATCH 03/17] wip: test --- .github/workflows/generate_oas.yml | 56 ++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 .github/workflows/generate_oas.yml diff --git a/.github/workflows/generate_oas.yml b/.github/workflows/generate_oas.yml new file mode 100644 index 00000000..8f745076 --- /dev/null +++ b/.github/workflows/generate_oas.yml @@ -0,0 +1,56 @@ +name: Export Open API Specification file +on: push + +jobs: + symfony: + name: Symfony 4.4 (PHP ${{ matrix.php-versions }}) + runs-on: ubuntu-20.04 + + strategy: + fail-fast: true + matrix: + php-versions: ['7.3'] + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Setup PHP, extensions and composer with shivammathur/setup-php + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + extensions: mbstring, xml, ctype, iconv, intl, pdo, pdo_mysql, dom, filter, gd, iconv, json, mbstring, pdo + tools: phpunit + env: + update: true + COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Check PHP Version + run: php -v + + - name: Validate composer.json and composer.lock + run: composer validate + + - name: Get composer cache directory + id: composer-cache + run: echo "::set-output name=dir::$(composer config cache-files-dir)" + + - name: Cache composer dependencies + uses: actions/cache@v1 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: ${{ runner.os }}-composer- + + - name: Install Composer dependencies + run: composer install + + - name: Check Symfony requirements + run: vendor/bin/requirements-checker + + - name: Check the Symfony console + run: | + bin/console about + + - name: Export Open API Specification file + run: | + php bin/console api:openapi:export --yaml --output=oas.yml From 56cd67b24e4ca1008557df185351210d5df329aa Mon Sep 17 00:00:00 2001 From: lutangar Date: Mon, 19 Jul 2021 14:58:28 +0200 Subject: [PATCH 04/17] chore: composer v2 --- .github/workflows/generate_oas.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/generate_oas.yml b/.github/workflows/generate_oas.yml index 8f745076..565b60ed 100644 --- a/.github/workflows/generate_oas.yml +++ b/.github/workflows/generate_oas.yml @@ -19,7 +19,7 @@ jobs: with: php-version: ${{ matrix.php-versions }} extensions: mbstring, xml, ctype, iconv, intl, pdo, pdo_mysql, dom, filter, gd, iconv, json, mbstring, pdo - tools: phpunit + tools: phpunit, composer:v2 env: update: true COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} From d94b135187c141ae361d04b8793f4585eecd2683 Mon Sep 17 00:00:00 2001 From: lutangar Date: Mon, 19 Jul 2021 15:13:48 +0200 Subject: [PATCH 05/17] chore: symfony cli --- .github/workflows/generate_oas.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/generate_oas.yml b/.github/workflows/generate_oas.yml index 565b60ed..4b903232 100644 --- a/.github/workflows/generate_oas.yml +++ b/.github/workflows/generate_oas.yml @@ -19,7 +19,7 @@ jobs: with: php-version: ${{ matrix.php-versions }} extensions: mbstring, xml, ctype, iconv, intl, pdo, pdo_mysql, dom, filter, gd, iconv, json, mbstring, pdo - tools: phpunit, composer:v2 + tools: phpunit, composer:v2, symfony-cli env: update: true COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -45,7 +45,7 @@ jobs: run: composer install - name: Check Symfony requirements - run: vendor/bin/requirements-checker + run: symfony check:requirements - name: Check the Symfony console run: | From 9a0bbae263c92cff2195095c2c92cce95eb32244 Mon Sep 17 00:00:00 2001 From: lutangar Date: Mon, 19 Jul 2021 15:25:18 +0200 Subject: [PATCH 06/17] chore: add moar caches --- .github/workflows/generate_oas.yml | 49 ++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/.github/workflows/generate_oas.yml b/.github/workflows/generate_oas.yml index 4b903232..c7e371c9 100644 --- a/.github/workflows/generate_oas.yml +++ b/.github/workflows/generate_oas.yml @@ -3,46 +3,60 @@ on: push jobs: symfony: - name: Symfony 4.4 (PHP ${{ matrix.php-versions }}) - runs-on: ubuntu-20.04 - + runs-on: ${{ matrix.operating-system }} + name: Symfony 4.4, PHP ${{ matrix.php-versions }} on ${{ matrix.operating-system }} + env: + extensions: mbstring, xml, ctype, iconv, intl, pdo, pdo_mysql, dom, filter, gd, iconv, json, mbstring, pdo + key: cache-v2 # can be any string, change to clear the extension cache. strategy: fail-fast: true matrix: + operating-system: [ubuntu-latest] php-versions: ['7.3'] steps: - name: Checkout uses: actions/checkout@v2 - - name: Setup PHP, extensions and composer with shivammathur/setup-php + - name: Setup cache environment + id: extcache + uses: shivammathur/cache-extensions@v1 + with: + php-version: ${{ matrix.php-versions }} + extensions: ${{ env.extensions }} + key: ${{ env.key }} + + - name: Cache extensions + uses: actions/cache@v2 + with: + path: ${{ steps.extcache.outputs.dir }} + key: ${{ steps.extcache.outputs.key }} + restore-keys: ${{ steps.extcache.outputs.key }} + + - name: Setup PHP, extension and tools uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php-versions }} - extensions: mbstring, xml, ctype, iconv, intl, pdo, pdo_mysql, dom, filter, gd, iconv, json, mbstring, pdo + extensions: ${{ env.extensions }} tools: phpunit, composer:v2, symfony-cli env: - update: true COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Check PHP Version - run: php -v - - - name: Validate composer.json and composer.lock - run: composer validate - - name: Get composer cache directory id: composer-cache run: echo "::set-output name=dir::$(composer config cache-files-dir)" - - name: Cache composer dependencies - uses: actions/cache@v1 + - name: Cache dependencies + uses: actions/cache@v2 with: path: ${{ steps.composer-cache.outputs.dir }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer- - - name: Install Composer dependencies - run: composer install + - name: Validate composer.json and composer.lock + run: composer validate + + - name: Install dependencies + run: composer install --prefer-dist - name: Check Symfony requirements run: symfony check:requirements @@ -51,6 +65,9 @@ jobs: run: | bin/console about + - name: Run PHPStan + run: phpstan analyse src + - name: Export Open API Specification file run: | php bin/console api:openapi:export --yaml --output=oas.yml From 008f4077cba37b0b70a17b2f8f7a546f395839fd Mon Sep 17 00:00:00 2001 From: lutangar Date: Mon, 19 Jul 2021 15:42:24 +0200 Subject: [PATCH 07/17] chore: update stan command --- .github/workflows/generate_oas.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/generate_oas.yml b/.github/workflows/generate_oas.yml index c7e371c9..2ba5fdfe 100644 --- a/.github/workflows/generate_oas.yml +++ b/.github/workflows/generate_oas.yml @@ -66,7 +66,7 @@ jobs: bin/console about - name: Run PHPStan - run: phpstan analyse src + run: composer stan - name: Export Open API Specification file run: | From 95d222f0792b643b13c22ad30e6a5f9033d98850 Mon Sep 17 00:00:00 2001 From: lutangar Date: Mon, 19 Jul 2021 15:47:17 +0200 Subject: [PATCH 08/17] chore: add phpunit install step --- .github/workflows/generate_oas.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/generate_oas.yml b/.github/workflows/generate_oas.yml index 2ba5fdfe..6449f4df 100644 --- a/.github/workflows/generate_oas.yml +++ b/.github/workflows/generate_oas.yml @@ -65,6 +65,10 @@ jobs: run: | bin/console about + - name: Run PHPUnit install to generate autoload file required by PHPStan + run: | + bin/phpunit install + - name: Run PHPStan run: composer stan From 9f1471fb95df5b136897c17ae5e83cd80ff582fe Mon Sep 17 00:00:00 2001 From: lutangar Date: Mon, 19 Jul 2021 16:07:25 +0200 Subject: [PATCH 09/17] chore: add update oas in generator repo --- .github/workflows/generate_oas.yml | 37 ++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/.github/workflows/generate_oas.yml b/.github/workflows/generate_oas.yml index 6449f4df..36e30a28 100644 --- a/.github/workflows/generate_oas.yml +++ b/.github/workflows/generate_oas.yml @@ -6,8 +6,10 @@ jobs: runs-on: ${{ matrix.operating-system }} name: Symfony 4.4, PHP ${{ matrix.php-versions }} on ${{ matrix.operating-system }} env: - extensions: mbstring, xml, ctype, iconv, intl, pdo, pdo_mysql, dom, filter, gd, iconv, json, mbstring, pdo - key: cache-v2 # can be any string, change to clear the extension cache. + EXTENSIONS: mbstring, xml, ctype, iconv, intl, pdo, pdo_mysql, dom, filter, gd, iconv, json, mbstring, pdo + CACHE_KEY: cache-v2 # can be any string, change to clear the extension cache. + GENERATOR_PATH: api-client-generator + strategy: fail-fast: true matrix: @@ -22,8 +24,8 @@ jobs: uses: shivammathur/cache-extensions@v1 with: php-version: ${{ matrix.php-versions }} - extensions: ${{ env.extensions }} - key: ${{ env.key }} + EXTENSIONS: ${{ env.EXTENSIONS }} + key: ${{ env.CACHE_KEY }} - name: Cache extensions uses: actions/cache@v2 @@ -36,7 +38,7 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php-versions }} - extensions: ${{ env.extensions }} + extensions: ${{ env.EXTENSIONS }} tools: phpunit, composer:v2, symfony-cli env: COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -72,6 +74,31 @@ jobs: - name: Run PHPStan run: composer stan + - name: Checkout generator repository + uses: actions/checkout@v2 + with: + repository: ${{ github.repository_owner }}/api-client-generator + token: ${{ secrets.PAT }} + path: ${{ env.GENERATOR_PATH }} + - name: Export Open API Specification file run: | php bin/console api:openapi:export --yaml --output=oas.yml + + - uses: peter-evans/create-pull-request@v3 + with: + token: ${{ secrets.PAT }} + path: ${{ env.GENERATOR_PATH }} + commit-message: ${{ github.event.pull_request.title }} + committer: GitHub + author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com> + branch: ${{ github.event.pull_request.head.ref }} + title: ${{ github.event.pull_request.title }} + body: | + > ${{ github.event.pull_request.body }} + > Created by @${{ github.actor }} via ${{ github.event.pull_request.html_url }} + delete-branch: true + labels: ${{ join(github.event.pull_request.labels.*.name) }} + assignees: ${{ join(github.event.pull_request.assignees.*.login) }} + reviewers: ${{ join(github.event.pull_request.requested_reviewers.*.login) }} +# draft: true \ No newline at end of file From 0b3a8dcf63ab56cdad1a0b793e3c63a4a6644815 Mon Sep 17 00:00:00 2001 From: lutangar Date: Thu, 22 Jul 2021 16:05:03 +0200 Subject: [PATCH 10/17] add path --- .github/workflows/generate_oas.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/generate_oas.yml b/.github/workflows/generate_oas.yml index 36e30a28..3b7b6ce6 100644 --- a/.github/workflows/generate_oas.yml +++ b/.github/workflows/generate_oas.yml @@ -83,7 +83,7 @@ jobs: - name: Export Open API Specification file run: | - php bin/console api:openapi:export --yaml --output=oas.yml + php bin/console api:openapi:export --yaml --output=${{ env.GENERATOR_PATH }}/oas.yml - uses: peter-evans/create-pull-request@v3 with: From bfe60d66db3e11f10721e1baf65bbee2d638524e Mon Sep 17 00:00:00 2001 From: lutangar Date: Thu, 22 Jul 2021 17:28:10 +0200 Subject: [PATCH 11/17] test --- .github/workflows/generate_oas.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/generate_oas.yml b/.github/workflows/generate_oas.yml index 3b7b6ce6..b5960614 100644 --- a/.github/workflows/generate_oas.yml +++ b/.github/workflows/generate_oas.yml @@ -89,7 +89,7 @@ jobs: with: token: ${{ secrets.PAT }} path: ${{ env.GENERATOR_PATH }} - commit-message: ${{ github.event.pull_request.title }} + commit-message: ${{ github.event.pull_request.title }}-removeme committer: GitHub author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com> branch: ${{ github.event.pull_request.head.ref }} From 8b83f16073f1170c3d737c8ff2ad62b0af6519f4 Mon Sep 17 00:00:00 2001 From: lutangar Date: Thu, 22 Jul 2021 17:33:59 +0200 Subject: [PATCH 12/17] test --- .github/workflows/generate_oas.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/generate_oas.yml b/.github/workflows/generate_oas.yml index b5960614..0b4785cc 100644 --- a/.github/workflows/generate_oas.yml +++ b/.github/workflows/generate_oas.yml @@ -1,5 +1,10 @@ name: Export Open API Specification file -on: push +on: + # Trigger the workflow on pull requests targeting the master branch + pull_request: + types: [assigned, unassigned, opened, reopened, synchronize, edited, labeled, unlabeled, edited, closed] + branches: + - master jobs: symfony: From 10ac4f83079ef1d65bdd703295eddae7dba33bda Mon Sep 17 00:00:00 2001 From: lutangar Date: Thu, 22 Jul 2021 17:36:23 +0200 Subject: [PATCH 13/17] fix file name --- .github/workflows/generate_oas.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/generate_oas.yml b/.github/workflows/generate_oas.yml index 0b4785cc..09d29055 100644 --- a/.github/workflows/generate_oas.yml +++ b/.github/workflows/generate_oas.yml @@ -88,7 +88,7 @@ jobs: - name: Export Open API Specification file run: | - php bin/console api:openapi:export --yaml --output=${{ env.GENERATOR_PATH }}/oas.yml + php bin/console api:openapi:export --yaml --output=${{ env.GENERATOR_PATH }}/oas.yaml - uses: peter-evans/create-pull-request@v3 with: From d31c911aa93ef24991f4d8af2624b0da3eca712a Mon Sep 17 00:00:00 2001 From: lutangar Date: Fri, 23 Jul 2021 15:55:30 +0200 Subject: [PATCH 14/17] chore(api): don't allow stats count edition from the API Mostly when creating/updating a notice. --- src/Entity/Notice.php | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/Entity/Notice.php b/src/Entity/Notice.php index a0e51d58..554b08cd 100644 --- a/src/Entity/Notice.php +++ b/src/Entity/Notice.php @@ -190,6 +190,8 @@ class Notice private $badgedCount = 0; /** + * The number of time the notice has been displayed in a list. + * * @var int * * @ORM\Column(name="displayed_count", type="integer", nullable=false, options={"default"=0}) @@ -198,42 +200,52 @@ class Notice private $displayedCount = 0; /** + * The number of time the notice has been displayed in full. + * * @var int * * @ORM\Column(name="unfolded_count", type="integer", nullable=false, options={"default"=0}) - * @Groups({"create", "read", "update"}) + * @Groups({"read"}) */ private $unfoldedCount = 0; /** + * The number of time the notice has been clicked. + * * @var int * * @ORM\Column(name="clicked_count", type="integer", nullable=false, options={"default"=0}) - * @Groups({"create", "read", "update"}) + * @Groups({"read"}) */ private $clickedCount = 0; /** + * The number of time the notice has been liked. + * * @var int * * @ORM\Column(name="liked_count", type="integer", nullable=false, options={"default"=0}) - * @Groups({"create", "read", "update"}) + * @Groups({"read"}) */ private $likedCount = 0; /** + * The number of time the notice has been disliked. + * * @var int * * @ORM\Column(name="disliked_count", type="integer", nullable=false, options={"default"=0}) - * @Groups({"create", "read", "update"}) + * @Groups({"read"}) */ private $dislikedCount = 0; /** + * The number of time the notice has been dismissed. + * * @var int * * @ORM\Column(name="dismissed_count", type="integer", nullable=false, options={"default"=0}) - * @Groups({"create", "read", "update"}) + * @Groups({"read"}) */ private $dismissedCount = 0; From 5e084bcf92109caaf86bdbd09e6733ba5702da89 Mon Sep 17 00:00:00 2001 From: lutangar Date: Fri, 23 Jul 2021 15:55:30 +0200 Subject: [PATCH 15/17] chore(api): don't allow stats count edition from the API Mostly when creating/updating a notice. --- src/Entity/Notice.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Entity/Notice.php b/src/Entity/Notice.php index 554b08cd..d4515c05 100644 --- a/src/Entity/Notice.php +++ b/src/Entity/Notice.php @@ -185,7 +185,7 @@ class Notice * @var int * * @ORM\Column(name="badged_count", type="integer", nullable=false, options={"default"=0}) - * @Groups({"create", "read", "update"}) + * @Groups({"read"}) */ private $badgedCount = 0; @@ -195,7 +195,7 @@ class Notice * @var int * * @ORM\Column(name="displayed_count", type="integer", nullable=false, options={"default"=0}) - * @Groups({"create", "read", "update"}) + * @Groups({"read"}) */ private $displayedCount = 0; From 242232d6d4fdfac97d3f1e3cd6f2ad42bfeff28c Mon Sep 17 00:00:00 2001 From: lutangar Date: Sat, 24 Jul 2021 18:56:50 +0200 Subject: [PATCH 16/17] fix(api-v4): fix various authentication config bugs --- config/bundles.php | 3 +++ config/packages/api_platform.yaml | 2 ++ config/packages/framework.yaml | 3 ++- config/packages/security.yaml | 8 +++----- config/routes/api_platform.yaml | 5 ----- config/routes/jwt.yaml | 2 +- docs/using_api_v4.md | 11 +++++++---- src/OpenApi/Documenter/JwtDocumenter.php | 2 +- tests/e2e/AuthenticationTest.php | 24 ++++++++++++++++++++++++ tests/e2e/GetNoticesTest.php | 8 ++++++++ 10 files changed, 51 insertions(+), 17 deletions(-) create mode 100644 tests/e2e/AuthenticationTest.php diff --git a/config/bundles.php b/config/bundles.php index 98b20b25..011baab6 100644 --- a/config/bundles.php +++ b/config/bundles.php @@ -25,4 +25,7 @@ Symplify\ConsoleColorDiff\ConsoleColorDiffBundle::class => ['dev' => true, 'test' => true], ApiPlatform\Core\Bridge\Symfony\Bundle\ApiPlatformBundle::class => ['all' => true], Lexik\Bundle\JWTAuthenticationBundle\LexikJWTAuthenticationBundle::class => ['all' => true], + Nelmio\Alice\Bridge\Symfony\NelmioAliceBundle::class => ['dev' => true, 'test' => true], + Fidry\AliceDataFixtures\Bridge\Symfony\FidryAliceDataFixturesBundle::class => ['dev' => true, 'test' => true], + Hautelook\AliceBundle\HautelookAliceBundle::class => ['dev' => true, 'test' => true], ]; diff --git a/config/packages/api_platform.yaml b/config/packages/api_platform.yaml index 191f91e0..8032da2d 100644 --- a/config/packages/api_platform.yaml +++ b/config/packages/api_platform.yaml @@ -1,4 +1,6 @@ api_platform: + # @deprecated https://api-platform.com/docs/core/fosuser-bundle/ + enable_fos_user: true show_webby: false title: DisMoi OpenAPI description: | diff --git a/config/packages/framework.yaml b/config/packages/framework.yaml index 28cf53b0..c4130555 100644 --- a/config/packages/framework.yaml +++ b/config/packages/framework.yaml @@ -18,4 +18,5 @@ framework: templating: engines: [ 'twig' ] - + # @deprecated https://api-platform.com/docs/core/fosuser-bundle/ + form: { enabled: true } \ No newline at end of file diff --git a/config/packages/security.yaml b/config/packages/security.yaml index 792ce523..c2dfda26 100644 --- a/config/packages/security.yaml +++ b/config/packages/security.yaml @@ -15,12 +15,10 @@ security: dev: pattern: ^/(_(profiler|wdt)|css|images|js)/ security: false - api_v4_docs: - pattern: ^/api/v4(|/|/docs|/docs/|/docs[.][a-z0-9]+)$ - anonymous: true api_v4: - pattern: ^/api/v4 + pattern: ^/v4 stateless: true + anonymous: true provider: fos_userbundle http_basic: realm: "Authentication Desk" @@ -28,7 +26,7 @@ security: authenticators: - lexik_jwt_authentication.jwt_token_authenticator json_login: - check_path: /api/v4/_jwt + check_path: /v4/_jwt username_path: username password_path: password success_handler: lexik_jwt_authentication.handler.authentication_success diff --git a/config/routes/api_platform.yaml b/config/routes/api_platform.yaml index 745431ca..b16d036e 100644 --- a/config/routes/api_platform.yaml +++ b/config/routes/api_platform.yaml @@ -1,9 +1,4 @@ api_platform: - resource: . - type: api_platform - prefix: /api/v4 - -api_v4: resource: . type: api_platform prefix: /v4 diff --git a/config/routes/jwt.yaml b/config/routes/jwt.yaml index 86898084..14ba17a6 100644 --- a/config/routes/jwt.yaml +++ b/config/routes/jwt.yaml @@ -3,5 +3,5 @@ authentication_token: # We use the `_jwt` semantics instead of a more explicit `login` or `authorize` # because the OAS ecosystem is still young and some third-parties (vendors) expect `_jwt`. # Ideally there would be aliases, but I don't know how to make one easily. - path: /api/v4/_jwt + path: /v4/_jwt methods: ['POST'] \ No newline at end of file diff --git a/docs/using_api_v4.md b/docs/using_api_v4.md index 6296bc6a..0afbfeea 100644 --- a/docs/using_api_v4.md +++ b/docs/using_api_v4.md @@ -6,13 +6,12 @@ ## Endpoints The endpoint to publish `Notice` as an authenticated `User` is only available on API V4. -Available endpoints are (will be) described at https://notices.bulles.fr/api/v4/docs.html - +Available endpoints are (will be) described at https://api.dismoi.io/v4/docs.html ## Clients Client libraries could be generated in any programming languages using the OpenApi definition file. -The definition file is available in `Json` format at: https://notices.bulles.fr/api/v4/docs.json +The definition file is available in `Json` format at: https://api.dismoi.io/v4/docs.json ## Authentication @@ -20,4 +19,8 @@ The definition file is available in `Json` format at: https://notices.bulles.fr/ > Authentication system is only available on API V4. Authentication is implemented as a _Json Web Token_ (JWT). -Currently login via `username` + `password`. \ No newline at end of file +Currently login via `username` + `password`. + + +jwt: +$(SYMFONY) lexik:jwt:generate-keypair diff --git a/src/OpenApi/Documenter/JwtDocumenter.php b/src/OpenApi/Documenter/JwtDocumenter.php index 4541c55c..8f5d51f8 100644 --- a/src/OpenApi/Documenter/JwtDocumenter.php +++ b/src/OpenApi/Documenter/JwtDocumenter.php @@ -102,7 +102,7 @@ public function document(OpenApi $openApi, array $context = []): OpenApi ) ), ); - $openApi->getPaths()->addPath('/api/v4/_jwt', $jwt); + $openApi->getPaths()->addPath('/v4/_jwt', $jwt); return $openApi; } diff --git a/tests/e2e/AuthenticationTest.php b/tests/e2e/AuthenticationTest.php new file mode 100644 index 00000000..26c4013c --- /dev/null +++ b/tests/e2e/AuthenticationTest.php @@ -0,0 +1,24 @@ +request('POST', '/v4/_jwt', [ + 'headers' => ['Content-Type' => 'application/json'], + 'json' => [ + 'username' => 'lmem', + 'password' => 'LM3M!P4SSW0RD', + ], + ]); + + $json = json_decode($response->getContent(), true); + $this->assertResponseIsSuccessful(); + $this->assertArrayHasKey('token', $json); + } +} \ No newline at end of file diff --git a/tests/e2e/GetNoticesTest.php b/tests/e2e/GetNoticesTest.php index da6422ae..cb3f85a1 100644 --- a/tests/e2e/GetNoticesTest.php +++ b/tests/e2e/GetNoticesTest.php @@ -46,4 +46,12 @@ static function ($noticeData) { self::assertCount(4, $diff); } + + public function testGetNoticesV4(): void + { + $this->client->request('GET', '/v4/notices'); + $response = $this->client->getResponse(); + + $this->assertEquals(200, $response->getStatusCode()); + } } From 9351c5799e9847ea628eca9ed7dfdb9591ac0dc1 Mon Sep 17 00:00:00 2001 From: lutangar Date: Sat, 24 Jul 2021 19:00:41 +0200 Subject: [PATCH 17/17] fix(api-v4): fix authentication test fix(api-v4): fix authentication test fix(api-v4): fix authentication test fix(api-v4): fix authentication test --- tests/e2e/AuthenticationTest.php | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/tests/e2e/AuthenticationTest.php b/tests/e2e/AuthenticationTest.php index 26c4013c..e9b7f52d 100644 --- a/tests/e2e/AuthenticationTest.php +++ b/tests/e2e/AuthenticationTest.php @@ -1,24 +1,26 @@ request('POST', '/v4/_jwt', [ - 'headers' => ['Content-Type' => 'application/json'], - 'json' => [ - 'username' => 'lmem', - 'password' => 'LM3M!P4SSW0RD', + $this->client->request( + 'POST', + '/v4/_jwt', + [], + [], + [ + 'CONTENT_TYPE' => 'application/json', ], - ]); - + '{"username":"lmem", "password":"LM3M!P4SSW0RD"}' + ); + $response = $this->client->getResponse(); $json = json_decode($response->getContent(), true); $this->assertResponseIsSuccessful(); $this->assertArrayHasKey('token', $json); } -} \ No newline at end of file +}