Skip to content

Commit

Permalink
fix: OpenApiFactory decoration (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentchalamon authored Sep 30, 2022
1 parent 56e9ea5 commit 09e6974
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 18 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ jobs:
api-platform:
# Only API Platform supported versions
- '^2.6'
- '^2.7@rc'
- '^3.0@rc'
- '^2.7'
- '^3.0'
include:
- php: '8.1'
symfony: '5.4.*'
Expand All @@ -49,15 +49,15 @@ jobs:
- symfony: '6.1.*'
php: '8.0'
# API Platform 3.0 requires PHP >= 8.1 and Symfony >= 6.1.*
- api-platform: '^3.0@rc'
- api-platform: '^3.0'
php: '7.4'
- api-platform: '^3.0@rc'
- api-platform: '^3.0'
php: '8.0'
- api-platform: '^3.0@rc'
- api-platform: '^3.0'
symfony: '4.4.*'
- api-platform: '^3.0@rc'
- api-platform: '^3.0'
symfony: '5.4.*'
- api-platform: '^3.0@rc'
- api-platform: '^3.0'
symfony: '6.0.*'
fail-fast: false
env:
Expand Down
2 changes: 2 additions & 0 deletions config/api_platform.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
class="CoopTilleuls\ForgotPasswordBundle\Bridge\ApiPlatform\OpenApi\OpenApiFactory">
<argument type="service" id="coop_tilleuls_forgot_password.openapi.factory.inner"/>
<argument type="service" id="router"/>
<argument>%coop_tilleuls_forgot_password.user_authorized_fields%</argument>
<argument>%coop_tilleuls_forgot_password.user_password_field%</argument>
</service>
</services>
</container>
5 changes: 4 additions & 1 deletion features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,10 @@ public function iShouldGetAnOpenApiDocumentationUpdated(): void
'required' => ['email'],
'properties' => [
'email' => [
'type' => 'string',
'oneOf' => [
['type' => 'string'],
['type' => 'integer'],
],
],
],
],
Expand Down
19 changes: 13 additions & 6 deletions src/Bridge/ApiPlatform/OpenApi/AbstractOpenApiFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,18 @@ abstract class AbstractOpenApiFactory
{
protected $decorated;
protected $router;
protected $authorizedFields;
protected $passwordField;

/**
* @param LegacyOpenApiFactoryInterface|OpenApiFactoryInterface $decorated
*/
public function __construct($decorated, RouterInterface $router)
public function __construct($decorated, RouterInterface $router, array $authorizedFields, string $passwordField)
{
$this->decorated = $decorated;
$this->router = $router;
$this->authorizedFields = $authorizedFields;
$this->passwordField = $passwordField;
}

public function __invoke(array $context = [])
Expand All @@ -49,9 +53,9 @@ public function __invoke(array $context = [])

$schemas['ForgotPassword:reset'] = new \ArrayObject([
'type' => 'object',
'required' => ['password'],
'required' => [$this->passwordField],
'properties' => [
'password' => [
$this->passwordField => [
'type' => 'string',
],
],
Expand All @@ -63,10 +67,13 @@ public function __invoke(array $context = [])

$schemas['ForgotPassword:request'] = new \ArrayObject([
'type' => 'object',
'required' => ['email'],
'required' => [$this->authorizedFields[0]], // get the first authorized field for reference
'properties' => [
'email' => [
'type' => 'string',
$this->authorizedFields[0] => [
'oneOf' => [
['type' => 'string'],
['type' => 'integer'],
],
],
],
]);
Expand Down
8 changes: 4 additions & 4 deletions src/Bridge/ApiPlatform/OpenApi/OpenApiFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
if (interface_exists(OpenApiFactoryInterface::class)) {
final class OpenApiFactory extends AbstractOpenApiFactory implements OpenApiFactoryInterface
{
public function __construct(OpenApiFactoryInterface $decorated, RouterInterface $router)
public function __construct(OpenApiFactoryInterface $decorated, RouterInterface $router, array $authorizedFields, string $passwordField)
{
parent::__construct($decorated, $router);
parent::__construct($decorated, $router, $authorizedFields, $passwordField);
}

public function __invoke(array $context = []): OpenApi
Expand All @@ -35,9 +35,9 @@ public function __invoke(array $context = []): OpenApi
} else {
final class OpenApiFactory extends AbstractOpenApiFactory implements LegacyOpenApiFactoryInterface
{
public function __construct(LegacyOpenApiFactoryInterface $decorated, RouterInterface $router)
public function __construct(LegacyOpenApiFactoryInterface $decorated, RouterInterface $router, array $authorizedFields, string $passwordField)
{
parent::__construct($decorated, $router);
parent::__construct($decorated, $router, $authorizedFields, $passwordField);
}

public function __invoke(array $context = []): LegacyOpenApi
Expand Down

0 comments on commit 09e6974

Please sign in to comment.