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

vocabulary enhancements #2803

Closed

Conversation

karenetheridge
Copy link
Member

small improvements for the discriminator keyword, from the spec

@karenetheridge karenetheridge force-pushed the ether/vocabulary-enhancements branch from 2172dcb to b1770ad Compare November 26, 2021 02:18
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).

Comment on lines +51 to +56
dependentSchemas:
discriminator:
anyOf:
- required: [ oneOf ]
- required: [ anyOf ]
- required: [ allOf ]
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.

Comment on lines -52 to -59
properties:
discriminator:
$ref: '#/$defs/discriminator'
example: true
externalDocs:
$ref: '#/$defs/external-docs'
xml:
$ref: '#/$defs/xml'
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.

anyOf:
- required: [ oneOf ]
- required: [ anyOf ]
- required: [ allOf ]
$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.

@karenetheridge karenetheridge marked this pull request as draft December 2, 2021 04:14
@karenetheridge karenetheridge deleted the ether/vocabulary-enhancements branch October 29, 2022 17:54
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.

2 participants