Unable to setup
oneEyedSunday opened this issue · 4 comments
oneEyedSunday commented
Hello Bakman, I'm having issues setting up.
This is the stack trace
Error: Missing or invalid input: 'options.swaggerDefinition' or 'options.definition' is required
at module.exports (/Users/ispoa/BetaQuick/AtomicKit/server/node_modules/swagger-jsdoc/src/lib.js:23:11)
at getResponseExpress (/Users/ispoa/BetaQuick/AtomicKit/server/node_modules/@tiemma/sonic-express/index.js:23:40)
For the configuration, I've copied the example config from the readme.
This is what my setup looks like
const { getResponseExpress } = require('@tiemma/sonic-express');
const swaggerDefinition = {
openapi: '3.0.1',
info: {
title: 'Demo server',
version: require('../../package.json').version,
description: 'Random description on API related stuff'
},
servers: [
{
url: '/api/v1',
description: 'Host system path'
}
],
definitions: {},
paths: {}
};
// options for the swagger docs
const options = (fileName) => ({
// import swaggerDefinitions
swaggerDefinition,
// path to the API docs
apis: [fileName]
});
const swaggerPath = require('path').join(__dirname, '../../docs/swagger.json');
application.use(getResponseExpress(application, options, swaggerPath));
oneEyedSunday commented
So I looked into the code, there's an issue on https://github.com/Tiemma/sonic-express/blob/master/index.js#L23
options
is a function (at least in the readme).
The below code snippet fixes the issue
const swaggerSpec = swaggerOptions ? swaggerJSDoc(swaggerOptions(swaggerFilePath)) : {};
oneEyedSunday commented
Closing this as for some reason this works for me.
if (process.env.RUN_SWAGGER_GEN === 'true') {
const { getResponseExpress } = require('@tiemma/sonic-express');
const swaggerDefinition = {
openapi: '3.0.1',
info: {
title: 'AtomicKit Server',
version: require('../../package.json').version,
description: 'Tax Software For Businesses'
},
servers: [
{
url: '/api/v1',
description: 'Host system path'
}
],
definitions: {},
produces: [
'application/json'
],
consumes: [
'application/json'
],
schemes: ['http', 'https'],
securityDefinitions: {
ApiKey: {
type: 'apiKey',
in: 'header',
name: 'api-key',
description: ''
},
Bearer: {
type: 'apiKey',
in: 'header',
name: 'authorization'
}
},
paths: {},
tags: ['account', 'auth', 'location'],
components: {
securitySchemes: {
jwtAuth: {
type: 'apiKey',
description: 'Use your token here',
in: 'header',
name: 'authorization'
}
}
},
security: [
{
bearerAuth: []
}
]
};
const options = (fileName) => ({
// import swaggerDefinitions
swaggerDefinition,
// path to the API docs
apis: [fileName]
});
application.use(getResponseExpress(application, options(__filename), swaggerSpecPath));
}
application.use('/api/v1/', routes);
application.use(
'/api/docs',
swaggerUI.serve,
swaggerUI.setup(swaggerSpec, {}, {})
);
oneEyedSunday commented
Closing this as for some reason this works for me.
if (process.env.RUN_SWAGGER_GEN === 'true') {
const { getResponseExpress } = require('@tiemma/sonic-express');
const swaggerDefinition = {
openapi: '3.0.1',
info: {
title: 'AtomicKit Server',
version: require('../../package.json').version,
description: 'Tax Software For Businesses'
},
servers: [
{
url: '/api/v1',
description: 'Host system path'
}
],
definitions: {},
produces: [
'application/json'
],
consumes: [
'application/json'
],
schemes: ['http', 'https'],
securityDefinitions: {
ApiKey: {
type: 'apiKey',
in: 'header',
name: 'api-key',
description: ''
},
Bearer: {
type: 'apiKey',
in: 'header',
name: 'authorization'
}
},
paths: {},
tags: ['account', 'auth', 'location'],
components: {
securitySchemes: {
jwtAuth: {
type: 'apiKey',
description: 'Use your token here',
in: 'header',
name: 'authorization'
}
}
},
security: [
{
bearerAuth: []
}
]
};
const options = (fileName) => ({
// import swaggerDefinitions
swaggerDefinition,
// path to the API docs
apis: [fileName]
});
application.use(getResponseExpress(application, options(__filename), swaggerSpecPath));
}
application.use('/api/v1/', routes);
application.use(
'/api/docs',
swaggerUI.serve,
swaggerUI.setup(swaggerSpec, {}, {})
);
oneEyedSunday commented
Closing this as for some reason this works for me.
if (process.env.RUN_SWAGGER_GEN === 'true') {
const { getResponseExpress } = require('@tiemma/sonic-express');
const swaggerDefinition = {
openapi: '3.0.1',
info: {
title: 'AtomicKit Server',
version: require('../../package.json').version,
description: 'Tax Software For Businesses'
},
servers: [
{
url: '/api/v1',
description: 'Host system path'
}
],
definitions: {},
produces: [
'application/json'
],
consumes: [
'application/json'
],
schemes: ['http', 'https'],
securityDefinitions: {
ApiKey: {
type: 'apiKey',
in: 'header',
name: 'api-key',
description: ''
},
Bearer: {
type: 'apiKey',
in: 'header',
name: 'authorization'
}
},
paths: {},
tags: ['account', 'auth', 'location'],
components: {
securitySchemes: {
jwtAuth: {
type: 'apiKey',
description: 'Use your token here',
in: 'header',
name: 'authorization'
}
}
},
security: [
{
bearerAuth: []
}
]
};
const options = (fileName) => ({
// import swaggerDefinitions
swaggerDefinition,
// path to the API docs
apis: [fileName]
});
application.use(getResponseExpress(application, options(__filename), swaggerSpecPath));
}
application.use('/api/v1/', routes);
application.use(
'/api/docs',
swaggerUI.serve,
swaggerUI.setup(swaggerSpec, {}, {})
);