Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does validation by swagger-parser actually work? #284

Open
mhassan1 opened this issue Sep 27, 2021 · 0 comments
Open

Does validation by swagger-parser actually work? #284

mhassan1 opened this issue Sep 27, 2021 · 0 comments
Labels
pinned Issues that will not be automatically closed

Comments

@mhassan1
Copy link

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:

parser.parse(swaggerObject, (err, api) => {
if (!err) {
specification = api;
}
});

The parse method from swagger-parser is asynchronous, but this library is not handling it that way.

To Reproduce

  1. Create routes.js (note the invalid xxxdescriptionxxx property):
/**
 * @openapi
 * /:
 *   get:
 *     xxxdescriptionxxx: Welcome to swagger-jsdoc!
 *     responses:
 *       200:
 *         description: Returns a mysterious string.
 */
app.get('/', (req, res) => {
  res.send('Hello World!');
});
  1. 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));
  1. Run generate.js and paste output in https://editor.swagger.io/
  2. See that the spec is invalid

Expected behavior
swaggerJsdoc should error or warn when it encounters invalid spec

@daniloab daniloab added the pinned Issues that will not be automatically closed label Sep 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pinned Issues that will not be automatically closed
Projects
None yet
Development

No branches or pull requests

2 participants