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

Can't define default security scheme using attributes. #1190

Closed
edipoReboucas opened this issue Apr 6, 2022 · 0 comments · Fixed by #1191
Closed

Can't define default security scheme using attributes. #1190

edipoReboucas opened this issue Apr 6, 2022 · 0 comments · Fixed by #1191
Labels

Comments

@edipoReboucas
Copy link
Contributor

edipoReboucas commented Apr 6, 2022

In current attribute API is not possible to define the default security scheme.

The security attribute is not exposed on OpenApi\Attributes\OpenApi.

As workaround, I inherited de attribute and rewrite the constructor.

#[\Attribute(\Attribute::TARGET_CLASS)]
class CustomOpenApi extends OA\OpenApi
{
    /**
     * @param Server[]|null             $servers
     * @param Tag[]|null                $tags
     * @param array<string,string>|null $x
     * @param Attachable[]|null         $attachables
     */
    public function __construct(
        string $openapi = self::DEFAULT_VERSION,
        ?Info $info = null,
        ?array $servers = null,
        ?array $tags = null,
        ?ExternalDocumentation $externalDocs = null,
        // annotation
        ?array $x = null,
        ?array $attachables = null,
        ?array $security = null //  --- WORKAROUND
    ) {
        \OpenApi\Annotations\OpenApi::__construct([
            'openapi' => $openapi,
            'x' => $x ?? Generator::UNDEFINED,
            'security' => $security ?? Generator::UNDEFINED, //--- WORKAROUND
            'value' => $this->combine($info, $servers, $tags, $externalDocs, $attachables),
        ]);
    }

}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants