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

Integrating with input validation #21

Open
mderazon opened this issue Sep 29, 2020 · 3 comments
Open

Integrating with input validation #21

mderazon opened this issue Sep 29, 2020 · 3 comments

Comments

@mderazon
Copy link

I know this is out of the scope of this library, but I am asking here to see if someone have already given a thought about this and solved it somehow within the openapi ecosystem.

A lot of boilerplate in any api service has to do with validating user's input. There are all kind of json schema validators and if you're using Typescript, you can use something like class-validator to decorate your classes and validate the user's input according to the requirements.

Ideally, we should write the openapi definitions one time in our code base with openapi-comment-parser syntax and then somehow use it to validate the requests according to the spec. I guess this will require "compiling" the comments into a openapi spec file and then using one of the validators to verify the user's input.

Has anyone tried anything like this before and can suggest an approach that worked for them ?

Thank you for this library

@bourdakos1
Copy link
Member

Have you tried something like express openapi validator?
https://www.npmjs.com/package/express-openapi-validator

@bourdakos1
Copy link
Member

bourdakos1 commented Sep 29, 2020

You should be able to do something like this:

const openapi = require('openapi-comment-parser');
const validator = require('express-openapi-validator');

const spec = openapi();

app.use(validator.middleware({ apiSpec: spec }));

@mderazon
Copy link
Author

Thanks, will try that and see how it works 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants