Repository navigation
Conversation
Member
|
Swagger 2.0 also uses the boolean form, so with the default (non-openapi) mode, { type: 'integer', exclusiveMinimum: 0 } produces an invalid document on this branch |
Contributor
Author
|
Good catch, thanks. Swagger 2.0 uses the same boolean form, so I added the conversion there too (361026b):
The new Swagger test (query param, array One thing I left as is: in Swagger mode, schemas registered with |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Route schemas are validated by Ajv as JSON Schema draft 7, where
exclusiveMinimum/exclusiveMaximumare numbers. OpenAPI 3.0 (the default document version) uses the draft 4 form, where they are booleans that makeminimum/maximumexclusive. They are currently copied through unchanged, so a schema such asproduces an invalid OpenAPI 3.0 document:
For OpenAPI 3.0,
convertJsonSchemaToOpenapi3now rewrites a numeric bound next to the existingtype: 'null'→nullableconversion:exclusiveMinimum: nbecomesminimum: n, exclusiveMinimum: true. When the schema also hasminimum/maximum, the stricter bound is kept, so{ minimum: 5, exclusiveMinimum: 0 }stays{ minimum: 5 }. OpenAPI 3.1+ documents are left as they are, since 3.1 uses the numeric form.Swagger 2.0 (the non-
openapimode) has the same boolean form, so the conversion also runs there: inreplaceUnsupportedfor body and response schemas, and on query/header/path parameters (includingitems). The helper lives inlib/util/convert-exclusive-bounds.js.Checklist
npm run test(there is nobenchmarkscript in this repo)and the Code of conduct
Tests: two new tests in
test/spec/openapi/schema.test.js, covering the 3.0 conversion (including the cases whereminimum/maximumis stricter) and checking that 3.1 is unchanged. Both validate the document with@apidevtools/swagger-parser. The 3.0 test fails onmain.npm run test(unit tests with 100% coverage, and tstyche) and ESLint pass.