question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Design of OpenAPIRequestValidator

See original GitHub issue

Thank 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:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jsdevelcommented, Aug 3, 2018

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!

0reactions
jsdevelcommented, Oct 18, 2018

FYI, koa-openapi is now ready.

Read more comments on GitHub >

github_iconTop Results From Across the Web

openapi-request-validator - npm
Validate request properties against an OpenAPI spec. Highlights. Performant. Extensively tested. Small footprint. Does not validate parameter ...
Read more >
OpenAPI.Tools
openapi-core - Validate your requests and responses against an OpenAPI 3 specification and get very verbose and human-readable descriptions of errors. You will ......
Read more >
Automatic Request Validation with OpenAPI - Kusk-Gateway
Let's explore how you can use OpenAPI with Kusk Gateway to ensure that all the request bodies sent to your cluster a properly...
Read more >
Top 5 openapi-request-validator Code Examples - Snyk
To help you get started, we've selected a few openapi-request-validator examples, based on popular ways it is used in public projects.
Read more >
How to validate OpenAPI definitions - Swagger
How to validate OpenAPI definitions in Swagger Editor using GitHub Actions. ... We used a design-first approach of producing the API.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found