GithubHelp home page GithubHelp logo

Comments (6)

acassan avatar acassan commented on June 2, 2024 1

As workaround, I rewrite decorator

<?php
declare(strict_types=1);

namespace App\OpenApi;

use ApiPlatform\Core\OpenApi\Factory\OpenApiFactoryInterface;
use ApiPlatform\Core\OpenApi\OpenApi;
use ApiPlatform\Core\OpenApi\Model;

final class ForgotPasswordDecorator implements OpenApiFactoryInterface
{
    public function __construct(
        private OpenApiFactoryInterface $decorated
    ) {}

    public function __invoke(array $context = []): OpenApi
    {
        $openApi = ($this->decorated)($context);
        $schemas = $openApi->getComponents()->getSchemas();

        $schemas['ForgotPassword:reset'] = new \ArrayObject([
            'type' => 'object',
            'required' => ['password'],
            'properties' => [
                'password' => [
                    'type' => 'string',
                ],
            ],
        ]);

        $schemas['ForgotPassword:validate'] = new \ArrayObject([
            'type' => 'object',
        ]);

        $schemas['ForgotPassword:request'] = new \ArrayObject([
            'type' => 'object',
            'required' => ['email'],
            'properties' => [
                'email' => [
                    'type' => 'string',
                ],
            ],
        ]);

        $pathItem = new Model\PathItem(
            ref: 'ForgotPassword',
            post: new Model\Operation(
                operationId: 'postForgotPassword',
                tags: ['Forgot password'],
                responses: [
                    204 => [
                        'description' => 'Valid email address, no matter if user exists or not',
                    ],
                    400 => [
                        'description' => 'Missing email parameter or invalid format',
                    ],
                ],
                summary: 'Generates a token and send email',
                requestBody: new Model\RequestBody(
                    description: 'Request a new password',
                    content: new \ArrayObject([
                        'application/json' => [
                            'schema' => [
                                '$ref' => '#/components/schemas/ForgotPassword:request',
                            ],
                        ],
                    ]),
                ),
            ),
        );
        $openApi->getPaths()->addPath('/forgot-password/', $pathItem);

        $pathItem = new Model\PathItem(
            ref: 'ForgotPassword',
            get: new Model\Operation(
                operationId: 'getForgotPassword',
                tags: ['Forgot password'],
                responses: [
                    200 => [
                        'description' => 'Authenticated user',
                        'content' => [
                            'application/json' => [
                                'schema' => [
                                    '$ref' => '#/components/schemas/ForgotPassword:validate',
                                ],
                            ],
                        ],
                    ],
                    404 => [
                        'description' => 'Token not found or expired',
                    ],
                ],
                summary: 'Validates token',
                parameters: [
                    [
                        'name' => 'token',
                        'in' => 'path',
                        'required' => true,
                        'schema' => [
                            'type' => 'string',
                        ],
                    ],
                ]
            ),
            post: new Model\Operation(
                operationId: 'postForgotPasswordToken',
                tags: ['Forgot password'],
                responses: [
                    204 => [
                        'description' => 'Email address format valid, no matter if user exists or not',
                    ],
                    400 => [
                        'description' => 'Missing password parameter',
                    ],
                    404 => [
                        'description' => 'Token not found',
                    ],
                ],
                summary: 'Resets user password from token',
                parameters: [
                    [
                        'name' => 'token',
                        'in' => 'path',
                        'required' => true,
                        'schema' => [
                            'type' => 'string',
                        ],
                    ],
                ],
                requestBody: new Model\RequestBody(
                    description: 'Reset password',
                    content: new \ArrayObject([
                        'application/json' => [
                            'schema' => [
                                '$ref' => '#/components/schemas/ForgotPassword:reset',
                            ],
                        ],
                    ]),
                ),
            ),
        );
        $openApi->getPaths()->addPath('/forgot-password/{token}', $pathItem);

        return $openApi;
    }
}
`

Documentation is well generated

from cooptilleulsforgotpasswordbundle.

acassan avatar acassan commented on June 2, 2024 1

from cooptilleulsforgotpasswordbundle.

vincentchalamon avatar vincentchalamon commented on June 2, 2024

Thanks @acassan,
Could you open a PR to fix it on dev-main, please? But be careful: the code is still compatible with PHP7

from cooptilleulsforgotpasswordbundle.

acassan avatar acassan commented on June 2, 2024

PR Opened, let me know, I tried to write with PHP7 compat

from cooptilleulsforgotpasswordbundle.

vincentchalamon avatar vincentchalamon commented on June 2, 2024

Thank you @acassan, I've merged your PR on main. Could you try it on your project and tell me it's working as expected, please?

from cooptilleulsforgotpasswordbundle.

vincentchalamon avatar vincentchalamon commented on June 2, 2024

Tagged as v1.3.5
Thank you @acassan!

from cooptilleulsforgotpasswordbundle.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.