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

OpenAPI 3 root level security not supported #322

Open
airedwin opened this issue Jul 20, 2022 · 3 comments
Open

OpenAPI 3 root level security not supported #322

airedwin opened this issue Jul 20, 2022 · 3 comments
Labels
pinned Issues that will not be automatically closed

Comments

@airedwin
Copy link

airedwin commented Jul 20, 2022

Describe the bug
Open API supports the keyword 'security' at the root level. Currently there is no commonProperties for 'security' so it gets added to the default 'paths'.
See: https://swagger.io/docs/specification/authentication/ Step 2: Applying security

To Reproduce
Steps to reproduce the behavior:
Create an OpenAPI 3.0 yaml spec with security defined and applied at the root level.
Generate a swagger json file.
The 'security' object gets put into the 'paths' object in the resulting json.

Expected behavior
The 'security' object if at the root level in the yaml should also be at the root level in the resulting json.

Screenshots
N/A

@stale
Copy link

stale bot commented Sep 18, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Sep 18, 2022
@daniloab daniloab added the pinned Issues that will not be automatically closed label Sep 19, 2022
@stale stale bot closed this as completed Sep 26, 2022
@daniloab daniloab reopened this Sep 26, 2022
@stale stale bot removed the wontfix label Sep 26, 2022
@ZebboKlaufix
Copy link

It seems that this error still occures. Is there any chance to bypass the issue?

@duluca
Copy link

duluca commented Sep 2, 2023

Bump.

edit:
I discovered a workaround. It works if you use it in the Options object. Given this is an app level config, this is an acceptable place to place this configuration.

Example below:

const options: Options = {
  swaggerDefinition: {
    openapi: '3.0.2',
    components: {
      securitySchemes: {
        bearerAuth: {
          type: 'http',
          scheme: 'bearer',
          bearerFormat: 'JWT',
        },
      },
      security: {
        bearerAuth: [],
      },
   },
}

In contrast, this doesn't work:

/**
 * @openapi
 * components:
 *   securitySchemes:
 *     bearerAuth:
 *       type: http
 *       scheme: bearer
 *       bearerFormat: JWT
 *   responses:
 *     UnauthorizedError:
 *       description: Unauthorized
 *       content:
 *         application/json:
 *           schema:
 *             $ref: "#/components/schemas/ServerMessage"
 *   schemas:
 *     ServerMessage:
 *       type: object
 *       properties:
 *         message:
 *           type: string
 *   security:
 *     - bearerAuth: []
 */

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pinned Issues that will not be automatically closed
Projects
None yet
Development

No branches or pull requests

4 participants