Forum Discussion

vk22's avatar
vk22
New Contributor
3 years ago

How to show Authorize button on OAS 3 swagger in javascript?

I am using this config for swagger:

{
routePrefix: "/documentation",
exposeRoute: true,
openapi: {
openapi: "3.0.3",
},
swagger: {
info: {
title: "Sample API",
description: "Sample API Swagger",
version: "1.0",
},
externalDocs: {
url: "https://swagger.io",
description: "Find more info here",
},
host: "localhost:8080",
schemes: ["http", "https"],
consumes: ["application/json"],
produces: ["application/json"],
security: [
{
bearerAuth: [],
},
],
},
components: {
securitySchemes: {
bearerAuth: {
type: "apiKey",
name: "Authorization",
in: "header",
},
},
},
}

 and then I am trying to put this in the endpoint schema:

security: [
{
bearerAuth: [],
}
],

 But this doesn't seem to work. 

  • I was able to figure out the issue. components and security array had to be inside openapi object. I am using the above config with fastify-swagger.

  • vk22's avatar
    vk22
    New Contributor

    I was able to figure out the issue. components and security array had to be inside openapi object. I am using the above config with fastify-swagger.