express-openapi-validator and swagger-jsdoc?
Is it possible to combine swagger-jsdoc with express-openapi-validator?
The following code:
var schema = swaggerJsdoc( {
swaggerDefinition: {
openapi: '3.0.0',
info: {
title: 'Title',
description: 'API',
version: '1.0.0',
},
servers: [{url: '/'}]
},
apis: ['./src/**/*.js']
})
// OpenApi validation
app.use(OpenApiValidator.middleware({
apiSpec: schema,
validateRequests: true,
validateResponses: false
}))
Gives the error:
error: openapi.validator: args.apiDoc was invalid. See the output.
If swagger-jsdoc is compliant, then it should work if you JSON.stringify(schema) before passing it in.
Didn't work:
error: openapi.validator: spec could not be read at {"openapi":"3.0.0","info":{"title":"Project ","description":"API","version":"1.0.0"},"servers........
Seams like it is interpreting the string as a file path rather then then a schema.
As far as I can see my first example should work, you can pass an object as the apiSpec: https://github.com/cdimascio/express-openapi-validator#%EF%B8%8F-apispec-required
error: openapi.validator: args.apiDoc was invalid. See the output.
What does the output say?
Looks like it works now, turns out I had an error in my schema.
This indicates that the schema is invalid:
error: openapi.validator: args.apiDoc was invalid. See the output.
What I don't understand is, if validation is done on the schema, why it does not tell me what is wrong with the schema.
This would be great for debugging.