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

OpenAPI v3.1 Support #11

Open
philsturgeon opened this issue Feb 17, 2021 · 8 comments
Open

OpenAPI v3.1 Support #11

philsturgeon opened this issue Feb 17, 2021 · 8 comments

Comments

@philsturgeon
Copy link

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.

@amazing-gao
Copy link
Collaborator

Hi, I have not read the 3.x specifications totally, but I will read it late.
In order to adapt to the breaking changes, we can publish a new version eg: 2.0.
Do you have any idea?

@philsturgeon
Copy link
Author

That would be possible, and then people could use 1.x for OAS3.0 and 2.x for OAS3.1, but that makes life tricky for tooling that is trying to support both OAS3.0 and OAS3.1 at the same time.

I think there's going to be a fair bit of tooling around which only uses this dependency, so it might be a good place to try and buffer out this awkard difference.

One thing I've been playing with is converting the old OpenAPI schema.json used here up to draft 2019-09, so that I can use AJV v7 for both OAS3.0 and OAS3.1. This is a bit of a hack but does seem to work...

I know there's a lot to sift through in this PR, but I've basically done this already if you'd like to take a look.

https://github.com/stoplightio/spectral/pull/1399/files

Then its just a case of adding a few more format validators and working out which to use, and making them off by default as OAS3.1 does not recommend validating format by default anymore.

@philsturgeon
Copy link
Author

Oh btw the OAS 3.1 schema is being worked on over here, it's not quite right yet but will be soon. OAI/OpenAPI-Specification#2474

@amazing-gao
Copy link
Collaborator

This is a hack way indeed. I find another way to use different version ajvs. It is more elegant.

npm install <alias>@npm:<name>:

Install a package under a custom alias. Allows multiple versions of a same-name package side-by-side, more convenient 
import names for packages with otherwise long ones and using git forks replacements or forked npm packages as 
replacements. Aliasing works only on your project and does not rename packages in transitive dependencies. Aliases 
should follow the naming conventions stated in validate-npm-package-name.
npm install ajv6@npm:[email protected]
npm install ajv7@npm:ajv@7

So, we can use two versions ajv like this.

  "dependencies": {
    "ajv6": "npm:ajv@^6.10.2",
    "ajv7": "npm:ajv@^7.1.1",
    "decimal.js": "^10.2.0"
  },
const Ajv6 = require('ajv6')
const Ajv7 = require('ajv7').default

What do you think of this method?

@philsturgeon
Copy link
Author

philsturgeon commented Feb 22, 2021 via email

@amazing-gao
Copy link
Collaborator

It looks like good, I will try it.

amazing-gao added a commit that referenced this issue Feb 27, 2021
BREAKING CHANGE: remove `metaSchema` option, add `oasVer` option.

re #11
@amazing-gao
Copy link
Collaborator

@philsturgeon I make a PR #12.

There is something changed:

  1. Minimum node version change to 10
  2. Ajv upgrade to v7
  3. Option metaSchema removed
  4. Option coerceTypes default value change to false
  5. Add oasVer option to select OAS 3.0 or 3.1

You can take oas31.test.js#L5-L17 as reference. Can this satisfy you?

@philsturgeon
Copy link
Author

I might just be a bit confused from working on 324897 things at once but I thought you would need the meta schema that is still under development OAI/OpenAPI-Specification#2489.

How would this package know how to validate nullable or type: null, or any of the other big changes between the two versions?

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