oaijs / ajv-oai Goto Github PK
View Code? Open in Web Editor NEWOpenAPI's JsonSchema validator.
OpenAPI's JsonSchema validator.
const Ajvoai = require('ajv-oai')
const ajvoai = new Ajvoai({ coerceTypes: false });
console.log( ajvoai.compile({ type: 'string', nullable: true })(null));
should return true, but returns false
Hey there, I help maintain two tools which use this package: Spectral and Prism.
Both are looking to update OAS support to OpenAPI v3.1, and to do that changes to this package will be required.
I'll be happy to help out, I just wanted to start the conversation somewhere. First and foremost, how do we go about supporting both OAS 3.0 and 3.1 in the same package, because there's some breaking changes in there.
Hi,
I'm the author of fastify-openapi-glue which adds OpenAPI support to the Fastify webserver.
fastify-openapi-glue uses your ajv-oai to implement the additional types on AJV.
Currently I create a new AJV instance using ajv-oai and pass that to Fastify. (see https://github.com/seriousme/fastify-openapi-glue/blob/master/index.js#L50)
That works great (thanks for that !) but also means that I need to track changes in Fastify's config of AJV.
Fastify exposes a parameter 'ajv' (see https://www.fastify.io/docs/latest/Server/#ajv) to pass AJV plugins to the default AJV instance.
Now If I could pass ajv-oai as a plugin to AJV then I would not need to track changes in Fastify's AJV config anymore.
I checked other AJV plugins (e.g. https://github.com/luzlab/ajv-formats/blob/master/index.js) and the main difference is that AJV needs to be passed as a parameter.
Is it possible to add a plugin option to ajv-oai ?
I can write a PR.
Kind regards,
Hans
Hi,
Thanks a lot for your work ;)
I found an incoherence between your github repo and what is published into npm registry. Indeed, in npm registry, ajv 6.x is declared as peerDependency but not in your code :(
https://www.npmjs.com/package/ajv-oai?activeTab=explore
I would like prefer using your code without this peerDependency declaration :D
Regards,
I would expect that ajv-oai and ajv return the same result for the following types.
I would also expect that nullable:false means null is not accepted.
node_modules/ajv-oai/package.json: "version": "1.2.0"
node_modules/ajv/package.json: "version": "6.12.5"
const Ajv = require('ajv')
const ajv = new Ajv();
const Ajvoai = require('ajv-oai')
const ajvoai = new Ajvoai();
console.log(ajv.compile({ type: 'number' })("42"));
console.log(ajv.compile({ type: 'string' })(42));
console.log(ajv.compile({ type: 'string' })(null))
console.log(ajvoai.compile({ type: 'number' })("42"));
console.log(ajvoai.compile({ type: 'string' })(42));
console.log(ajvoai.compile({ type: 'string', })(null));
console.log(ajvoai.compile({ type: 'string', nullable: false })(null));
false
false
false
false
false
false
false
false
false
false
true
true
true
true
When you specify a property as required, but omit it from the JSON it will not fail the validation. It should always fail on a missing required property.
# Partial OpenAPI Schema
type: object
required:
- foo
properties:
foo:
type: string
bar:
type: string
{
"bar": "some value"
}
Validation using this OAS and JSON should fail but doesn't.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.