Does validation by `swagger-parser` actually work?
mhassan1 opened this issue · 0 comments
mhassan1 commented
Describe the bug
The README says:
The resulting openapiSpecification will be a swagger tools-compatible (and validated) specification.
I may be misunderstanding what this means, but it doesn't seem like it is true. I am able to provide an invalid spec and swagger-jsdoc
does not complain.
Looking at this code:
swagger-jsdoc/src/specification.js
Lines 100 to 104 in e1b8902
The parse
method from swagger-parser
is asynchronous, but this library is not handling it that way.
To Reproduce
- Create
routes.js
(note the invalidxxxdescriptionxxx
property):
/**
* @openapi
* /:
* get:
* xxxdescriptionxxx: Welcome to swagger-jsdoc!
* responses:
* 200:
* description: Returns a mysterious string.
*/
app.get('/', (req, res) => {
res.send('Hello World!');
});
- Create
generate.js
:
const swaggerJsdoc = require('swagger-jsdoc');
const options = {
definition: {
openapi: '3.0.0',
info: {
title: 'Hello World',
version: '1.0.0',
},
},
apis: ['./routes.js'], // files containing annotations as above
};
const openapiSpecification = swaggerJsdoc(options);
console.log(JSON.stringify(openapiSpecification, null, 2));
- Run
generate.js
and paste output in https://editor.swagger.io/ - See that the spec is invalid
Expected behavior
swaggerJsdoc
should error or warn when it encounters invalid spec