Skip to main content

API Keys (Token)

The security example below was taken from the original Swagger documentation.

const doc = {
...
securityDefinitions: {
apiKeyAuth: {
type: 'apiKey',
in: 'header', // can be 'header', 'query' or 'cookie'
name: 'X-API-KEY', // name of the header, query parameter or cookie
description: 'Some description...'
}
}
};

To see more about the properties of the doc object, see the Advanced Usage section.

In the endpoint, add the #swagger.security, for example:

Example
app.get('/path', (req, res) => {
...
/* #swagger.security = [{
"apiKeyAuth": []
}] */
...
});

NOTE: To assign security to an entire route, see the Property Inheritance section.