Closed zzzevaka closed 9 months ago
I think I'm experiencing the same thing with readOnly
, getting a failure on a simple {"default": "foo", "readOnly": True}
when trying to validate my generated OpenAPI data.
I'm having trouble following the code -- this library is the most sophisticated user of jsonschema
I have seen -- but I think the relevant bit must be where a default
is checked against the schema?
(https://github.com/python-openapi/openapi-spec-validator/blob/b0d96b6b9d94b99978a5db4beb9f586026151124/openapi_spec_validator/validation/validators.py#L336)
Is it reasonable to make it possible to opt-out of this check? I can imagine other cases in which someone wants to specify a default of "foo"
, but users are only allowed to provide enumerated values of ["bar", "baz"]
, so checking the default will always fail. (Is such a thing forbidden by OpenAPI? It's definitely not forbidden by JSON Schema.)
I believe the issue is in default value validation that we shouldn't consider other keywords, including writeonly/readonly.
Based on OpenAPI 3.0, schema type should be the only keyword to be considered here.
The default value represents what would be assumed by the consumer of the input as the value of the schema if one is not provided. Unlike JSON Schema, the value MUST conform to the defined type for the Schema Object defined at the same level. For example, if type is string, then default can be "foo" but cannot be 1.
The issue should be fixed with openapi-schema-validator 0.6.2
Good day! I use OpenAPI 3.0.0 schema and it stopped working with properties that have
writeOnly
anddefault
at the same time.A simple code snippet:
The error:
As I understood the root cause is here https://github.com/python-openapi/openapi-schema-validator/pull/85
As a workaround, I made a custom validator that uses
OAS30WriteValidator
:Shouldn't it be replaced in
openapi-spec-validator
?