Design of OpenAPIRequestValidator
See original GitHub issueThank you all for tackling this problem!
Our team is attempting to use the openapi-request-validator
package to write a custom Koa middleware. We know you guys have a Koa middleware planned, but we figured we’d write a simplified version. We’d be happy to contribute to a larger middleware, and we’re okay with maintaining our own if our visions are incompatible.
We’re currently finding the interface to OpenAPIRequestValidtor
a little hard to understand. To us, ideally the process would look something like this:
new OpenapiRequestValidator(openapiSchema).validate(request)
Where openapiSchema
is our full Open API JSON object and request
is a standardized request format. This would make writing a middleware trivial. Here’s a simplified example:
export default async function validationMiddleware(context, next) {
let openAPIDocument = parseOpenAPI(OPEN_API_PATH);
let request = convertKoaRequestToOpenAPIRequest(context.request);
let requestValidationResult = new OpenAPIRequestValidator(openAPIDocument).validate(request);
if (requestValidationResult) {
throw new ValidationError(requestValidationResult.errors[0].message);
}
await next();
}
We’re struggling to understand the current OpenAPIRequestValidator
API. It seems like we need to transform the Open API schema into some other format, but we’re not sure what that format is or what it should look like. We looked at the implementation of the Express middleware for inspiration, but it’s very daunting.
We’d really appreciate some guidance on the best path forward. Ideally, the interface to the validator would match what we expect, but we’re happy to take a different path if that is what is best moving forward. We might also be missing something in our understanding, and we would appreciate clarification if that’s the case.
Thanks!
CC @griesmnr and @jorge0136
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
I’m glad you guys were able to find a workaround! I’m in the process of getting
koa-openapi
going, so when that’s ready I may draw your attention to that for review. Going to close this now. Thanks for your support!FYI,
koa-openapi
is now ready.