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

Authorization header is required while being set #734

Closed
2 tasks done
nick-berilov opened this issue Jun 27, 2023 · 3 comments · Fixed by #769
Closed
2 tasks done

Authorization header is required while being set #734

nick-berilov opened this issue Jun 27, 2023 · 3 comments · Fixed by #769

Comments

@nick-berilov
Copy link

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

4.18.0

Plugin version

8.6.0

Node.js version

16

Operating system

Linux

Operating system version (i.e. 20.04, 11.3, 10)

22.04

Description

Is there a way to hide authorization header from OpenAPI 3.1.0 UI, so that I would not need to set a dummy unused value every time?

alt text

Steps to Reproduce

import { fastify } from "fastify";
import fs from "@fastify/swagger";
import fsu from "@fastify/swagger-ui";

const app = fastify();

await app.register(fs, {
  openapi: {
    openapi: "3.1.0",
    components: {
      securitySchemes: {
        bearerAuth: {
          type: "http",
          scheme: "bearer",
        },
      },
    },
  },
});

await app.register(fsu);

app.get(
  "/",
  {
    schema: {
      headers: {
        type: "object",
        properties: { authorization: { type: "string" } },
        required: ["authorization"],
      },
      security: [{ bearerAuth: [] }],
    },
  },
  async (request, reply) => {
    return { hello: "world" };
  }
);

app
  .listen({ port: 3001 })
  .then(() => {
    console.log("listening");
  })
  .catch((err) => console.log(err));

Expected Behavior

Authorization valued should not be required if already set or authorization property should be hidden in UI

@Uzlopak
Copy link
Contributor

Uzlopak commented Jun 27, 2023

You are configuring it wrong. You have to define the security schema globally when initializing fastify-swagger.

@nick-berilov
Copy link
Author

nick-berilov commented Jun 27, 2023

@Uzlopak even if I move security: [{ bearerAuth: [] }], from routes to swagger coonfig it doesn't change anything

@alexey-sh
Copy link

Any chance to fix it?

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

Successfully merging a pull request may close this issue.

3 participants