I generated the swagger.json listed below using tsoa for TypeScript. However when I add an access token to the authorize menu from swagger and make a request to one of my endpoints I am expecting the access token to be inside the x-access-token header. However, the header is not added to my request. What do I need to change to my swagger.json to enable the authorize header?
Swagger.json
{
"components":{
"examples":{
},
"headers":{
},
"parameters":{
},
"requestBodies":{
},
"responses":{
},
"schemas":{
"Parameter":{
"properties":{
"property":{
"type":"string"
},
"value":{
"type":"string"
}
},
"required":[
"property",
"value"
],
"type":"object",
"additionalProperties":false
},
"Header":{
"properties":{
"key":{
"type":"string"
},
"value":{
"type":"string"
}
},
"required":[
"key",
"value"
],
"type":"object",
"additionalProperties":false
},
"AuthenticationEndpoint":{
"properties":{
"host":{
"type":"string"
},
"method":{
"type":"string"
},
"requestLine":{
"type":"string"
},
"queryParameters":{
"items":{
"$ref":"#/components/schemas/Parameter"
},
"type":"array"
},
"headers":{
"items":{
"$ref":"#/components/schemas/Header"
},
"type":"array"
},
"body":{
"properties":{
},
"type":"object"
}
},
"required":[
"host",
"method",
"requestLine"
],
"type":"object",
"additionalProperties":false
},
"Endpoint":{
"properties":{
"host":{
"type":"string"
},
"method":{
"type":"string"
},
"requestLine":{
"type":"string"
},
"queryParameters":{
"items":{
"$ref":"#/components/schemas/Parameter"
},
"type":"array"
},
"headers":{
"items":{
"$ref":"#/components/schemas/Header"
},
"type":"array"
},
"body":{
"properties":{
},
"type":"object"
},
"secured":{
"type":"boolean"
},
"authenticationHeader":{
"type":"string"
},
"authenticationAction":{
"$ref":"#/components/schemas/AuthenticationEndpoint"
}
},
"required":[
"host",
"method",
"requestLine"
],
"type":"object",
"additionalProperties":false
},
"Order":{
"properties":{
"_id":{
"type":"string"
},
"command":{
"type":"string"
},
"action":{
"$ref":"#/components/schemas/Endpoint"
}
},
"required":[
"command",
"action"
],
"type":"object",
"additionalProperties":false
},
"ApplicationUser":{
"properties":{
"_id":{
"type":"string"
},
"email":{
"type":"string"
},
"password":{
"type":"string"
},
"firstname":{
"type":"string"
},
"lastname":{
"type":"string"
},
"role":{
"type":"string"
},
"language":{
"type":"string"
},
"commands":{
"items":{
"$ref":"#/components/schemas/Order"
},
"type":"array"
}
},
"required":[
"email",
"password",
"firstname"
],
"type":"object",
"additionalProperties":false
}
},
"securitySchemes":{
"bearer":{
"type":"apiKey",
"name":"x-access-token",
"in":"header"
}
}
},
"info":{
"title":"custom_voice_commands",
"version":"1.0.0",
"description":"<b>This API facilitates custom voice commands to execute the corresponding configured API endpoint</b>",
"license":{
"name":"ISC"
},
"contact":{
}
},
"openapi":"3.0.0",
"paths":{
"/admin/register":{
"post":{
"operationId":"RegisterAdmin",
"responses":{
"200":{
"description":"Ok",
"content":{
"application/json":{
"schema":{
"type":"string"
}
}
}
}
},
"tags":[
"Admin"
],
"security":[
],
"parameters":[
],
"requestBody":{
"required":true,
"content":{
"application/json":{
"schema":{
"$ref":"#/components/schemas/ApplicationUser"
}
}
}
}
}
},
"/admin/commands/create":{
"post":{
"operationId":"CreateCommand",
"responses":{
"201":{
"description":"Created",
"content":{
"application/json":{
"schema":{
}
}
}
}
},
"tags":[
"Admin Commands"
],
"security":[
{
"jwt":[
"admin"
]
}
],
"parameters":[
],
"requestBody":{
"required":true,
"content":{
"application/json":{
"schema":{
"$ref":"#/components/schemas/Order"
}
}
}
}
}
},
"/admin/commands/update/{orderId}":{
"put":{
"operationId":"UpdateCommand",
"responses":{
"204":{
"description":"No content"
}
},
"tags":[
"Admin Commands"
],
"security":[
{
"jwt":[
"admin"
]
}
],
"parameters":[
{
"in":"path",
"name":"orderId",
"required":true,
"schema":{
"type":"string"
}
}
],
"requestBody":{
"required":true,
"content":{
"application/json":{
"schema":{
"$ref":"#/components/schemas/Order"
}
}
}
}
}
},
"/admin/commands/delete/{orderId}":{
"delete":{
"operationId":"DeleteCommand",
"responses":{
"204":{
"description":"No content"
}
},
"tags":[
"Admin Commands"
],
"security":[
{
"jwt":[
"admin"
]
}
],
"parameters":[
{
"in":"path",
"name":"orderId",
"required":true,
"schema":{
"type":"string"
}
}
]
}
},
"/orders/execute-voice-command":{
"post":{
"operationId":"ExecuteCommand",
"responses":{
"200":{
"description":"Ok",
"content":{
"application/json":{
"schema":{
}
}
}
}
},
"tags":[
"Orders"
],
"security":[
],
"parameters":[
]
}
},
"/orders":{
"get":{
"operationId":"GetOrders",
"responses":{
"200":{
"description":"Ok",
"content":{
"application/json":{
"schema":{
"items":{
"$ref":"#/components/schemas/Order"
},
"type":"array"
}
}
}
}
},
"tags":[
"Orders"
],
"security":[
],
"parameters":[
]
}
},
"/orders/{orderId}":{
"get":{
"operationId":"GetOrder",
"responses":{
"200":{
"description":"Ok",
"content":{
"application/json":{
"schema":{
"$ref":"#/components/schemas/Order"
}
}
}
}
},
"tags":[
"Orders"
],
"security":[
],
"parameters":[
{
"in":"path",
"name":"orderId",
"required":true,
"schema":{
"type":"string"
}
}
]
}
},
"/user/register":{
"post":{
"operationId":"RegisterUser",
"responses":{
"200":{
"description":"Ok",
"content":{
"application/json":{
"schema":{
"type":"string"
}
}
}
}
},
"tags":[
"User"
],
"security":[
{
"jwt":[
"admin"
]
}
],
"parameters":[
],
"requestBody":{
"required":true,
"content":{
"application/json":{
"schema":{
"$ref":"#/components/schemas/ApplicationUser"
}
}
}
}
}
},
"/commands/execute":{
"post":{
"description":"<b>Upload a command as a mono recording formatted to a wav file with 16kHz</b> <br> <b>The endpoint corresponding to the command will be executed.</b>",
"requestBody":{
"required":true,
"content":{
"multipart/form-data":{
"schema":{
"type":"object",
"properties":{
"voiceCommand":{
"type":"string",
"format":"binary"
}
}
}
}
}
}
}
}
},
"servers":[
{
"url":"/"
}
]
}
Update the following swagger.json solved my problem (removed schemas due to character limit)
{
"components":{
"securitySchemes":{
"jwt":{
"type":"apiKey",
"name":"x-access-token",
"in":"header"
}
}
},
"info":{
"title":"custom_voice_commands",
"version":"1.0.0",
"description":"<b>This API facilitates custom voice commands to execute the corresponding configured API endpoint</b>",
"license":{
"name":"ISC"
},
"contact":{
}
},
"openapi":"3.0.0",
"paths":{
"/admin/register":{
"post":{
"operationId":"RegisterAdmin",
"responses":{
"200":{
"description":"Ok",
"content":{
"application/json":{
"schema":{
"type":"string"
}
}
}
}
},
"tags":[
"Admin"
],
"security":[
],
"parameters":[
],
"requestBody":{
"required":true,
"content":{
"application/json":{
"schema":{
"$ref":"#/components/schemas/ApplicationUser"
}
}
}
}
}
},
"/admin/commands/create":{
"post":{
"operationId":"CreateCommand",
"responses":{
"201":{
"description":"Created",
"content":{
"application/json":{
"schema":{
}
}
}
}
},
"tags":[
"Admin Commands"
],
"security":[
{
"jwt":[
"admin"
]
}
],
"parameters":[
],
"requestBody":{
"required":true,
"content":{
"application/json":{
"schema":{
"$ref":"#/components/schemas/Order"
}
}
}
}
}
},
"/admin/commands/update/{orderId}":{
"put":{
"operationId":"UpdateCommand",
"responses":{
"204":{
"description":"No content"
}
},
"tags":[
"Admin Commands"
],
"security":[
{
"jwt":[
"admin"
]
}
],
"parameters":[
{
"in":"path",
"name":"orderId",
"required":true,
"schema":{
"type":"string"
}
}
],
"requestBody":{
"required":true,
"content":{
"application/json":{
"schema":{
"$ref":"#/components/schemas/Order"
}
}
}
}
}
},
"/admin/commands/delete/{orderId}":{
"delete":{
"operationId":"DeleteCommand",
"responses":{
"204":{
"description":"No content"
}
},
"tags":[
"Admin Commands"
],
"security":[
{
"jwt":[
"admin"
]
}
],
"parameters":[
{
"in":"path",
"name":"orderId",
"required":true,
"schema":{
"type":"string"
}
}
]
}
},
"/orders/execute-voice-command":{
"post":{
"operationId":"ExecuteCommand",
"responses":{
"200":{
"description":"Ok",
"content":{
"application/json":{
"schema":{
}
}
}
}
},
"tags":[
"Orders"
],
"security":[
],
"parameters":[
]
}
},
"/orders":{
"get":{
"operationId":"GetOrders",
"responses":{
"200":{
"description":"Ok",
"content":{
"application/json":{
"schema":{
"items":{
"$ref":"#/components/schemas/Order"
},
"type":"array"
}
}
}
}
},
"tags":[
"Orders"
],
"security":[
],
"parameters":[
]
}
},
"/orders/{orderId}":{
"get":{
"operationId":"GetOrder",
"responses":{
"200":{
"description":"Ok",
"content":{
"application/json":{
"schema":{
"$ref":"#/components/schemas/Order"
}
}
}
}
},
"tags":[
"Orders"
],
"security":[
],
"parameters":[
{
"in":"path",
"name":"orderId",
"required":true,
"schema":{
"type":"string"
}
}
]
}
},
"/user/register":{
"post":{
"operationId":"RegisterUser",
"responses":{
"200":{
"description":"Ok",
"content":{
"application/json":{
"schema":{
"type":"string"
}
}
}
}
},
"tags":[
"User"
],
"security":[
{
"jwt":[
"admin"
]
}
],
"parameters":[
],
"requestBody":{
"required":true,
"content":{
"application/json":{
"schema":{
"$ref":"#/components/schemas/ApplicationUser"
}
}
}
}
}
},
"/commands/execute":{
"post":{
"description":"<b>Upload a command as a mono recording formatted to a wav file with 16kHz</b> <br> <b>The endpoint corresponding to the command will be executed.</b>",
"requestBody":{
"required":true,
"content":{
"multipart/form-data":{
"schema":{
"type":"object",
"properties":{
"voiceCommand":{
"type":"string",
"format":"binary"
}
}
}
}
}
}
}
}
},
"servers":[
{
"url":"/"
}
]
}
You have defined the security scheme, but you haven't actually used it anywhere. On many of your endpoints you've got a blank
security
section, and on others you're using "jwt", which is not your defined "bearer" scheme. (Note: You are using an API key, NOT bearer authentication, your name is misleading.)Place something like this in the endpoints you wish to have use this auth type.