-
Notifications
You must be signed in to change notification settings - Fork 129
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
lint: non-existing object properties listed as required are ignored #477
Comments
I don't think this is a bug. This seems like a feature request? By default the objects allow additional properties. So by example it is technically correct (unless the additionalProperties was set to false -- in which case, it would be a bug). |
This is indeed not a bug. This is technically a valid openapi definition. It states that the But I think we need an additional lint rule to enforce all properties defined in Not sure how to name this rule... Any other ideas? |
|
The OpenAPI Specification (both 2x and 3x) states the Schema Object is based on the JSON Schema Core and JSON Schema Validation. The JSON Schema Validation states the following at 5.4.3. required:
My understanding is the |
Hi David, yes, we believe you have a misunderstanding. Your request is a good feature request, but it is not bug. Let's look at this example: type: object
required:
- adam
properties:
david:
type: string
additionalProperties: true The The This example object is invalid: {} This example object is invalid: { "david": "sample"} This example object is valid: { "adam": "sample"} This example object is valid: {
"adam": "sample",
"david": "sample"
} This example object is valid: {
"adam": "sample",
"david": "sample",
"elvira": "sample"
} You may be wondering... the valid example objects have properties that are not defined. That is what "additionalProperties" means. http://json-schema.org/understanding-json-schema/reference/object.html#additional-properties |
Hi @adamaltman, thank you for the explanation, I was not aware of the |
@davidkuridza finally in progress on this one. 👍 |
Sorry @davidkuridza, we had to put this on hold for some time. I hope we will eventually get back to it. |
@tatomyr no problem, good things come to those who wait :) |
We usually set the additionalProperties to false, because we don't want the objects open for extension. In this case any property named in the "required" array must exist as an entry in the properties dictionary. Otherwise an error should be thrown.
Should throw an error, that the property adam cannot be a required property, since it is not defined. And even if I set additionalProperties to true, I might want to check if there are undefined properties in my required array. I would suggest the name |
Finally we've managed to have this done in v1.9 😅. |
Thank you for the update. We checked the new rule and it throws the expected errors. At some points we use allOf to extend an object without required properties by an object with required properties. I'm not sure, if this is a common practice. We use it, when a schema has properties that are required in some contexts and optional in other contexts. See the following example: Schema 1: (only props, not required)
Schema 2: (no props, just required array that includes Property names of Schema 1)
allOf: {
The problem is, that every Schema 2 will throw an error now, because there are no props included. Is there a better way to specify that scenario? |
Thanks for the feedback @tib-c!
Certainly! Will do that.
The linter visits every schema separately, and it'd be challenging to know the context a schema is used in (and even if so, the schema could be used in different contexts, in some correctly, in some not). I can see several solutions to this, however. rules:
no-required-schema-properties-undefined:
severity: warn
allowAdditionalProperties: true And the last option I can think of is to take into account If you think any of the latter two should be implemented, feel free to open a new issue. NB: The issue is somewhat similar to this one: #1437. |
@tatomyr it works, thank you very much! |
Describe the bug
The
openapi-cli
ignores non-existing object properties which are listed as required. Anything can be listed under therequired:
tag and thelint
will not return any errors.To Reproduce
Steps to reproduce the behavior:
openapi lint petstore.yaml --format stylish
Expected behavior
There should be an error saying the required property is not defined, for example:
openapi-cli
Version(s)Node.js
Version(s)Additional context
.redocly.yaml
present, the default out-of-the-boxopenapi-cli
is used.The text was updated successfully, but these errors were encountered: