Comments (8)
no-illogical-schemas
could be a potential name for the rule.
We could also check allOf
for illogical behavior:
https://json-schema.org/understanding-json-schema/reference/combining#illogicalschemas
from redocly-cli.
Thanks for reporting! This looks more like an enhancement though.
from redocly-cli.
@adamaltman a question based on the next example from the link you provided:
{
"oneOf": [
{ "type": "number", "multipleOf": 5 },
{ "type": "number", "multipleOf": 3 }
]
}
Wouldn't it be also considered an illogical use of oneOf
? The number 15
will be technically valid against both of the subschemas. Is there a way to distinguish an intentional use of oneOf
to exclude certain numbers from an example of illogical use?
from redocly-cli.
It is indeed illogical too.
If possible values intersect, they are illogical in the context of oneOf
.
I don't know what you mean by the intentional use of oneOf
to exclude certain numbers? oneOf
would not be the appropriate tool to exclude certain numbers. Instead, more detailed schema criteria should be used.
I suspect there is a good amount of the nullable case in the real world (at least for people who adopted 3.1 with nullable). I'm not sure if there are many of this multiple of 3 and 5 type cases in the real world. And I suspect if there is, it would mostly be something like greater or equal to 0 and also something else that includes 0 where 0 is the culprit and could match two schemas.
from redocly-cli.
I don't know what you mean by the intentional use of oneOf to exclude certain numbers?
The same example - all multiples of 3 and 5 will be valid against that oneOf
except for multiples of 3 AND 5 at the same time. (e.g. 3, 5 - valid, 15 - invalid). So technically a similar trick could be used intentionally.
I'm not sure if there are many of this multiple of 3 and 5 type cases in the real world
Most likely not too much. And the vast majority should be using anyOf
instead. But how about the following:
oneOf:
- type: object
properties:
foo: { type: string }
- type: object
properties:
bar: { type: number }
Technically any object is invalid against this schema since additionalProperties
are true
by default and any field will be valid against both schemas. However, I suppose it's pretty common to write schemas like that. Do we want to error on such cases as well?
from redocly-cli.
@tatomyr I think the schema is written incorrectly for "I want 15 to be invalid" and the user would need to compose of more complex objects with not
multiple of 15. So, I do believe it is still illogical. I'm not sure we need to check for all aspects of illogicality.
Your example with additionalProperties
is a common illogical situation. I believe that I would want to know it is illogical, but there are likely people who would like to assume additionalProperties
was false
even though it isn't false.
I think the rule should take into consideration required properties. Sometimes a missing required property can make the case logical even without additionalProperties
set to false
.
from redocly-cli.
Makes sense. Thanks for the explanation!
from redocly-cli.
This is a big black hole of linting rules. It would be amazing!! Certainly, there are a million configurable rules you can create for these types of checks, similar to #1318
There has never really existed a good JSON Schema linter, which is something the JSON Schema core group has discussed many times, but without the budget to produce something. I would definitely consider discussing at least some of the bigger schema authoring mistakes they encounter to try and build some rules around them.
from redocly-cli.
Related Issues (20)
- Can't resolve remote $ref with query parameter HOT 3
- OAS 3.1 - arbitrary schema keywords are classified as lint errors HOT 3
- Missing const typing support HOT 2
- bug: inconsistent types for OAS3_1 schemas HOT 1
- Add some type of plugin to allow dynamic definition of extensions or config files HOT 2
- Support better means to set environment variables HOT 4
- dependentRequired is valid json schema but does not pass linting and prevents component from being available in UI. HOT 3
- Api HOT 2
- Add the `--ext` parameter to the `split` command HOT 1
- Running out of CPU inside of containers HOT 3
- join fails on commonly referenced components HOT 4
- Redocly removing string for enums if there's non-numbers mixed in HOT 3
- Ability to exclude some operations from security-defined rule HOT 4
- `remove-unused-components` removes used `securityDefinitions` from `Swagger 2.0` specifications HOT 1
- "join" remove extension properties under path property HOT 3
- Add option `--prefix-components-with-filepath` to `join` HOT 2
- Add `output` as a per-API configuration option
- Document behaviour of lint cli args after `--` HOT 3
- Configure object order for redocly bundle command
- Unexpected theme/htmlTemplate config warnings in v1.15.0 HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from redocly-cli.