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

Allow user to pass config to AJV #659

Open
Lakitna opened this issue Apr 29, 2020 · 3 comments
Open

Allow user to pass config to AJV #659

Lakitna opened this issue Apr 29, 2020 · 3 comments

Comments

@Lakitna
Copy link

Lakitna commented Apr 29, 2020

I've been attempting to migrate from my own openapi validation package to this one. It took some time, but it looks like I've got most things working now.

A notable exception is that I would like human-readable error messages by using better-ajv-errors. https://www.npmjs.com/package/better-ajv-errors. This requires the following to be passed to AJV:

const ajv = new Ajv({ jsonPointers: true });

I think the cleanest way to do this is to allow the user to pass AJV config to the AJV instance inside openapi-request-validator, openapi-response-validator, and possibly openapi-schema-validator. I'm not too bothered about the schema validator myself.

This would also allow the user to make AJV more strict if that's what their use case calls for. For example setting unknownFormats: true instead of 'ignore', or setting format: 'full' instead of 'fast'.

Edit: This is how it looks when I set jsonPointers: true in my node_modules:
image

@Envek
Copy link
Contributor

Envek commented Feb 4, 2021

+1 on this. Also it would be useful to access underlying Ajv instance to setup other plugins like official ajv-errors which is required to refer field names in error messages which isn't achievable with Ajv itself (see ajv-validator/ajv#827 for details)

@ro0gr
Copy link

ro0gr commented Nov 30, 2021

the other use case I've just faced is a need to pass multipleOfPrecision option. Without it AJV just isn't able to handle the multipleOf properly(ajv-validator/ajv#84).

I doubt if hardcoding any specific multipleOfPrecision value inside the "openapi-response-validator" makes sense for everyone, so it seems reasonable to defer the decision to the user of the "openapi-response-validator".

@jsdevel
Copy link
Contributor

jsdevel commented Nov 30, 2021

feel free to submit a PR

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

4 participants