How can I define the security scheme and apply the authorization to my endpoint(s)?
{
"openapi": "3.0.3",
"info": {
"description": "NodeJS API documentation of SSV",
"version": "1.0.0",
"title": "SSV APIs"
},
"components": {
"securitySchemes": {
"BearerAuth": {
"name": "Authorization",
"in": "header",
"type": "apiKey",
"scheme": "bearer",
"bearerFormat": "JWT",
"description": "Enter your bearer token in the format Bearer <token>"
}
}
}
}
import swaggerUi from "swagger-ui-express";
import openapiSpecification from "../swaggerAPI";
const options = {
explorer: true,
};
app.use(
"/api-docs",
swaggerUi.serve,
swaggerUi.setup(openapiSpecification, options)
);
Couple things with your description.
"swagger": "2.0"
has a completely different structure than the one used. You should define"openapi": "3.0.3"
to match your file content.Adding the
security
array at the root of the file will require the authorization for all endpoints defined.Alternatively, you can set the authorization at individual endpoints.