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

Chore/oas export #423

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 109 additions & 0 deletions .github/workflows/generate_oas.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
name: Export Open API Specification file
on:
# Trigger the workflow on pull requests targeting the master branch
pull_request:
types: [assigned, unassigned, opened, reopened, synchronize, edited, labeled, unlabeled, edited, closed]
Copy link
Member

Choose a reason for hiding this comment

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

duplicate edited

branches:
- master

jobs:
symfony:
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
CACHE_KEY: cache-v2 # can be any string, change to clear the extension cache.
GENERATOR_PATH: api-client-generator

strategy:
fail-fast: true
matrix:
operating-system: [ubuntu-latest]
php-versions: ['7.3']
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup cache environment
id: extcache
uses: shivammathur/cache-extensions@v1
with:
php-version: ${{ matrix.php-versions }}
EXTENSIONS: ${{ env.EXTENSIONS }}
key: ${{ env.CACHE_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: ${{ env.EXTENSIONS }}
tools: phpunit, composer:v2, symfony-cli
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- 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: 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

- name: Check the Symfony console
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

- 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=${{ env.GENERATOR_PATH }}/oas.yaml

- uses: peter-evans/create-pull-request@v3
Copy link
Member

Choose a reason for hiding this comment

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

Can you explain why we create a PR here ?

with:
token: ${{ secrets.PAT }}
path: ${{ env.GENERATOR_PATH }}
commit-message: ${{ github.event.pull_request.title }}-removeme
committer: GitHub <[email protected]>
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
23 changes: 14 additions & 9 deletions composer.lock

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

3 changes: 3 additions & 0 deletions config/bundles.php
Original file line number Diff line number Diff line change
Expand Up @@ -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],
];
2 changes: 2 additions & 0 deletions config/packages/api_platform.yaml
Original file line number Diff line number Diff line change
@@ -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: |
Expand Down
3 changes: 2 additions & 1 deletion config/packages/framework.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ framework:

templating:
engines: [ 'twig' ]

# @deprecated https://api-platform.com/docs/core/fosuser-bundle/
form: { enabled: true }
8 changes: 3 additions & 5 deletions config/packages/security.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,18 @@ 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"
guard:
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
Expand Down
5 changes: 0 additions & 5 deletions config/routes/api_platform.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
api_platform:
resource: .
type: api_platform
prefix: /api/v4

api_v4:
resource: .
type: api_platform
prefix: /v4
2 changes: 1 addition & 1 deletion config/routes/jwt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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']
11 changes: 7 additions & 4 deletions docs/using_api_v4.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,21 @@
## 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

> Authentication system is only available on API V4.

Authentication is implemented as a _Json Web Token_ (JWT).
Currently login via `username` + `password`.
Currently login via `username` + `password`.


jwt:
$(SYMFONY) lexik:jwt:generate-keypair
26 changes: 19 additions & 7 deletions src/Entity/Notice.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,55 +185,67 @@ 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;

/**
* 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})
* @Groups({"create", "read", "update"})
* @Groups({"read"})
*/
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;

Expand Down
4 changes: 2 additions & 2 deletions src/OpenApi/Documenter/JwtDocumenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function document(OpenApi $openApi, array $context = []): OpenApi
]);

$jwt = new PathItem(
'jwt',
null,
'',
'',
null,
Expand Down Expand Up @@ -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;
}
Expand Down
Loading