swaggerize-routes
swaggerize-routes copied to clipboard
$ref ignored in body parameter schemas
Example: ...
...
put:
parameters:
- name: body
required: true
in: body
schema:
$ref: '#/definitions/employeeFull'
validator.js does not call $ref resolution before enjoi at line 97. Suggested fix:
if ((parameter.in === 'body' || parameter.in === 'formData') && template.schema) {
iif (template.schema.$ref) {
template.schema = refresolver(schemas, template.schema.$ref);
} // resolve schema!
schema = enjoi(template.schema, {
subSchemas: schemas,
types: types
});
}
Maybe resolving all of the refs makes it easier. I do it externally currently, but I would have expected it to be done:
const http = require('http');
const express = require('express');
const swaggerize = require('swaggerize-express');
const refParser = require('json-schema-ref-parser');
const morgan = require('morgan');
app = express();
const server = http.createServer(app);
refParser.dereference('./api-docs/swagger.yaml')
.then(function(schema) {
app.use(morgan("dev"));
app.use(swaggerize({
api: schema,
docspath: '/api-docs',
handlers: './handlers'
}));
server.listen(10010, 'localhost', function () {
app.swagger.api.host = server.address().address + ':' + server.address().port;
});
})
.catch(function(err) {
console.error(err);
});
I think I'm running into exactly this on query parameters as well. It's partly because it's using it as a key in a dictionary:
if (def.parameters) {
def.parameters.forEach(function (parameter) {
validators[parameter.in + parameter.name] = parameter;
});
}
And with a ref, those things aren't there.