Skip to content

vocabulary enhancements #2803

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

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions schemas/v3.1/meta/base.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,8 @@

"type": ["object", "boolean"],
"properties": {
"example": true,
"discriminator": { "$ref": "#/$defs/discriminator" },
"externalDocs": { "$ref": "#/$defs/external-docs" },
"xml": { "$ref": "#/$defs/xml" }
},
"$defs": {
"extensible": {
"patternProperties": {
"^x-": true
}
"example": {
"deprecated": true
},
"discriminator": {
"$ref": "#/$defs/extensible",
Expand All @@ -30,14 +22,15 @@
"mapping": {
"type": "object",
"additionalProperties": {
"type": "string"
"type": "string",
"format": "uri-reference"
}
}
},
"required": ["propertyName"],
"unevaluatedProperties": false
},
"external-docs": {
"externalDocs": {
"$ref": "#/$defs/extensible",
"type": "object",
"properties": {
Expand Down Expand Up @@ -75,5 +68,21 @@
},
"unevaluatedProperties": false
}
},
"dependentSchemas": {
"discriminator": {
"anyOf": [
{ "required": [ "oneOf" ] },
{ "required": [ "anyOf" ] },
{ "required": [ "allOf" ] }
]
}
},
"$defs": {
"extensible": {
"patternProperties": {
"^x-": true
}
}
}
}
26 changes: 14 additions & 12 deletions schemas/v3.1/meta/base.schema.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
---
$defs:
extensible:
patternProperties:
^x-: true
properties:
discriminator:
$ref: '#/$defs/extensible'
properties:
mapping:
additionalProperties:
type: string
format: uri-reference
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not correct. These values can be either a uri-reference or a Schema Name.

An object to hold mappings between payload values and schema names or references.

Unfortunately, the concept of a "schema name" is not actually defined. See #2618 for a patch proposal that defines the concept the way I believe existing tooling interprets it.

Copy link
Member Author

Choose a reason for hiding this comment

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

I see. It would be good to clarify that wording, then (and perhaps take out the bits that don't add much value).

type: object
propertyName:
type: string
required:
- propertyName
type: object
unevaluatedProperties: false
extensible:
patternProperties:
^x-: true
external-docs:
example:
deprecated: true
externalDocs:
$ref: '#/$defs/extensible'
properties:
description:
Expand Down Expand Up @@ -44,19 +48,17 @@ $defs:
type: boolean
type: object
unevaluatedProperties: false
dependentSchemas:
discriminator:
anyOf:
- required: [ oneOf ]
- required: [ anyOf ]
- required: [ allOf ]
Comment on lines +51 to +56
Copy link
Contributor

Choose a reason for hiding this comment

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

The spec technically says not having oneOf/anyOf/allOf with a discriminator is a failure, but there is no good reason to fail in this case. It should be a linter warning, not a schema failure. Personally, I'd rather leave this out, but I'm ok with it since it is technically what the spec says. I propose changing this in #2621

Copy link
Member Author

Choose a reason for hiding this comment

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

it is indeed a very strange keyword, and doesn't really fit with the simplicity that most other keywords have.

I'll put this PR into draft mode while the other issue is being discussed.

$dynamicAnchor: meta
$id: https://spec.openapis.org/oas/3.1/meta/base
Copy link
Contributor

Choose a reason for hiding this comment

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

I noticed that this schema's keywords are all mixed up. I know that wasn't introduced in this schema, but it would be nice to fix that while we're making changes anyway.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure what you mean here.

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean the ordering is not the same as the JSON version. Things that are best practice to put at the top of the document ($id, $schema, $vocabularies) are at the bottom of the document. Unorganized schemas are harder to read.

$schema: https://json-schema.org/draft/2020-12/schema
$vocabulary:
https://spec.openapis.org/oas/3.1/vocab/base: true
properties:
discriminator:
$ref: '#/$defs/discriminator'
example: true
externalDocs:
$ref: '#/$defs/external-docs'
xml:
$ref: '#/$defs/xml'
Comment on lines -52 to -59
Copy link
Contributor

Choose a reason for hiding this comment

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

I see you've inlined the referenced schemas. The style I prefer is that any objects (excluding objects used like maps) are generally pulled out into definitions. It allows the reader to see what the whole schema does in the first few lines. Especially when inlining multiple large object schemas, it can we hard to determine the top level properties of an object. This way the reader can see the top level structure more easily and then dig down into the definitions to learn more about the specific properties they are interested in.

Copy link
Member Author

Choose a reason for hiding this comment

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

I inlined them here because they aren't referenced from anywhere else, and to mirror the style we use for the standard json-schema-spec schema files. This file is more like those schemas, rather than the main openapi schema (where splitting out into definitions, even if something is only referenced once, is helpful because the document is so nested). Vocabularies aren't like that -- there's just one level: the keywords themselves.

Copy link
Contributor

Choose a reason for hiding this comment

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

There is no precedent for compound keywords like these in the JSON Schema meta-schemas because there are no such keywords in JSON Schema. The only time we use objects is for map-like structures such as properties mapping a property name to a schema. If there were something similar in JSON Schema, I'd like to think we would use a definition for that as well.

title: OAS Base vocabulary
type:
- object
Expand Down