-
-
Notifications
You must be signed in to change notification settings - Fork 68
Allow "required" list to have undefined properties #97
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
Comments
Hi Guys, did any one figure out a workaround for this problem changing the spec? |
Thanks @hibougeek ! We are blocked by this also. |
feat: handle allof when required linked to parent object (#97)
The problem with #312 is that it left the validation in an inconsistent state: if the schema contains This is what's causing #390 and what I tried to fix in #391. I'd rather try to validate that required are always defined in properties, even if the OpenAPI spec does not enforce it, because if you define a field in Example: type: object
required:
- foo In this case, To avoid ambiguity, it's best practice to define all type: object
required:
- foo
properties:
foo:
type: string |
I think requiring property names listed in
required
to be defined inproperties
is too strict. I also couldn't find this requirement in the JSON Schema or OpenAPI specs. JSON Schema validators and the Swagger Editor are fine with property names listed inrequired
that are not defined inproperties
.It makes sense to list required properties without defining them in
properties
when usingallOf
where one sub-schema requires some properties but does not specify them while another sub-schema only provides the specifications of the properties (possibly even without stating which ones are required and which ones aren't). This is especially useful when referencing and merging schema definitions or when expressing discriminated unions with some properties that are common to all union members.I suggest to remove the following code block
https://github.com/p1c2u/openapi-spec-validator/blob/3f53e957812a9c545d71226e3a4d696240e2cee6/openapi_spec_validator/validators.py#L134-L142
and the
require_properties
argument:https://github.com/p1c2u/openapi-spec-validator/blob/3f53e957812a9c545d71226e3a4d696240e2cee6/openapi_spec_validator/validators.py#L123
I have seen the test case
https://github.com/p1c2u/openapi-spec-validator/blob/3f53e957812a9c545d71226e3a4d696240e2cee6/tests/integration/test_validators.py#L83-L115
but it also seems to be valid to express this schema like this:
Or did I miss this rule somewhere in the spec?
The text was updated successfully, but these errors were encountered: