-
Notifications
You must be signed in to change notification settings - Fork 9.1k
[WIP] Alternative OAS3 JSON Schema #1270
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
Changes from 1 commit
45971df
bda4218
1eb22f0
bd277c6
069367f
629cd7c
49e784d
1087db4
13a4fd2
5529143
82ef49c
f71d7f8
e619259
e9de80f
99226cf
6fbc926
0684d65
f39cbf0
88dd430
26cf125
bedcc17
9592b1f
81e3dd5
cdd7816
2208e08
3f09f46
66659e4
bbd49b6
c094c22
92e15eb
6d17b63
3dcfee1
35ab014
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,8 +6,7 @@ required: | |
properties: | ||
openapi: | ||
type: string | ||
enum: | ||
- 3.0.0 | ||
pattern: ^3\.0\.\d(-.+)?$ | ||
info: | ||
$ref: '#/definitions/Info' | ||
externalDocs: | ||
|
@@ -34,10 +33,12 @@ additionalProperties: false | |
definitions: | ||
Reference: | ||
type: object | ||
required: | ||
- $ref | ||
properties: | ||
$ref: | ||
type: string | ||
format: uri-ref | ||
format: uriref | ||
Info: | ||
type: object | ||
required: | ||
|
@@ -50,7 +51,7 @@ definitions: | |
type: string | ||
termsOfService: | ||
type: string | ||
format: uri-ref | ||
format: uriref | ||
contact: | ||
$ref: '#/definitions/Contact' | ||
license: | ||
|
@@ -69,7 +70,7 @@ definitions: | |
type: string | ||
url: | ||
type: string | ||
format: uri-ref | ||
format: uriref | ||
email: | ||
type: string | ||
format: email | ||
|
@@ -86,7 +87,7 @@ definitions: | |
type: string | ||
url: | ||
type: string | ||
format: uri-ref | ||
format: uriref | ||
patternProperties: | ||
'^x-': {} | ||
additionalProperties: false | ||
|
@@ -98,7 +99,7 @@ definitions: | |
properties: | ||
url: | ||
type: string | ||
format: uri-ref | ||
format: uriref | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should be a /^(?:(?:[^\x00-\x20"'<>%\\^`{|}]|%[0-9a-f]{2})|\{[+#.\/;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?:\:[1-9][0-9]{0,3}|\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?:\:[1-9][0-9]{0,3}|\*)?)*\})*$/i There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd rather not get into that. I'm not sure what the difference is between I find adding complex regex impossible to read and maintain. We could have added a regex to define media types as well and we didn't (we had a similar discussion about it around 2.0's schema). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Understood. I'm seeing that it's too restrictive being a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense, will remove. |
||
description: | ||
type: string | ||
variables: | ||
|
@@ -254,31 +255,57 @@ definitions: | |
type: | ||
type: string | ||
enum: | ||
- array | ||
- boolean | ||
- integer | ||
- number | ||
- object | ||
- string | ||
- array | ||
- boolean | ||
- integer | ||
- number | ||
- object | ||
- string | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be possible to get There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I see now that 3.0.0 indicates that it doesn't support the Do you have any feeling as to whether this is set in stone yet? Unless I'm really misunderstanding something, the trouble with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And alright, I just read through #229. It doesn't look like the core team can be persuaded on this point, but oof, one of my perceived advantages of the 3.0 upgrade was not having to deal with the arbitrary restrictions that 2.0 imposed on JSON schemas. It seems that there are now fewer of them for 3.0, but they're still there, and JSON schema generated to be OpenAPI-compatible still cannot be used to accurately describe all types of API resources without additional meta-annotations (which are obviously not portable). I'm not sure where that leaves us. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. V3 leaves us in the position where the Schema object can processed with JSON schema tooling without generating errors (due mainly to type: file). It is true that not everything in JSON schema is supported. Hopefully we can get there in the future. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
not: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we also missing definitions for the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, added. |
||
$ref: '#/definitions/Schema' | ||
oneOf: | ||
- $ref: '#/definitions/Schema' | ||
- $ref: '#/definitions/Reference' | ||
allOf: | ||
type: array | ||
items: | ||
oneOf: | ||
- $ref: '#/definitions/Schema' | ||
- $ref: '#/definitions/Reference' | ||
oneOf: | ||
type: array | ||
items: | ||
oneOf: | ||
- $ref: '#/definitions/Schema' | ||
- $ref: '#/definitions/Reference' | ||
anyOf: | ||
type: array | ||
items: | ||
oneOf: | ||
- $ref: '#/definitions/Schema' | ||
- $ref: '#/definitions/Reference' | ||
items: | ||
type: array | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wondering why array's item type is
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's me being too tired. Good catch, will fix shortly. |
||
items: | ||
oneOf: | ||
- $ref: '#/definitions/Schema' | ||
- $ref: '#/definitions/Reference' | ||
properties: | ||
type: object | ||
additionalProperties: | ||
$ref: '#/definitions/Schema' | ||
oneOf: | ||
- $ref: '#/definitions/Schema' | ||
- $ref: '#/definitions/Reference' | ||
additionalProperties: | ||
oneOf: | ||
- $ref: '#/definitions/Schema' | ||
- $ref: '#/definitions/Reference' | ||
- type: boolean | ||
default: true | ||
description: | ||
type: string | ||
format: | ||
type: string | ||
default: {} | ||
$ref: | ||
type: string | ||
format: uri-ref | ||
nullable: | ||
type: boolean | ||
default: false | ||
|
@@ -327,7 +354,7 @@ definitions: | |
attribute: | ||
type: boolean | ||
default: false | ||
wrapperd: | ||
wrapped: | ||
type: boolean | ||
default: false | ||
patternProperties: | ||
|
@@ -383,6 +410,8 @@ definitions: | |
|
||
MediaTypeWithExamples: | ||
type: object | ||
required: | ||
- examples | ||
properties: | ||
schema: | ||
oneOf: | ||
|
@@ -409,17 +438,28 @@ definitions: | |
type: string | ||
description: | ||
type: string | ||
value: | ||
type: string | ||
value: {} | ||
externalValue: | ||
type: string | ||
format: uri-ref | ||
format: uriref | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that the modern name of a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OpenAPI 3.0.0 uses JSON schema Draft Wright 00 (aka Draft 5) so uriref is correct, uri-reference is defined in Draft Wright 01 (aka JSON Schema Draft 6). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks Mike. I'd seen the change in the changelog, but assumed maybe some tooling was outdated. Do you know what the rational for tying the spec and an older JSON schema version is? I guess because draft 6 introduces quite a few changes? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @brandur ...because tying the spec to "whatever is the current version" would be impossible for tooling to deal with. We had to lock on one version. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @MikeRalphson it would be better to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @handrews for better or worse, we're stuck with Draft 5 until at least OpenAPI 3.1.0 (or possibly 4.0 if it's deemed a breaking change). I think it would cause more confusion to use formats from Draft 6, and possibly result in those URI Reference properties not being validated at all. At least There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @MikeRalphson I was under the impression that a lot of people use extended formats with OpenAPI? Most validators that support formats, including Ajv allow registering additional ones. If this is the only extended (from the draft-05 perspective) format being used, then yes, I agree it makes sense not to use it. But if it's not, I'd encourage folks to ignore |
||
patternProperties: | ||
'^x-': {} | ||
additionalProperties: false | ||
|
||
Header: | ||
oneOf: | ||
- $ref: '#/definitions/HeaderWithSchema' | ||
- $ref: '#/definitions/HeaderWithContent' | ||
|
||
HeaderWithSchema: | ||
oneOf: | ||
- $ref: '#/definitions/HeaderWithSchemaWithExample' | ||
- $ref: '#/definitions/HeaderWithSchemaWithExamples' | ||
|
||
HeaderWithSchemaWithExample: | ||
type: object | ||
required: | ||
- schema | ||
properties: | ||
description: | ||
type: string | ||
|
@@ -439,24 +479,81 @@ definitions: | |
default: simple | ||
explode: | ||
type: boolean | ||
allowReserved: | ||
type: boolean | ||
default: false | ||
schema: | ||
oneOf: | ||
- $ref: '#/definitions/Schema' | ||
- $ref: '#/definitions/Reference' | ||
example: {} | ||
patternProperties: | ||
'^x-': {} | ||
additionalProperties: false | ||
|
||
HeaderWithSchemaWithExamples: | ||
type: object | ||
required: | ||
- schema | ||
- examples | ||
properties: | ||
description: | ||
type: string | ||
required: | ||
type: boolean | ||
default: false | ||
deprecated: | ||
type: boolean | ||
default: false | ||
allowEmptyValue: | ||
type: boolean | ||
default: false | ||
style: | ||
type: string | ||
enum: | ||
- false | ||
- simple | ||
default: simple | ||
explode: | ||
type: boolean | ||
allowReserved: | ||
type: boolean | ||
default: false | ||
schema: | ||
oneOf: | ||
- $ref: '#/definitions/Schema' | ||
- $ref: '#/definitions/Reference' | ||
examples: | ||
type: array | ||
items: | ||
type: object | ||
additionalProperties: | ||
oneOf: | ||
- $ref: '#/definitions/Example' | ||
- $ref: '#/definitions/Reference' | ||
example: {} | ||
patternProperties: | ||
'^x-': {} | ||
additionalProperties: false | ||
|
||
HeaderWithContent: | ||
type: object | ||
required: | ||
- content | ||
properties: | ||
description: | ||
type: string | ||
required: | ||
type: boolean | ||
default: false | ||
deprecated: | ||
type: boolean | ||
default: false | ||
allowEmptyValue: | ||
type: boolean | ||
default: false | ||
content: | ||
type: object | ||
additionalProperties: | ||
$ref: '#/definitions/MediaType' | ||
minProperties: 1 | ||
maxProperties: 1 | ||
patternProperties: | ||
'^x-': {} | ||
additionalProperties: false | ||
|
@@ -557,8 +654,6 @@ definitions: | |
additionalProperties: false | ||
|
||
Responses: | ||
allOf: | ||
- $ref: '#/definitions/Extensions' | ||
type: object | ||
properties: | ||
default: | ||
|
@@ -577,6 +672,7 @@ definitions: | |
type: object | ||
patternProperties: | ||
'^x-': {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this requires an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @webron @MikeRalphson why is this Responses:
type: object
patternProperties:
'^x-': {}
additionalProperties: false
not:
type: object
patternProperties:
'^x-': {}
additionalProperties: false which is an impossible schema. Am I misreading something here? |
||
additionalProperties: false | ||
|
||
|
||
SecurityRequirement: | ||
|
@@ -610,7 +706,7 @@ definitions: | |
type: string | ||
url: | ||
type: string | ||
format: uri-ref | ||
format: uriref | ||
patternProperties: | ||
'^x-': {} | ||
additionalProperties: false | ||
|
@@ -825,6 +921,7 @@ definitions: | |
- in | ||
- schema | ||
- required | ||
- examples | ||
properties: | ||
name: | ||
type: string | ||
|
@@ -876,6 +973,7 @@ definitions: | |
- name | ||
- in | ||
- schema | ||
- examples | ||
properties: | ||
name: | ||
type: string | ||
|
@@ -927,6 +1025,7 @@ definitions: | |
- name | ||
- in | ||
- schema | ||
- examples | ||
properties: | ||
name: | ||
type: string | ||
|
@@ -975,6 +1074,7 @@ definitions: | |
- name | ||
- in | ||
- schema | ||
- examples | ||
properties: | ||
name: | ||
type: string | ||
|
@@ -1187,8 +1287,8 @@ definitions: | |
type: string | ||
type: | ||
type: string | ||
enum: | ||
- http | ||
enum: | ||
- http | ||
description: | ||
type: string | ||
patternProperties: | ||
|
@@ -1255,10 +1355,10 @@ definitions: | |
properties: | ||
authorizationUrl: | ||
type: string | ||
format: uri-ref | ||
format: uriref | ||
refreshUrl: | ||
type: string | ||
format: uri-ref | ||
format: uriref | ||
scopes: | ||
type: object | ||
additionalProperties: | ||
|
@@ -1274,10 +1374,10 @@ definitions: | |
properties: | ||
tokenUrl: | ||
type: string | ||
format: uri-ref | ||
format: uriref | ||
refreshUrl: | ||
type: string | ||
format: uri-ref | ||
format: uriref | ||
scopes: | ||
type: object | ||
additionalProperties: | ||
|
@@ -1293,10 +1393,10 @@ definitions: | |
properties: | ||
tokenUrl: | ||
type: string | ||
format: uri-ref | ||
format: uriref | ||
refreshUrl: | ||
type: string | ||
format: uri-ref | ||
format: uriref | ||
scopes: | ||
type: object | ||
additionalProperties: | ||
|
@@ -1313,13 +1413,13 @@ definitions: | |
properties: | ||
authorizationUrl: | ||
type: string | ||
format: uri-ref | ||
format: uriref | ||
tokenUrl: | ||
type: string | ||
format: uri-ref | ||
format: uriref | ||
refreshUrl: | ||
type: string | ||
format: uri-ref | ||
format: uriref | ||
scopes: | ||
type: object | ||
additionalProperties: | ||
|
@@ -1338,7 +1438,7 @@ definitions: | |
properties: | ||
operationRef: | ||
type: string | ||
format: uri-ref | ||
format: uriref | ||
parameters: | ||
type: object | ||
additionalProperties: {} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should
$ref
be arequired
property? Otherwise I get false matches of both halves of aoneOf
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, will fix.