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

WIP: OpenAPI v3.1 Support #1399

Closed
wants to merge 5 commits into from
Closed

WIP: OpenAPI v3.1 Support #1399

wants to merge 5 commits into from

Conversation

philsturgeon
Copy link
Contributor

@philsturgeon philsturgeon commented Nov 7, 2020

Fixes #1302

OpenAPI v3.1 will be rather tricky for Spectral to implement for a few reasons:

  1. We use a meta-schema based validation approach and the OAS3.1 metaschema is not complete (First pass at 3.1 schema object meta-schema OAI/OpenAPI-Specification#2016)
  2. We rely on AJV v6 for this validation. The WIP OAS v3.1 meta-schema is based on JSON Schema 2019-09, which was added in AJV v7, but AKV v7 dropped support Draft 04 which is required for OAS v3.0...

I attempted shoving both AJV v6 and v7 in at the same time but there are quite a few major differences between the two (fair enough) and that meant it was a nightmare to pull off.

Instead, I have upgraded the OAS 3.0 metaschema from being based on draft 4 to being based on dradt 2019-09. This should work...

@philsturgeon

This comment has been minimized.

@Gdewilde
Copy link

@philsturgeon any updates on this? Thanks

@philsturgeon
Copy link
Contributor Author

philsturgeon commented Jan 22, 2021 via email

@Gdewilde
Copy link

Ait, good luck! Let us know if we can help

@Gdewilde
Copy link

@philsturgeon, congrats on the release of OAS 3.1.0! Any news on the task force?

@philsturgeon
Copy link
Contributor Author

@Gdewilde I'm very excited OAS3.1 final has been released. Folks here are working on things as quickly as they can despite being literally snowed out in Austin Texas. :)

Phil Sturgeon and others added 2 commits February 17, 2021 09:40
Basically JSON Schema Draft  support is dropped, and OpenAPI v3.0 support is proivded through converting the old schema.oas3.json to use Draft 2019-09 with json-schema-migrate. The TypeScript has changed a lot and now everything is very broken.
@@ -33,7 +33,6 @@
"node": ">=10.18"
},
"scripts": {
"postinstall": "patch-package",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this because it was focused on nullable which is gone now. We might need to bring it back to support OAS3.0 but im on a rampage trying to get 3.1 working first.

cache?: object;
logger?: CustomLogger | false;
nullable?: boolean;
+ xNullable?: boolean;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we wanted to make this patch work, i think the main difference is that nullable is always set to true now, which is funny because its been removed in OAS3.1, but... whatever that's the change according to https://github.com/ajv-validator/ajv/releases/tag/v7.0.0

@philsturgeon
Copy link
Contributor Author

@P0lip hey I'm spiking on something over here and running into a problem:

yarn run v1.22.5
$ yarn build.clean && copyfiles -u 1 "src/rulesets/{oas,asyncapi}/**/*.json" dist && copyfiles -u 1 "src/rulesets/{oas,asyncapi}/**/*.json" ./ && yarn copy.html-templates
$ rimraf ./coverage && rimraf ./dist && rimraf ./rulesets && rimraf ./__karma__/__fixtures__
$ copyfiles -u 1 "./src/cli/formatters/html/*.html" "./dist/"
$ tsc -p ./tsconfig.build.json
node_modules/ajv/lib/compile/codegen/code.ts:52:25 - error TS1109: Expression expected.

52     return (this._str ??= this._items.reduce((s: string, c: CodeItem) => `${s}${c}`, ""))
                           ~

node_modules/ajv/lib/compile/codegen/code.ts:52:89 - error TS1005: ';' expected.

52     return (this._str ??= this._items.reduce((s: string, c: CodeItem) => `${s}${c}`, ""))
                                                                                           ~

node_modules/ajv/lib/compile/codegen/code.ts:56:27 - error TS1109: Expression expected.

56     return (this._names ??= this._items.reduce((names: UsedNames, c) => {
                             ~

node_modules/ajv/lib/compile/codegen/code.ts:59:11 - error TS1005: ';' expected.

59     }, {}))
             ~


Found 4 errors.```

Think this is a problem with AJV itself? Or what is going on do you think, seems rather confusing. 

@P0lip
Copy link
Contributor

P0lip commented Feb 17, 2021

Did you try upgrading typescript?
I think conditional assignments were introduced in the 4.0.x version, while we're still on 3.9.x.

@philsturgeon
Copy link
Contributor Author

philsturgeon commented Feb 17, 2021

@P0lip progress! Any idea why we're downloading meta schemas?

$ ts-node --compiler-options {\"module\":\"CommonJS\"} ./scripts/generate-assets.ts
(node:45371) UnhandledPromiseRejectionWarning: ResolverError: Error downloading https://spec.openapis.org/oas/3.1/meta/extensions/2019-10
HTTP ERROR 404
    at /Users/phil/src/spectral/node_modules/@apidevtools/json-schema-ref-parser/lib/resolvers/http.js:127:16
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:45371) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 3)

Also we've got json-ref-resolver and json-schema-ref-parser in here?

@kikofernandez
Copy link

Hi there. I think that moving to OpenAPI v3.1 would be lovely.
Does anyone know what is the status of this PR or whether it will be happening?
Thanks a lot for an awesome job!

@philsturgeon
Copy link
Contributor Author

Yep this spike showed how far we could get without the dependencies improving, so now we're waiting for AJV v8.

A beta has just come out so we can once again make progress.

@kikofernandez
Copy link

Awesome work! Thanks a lot for update :)

@philsturgeon
Copy link
Contributor Author

Thankfully this PR has been superceded by #1589.

@P0lip P0lip closed this Jun 7, 2021
@P0lip P0lip deleted the oas-31 branch June 7, 2021 15:26
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

Successfully merging this pull request may close these issues.

OpenAPI v3.1.0 Support
4 participants