-
Notifications
You must be signed in to change notification settings - Fork 9.1k
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
The mutually-exclusive url and identifier properties of License object are optional in specification and required in schema #2975
Comments
If the schema is wrong, it's my fault. Reading the spec it doesn't appear that one of "url" or "identifier" is required, but I'd be surprised if that wasn't the intention. "name" is just a free-form label, right? The License Object wouldn't convey any real information without one of those included. |
@jdesrosiers The challenge with making url or identifier required is that it would be breaking from v3.0 where url was not required and identifier didn't exist. https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.0.md#license-object We should probably make url or identifier required in v4. |
Yeah, in that sense it's no different than 3.0. |
Understood. Unless @arno-di-loreto already has something prepared, I'll update the schema. |
Working on it. |
@jdesrosiers Here are some proposals before sending a PR. I found 5 different ways of telling "url and identifier are mutually exclusive (but not required)". I put them all in a repo (including the original schema) with samples and a test suite demonstrating the original bug and the fixes. I think option 5 could be the one: not too verbose and clear intent. What do you think? Option 1 - Global anyOf defining 2 objectsMy first working attempt. The name is duplicated, but it works 😅. I am just keeping it for the record. Full source here Option 2 - A not required identifier and urlThe original
Full source here Option 3 - A allOf if url then required identifier and reverseThe original
Full source here Option 4 - Using dependentSchemasThe original
Full source here Option 5 - Taking advantage of inner $defs to be more explicit about the intentI took option 2 and put the
Full source here |
I'm impressed that you found nearly every possible way to express this constraint. The only one I'd actively discourage is Option 1. It could be reworked to reduce the duplication, but in any case, the error messaging using this pattern is going to be confusing. There's only one option I can think of that you missed and that's the implication pattern. anyOf:
- not:
required:
- identifier
- not:
required:
- url Which can be written more simply using if:
required:
- identifier
then:
- not:
required:
- url And can be written even more concisely with dependentSchemas:
identifier:
not:
required:
- url I didn't include the inverse because it isn't necessary and produces unnecessary error results. If the license object has both "url" and "identifier" you'll get a message that says "url" isn't allowed with "identifier" and another message that says "identifier" isn't allowed with "url". One of those is sufficient. So, the choice comes down to I'm a big fan of using |
I'm not really sure what this all mean I'm look for someone to teach me and understand coding and how it works |
🤦🏻♂️😅 Obviously "if A not B" also means "if B not A". I really like the
|
Few questions to do a PR :
|
There's a brief explanation at the schema directory (version based), for example https://github.com/OAI/OpenAPI-Specification/tree/main/schemas/v3.1. You only need to modify the YAML version, no need to update the date and the PR should be against the main branch. |
…ly exclusive. Fixes OAI#2975
In the definition of the License object of OpenAPI 3.1: the
url
andidentifier
properties are not marked as REQUIRED, so optional, and are defined as mutually exclusive.The schema of the License object does not match with the specification making
url
oridentifier
required using the following construction at the root of of the object definition:If we compare both behaviors, that means the following (note that
name
is required):name
alonename
andurl
name
andidentifier
name
,url
andidentifier
name
alonename
andurl
name
andidentifier
name
alonename
,url
andidentifier
The following document which is valid according to the specification is considered invalid when using the schema with the validation script or directly using it with ajv:
Before proposing a pull request to fix that issue, I would like to confirm that my interpretation of the specification is correct and to know if there are any recommendations to follow regarding when modifying the schema. Besides sticking to the JSON Schema version already used, there are maybe some features to not use to ensure compatibility? (I already found 4 different ways to say "url and identifier are optional and mutually exclusive", I'll put them in the discussion if fixing the schema is the solution).
The text was updated successfully, but these errors were encountered: