-
-
Notifications
You must be signed in to change notification settings - Fork 32
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
Bug when a schema has a nullable AllOf ref #20
Comments
I have also bumped into this issue. I believe that these lines are incorrect and should be removed: This is for a number of reasons, all of which have affected me:
The comment This shouldn't be an issue with OpenAPI 3.1.x when it is supported as I have used the following workaround which may help: from openapi_core.unmarshalling.schemas.enums import UnmarshalContext
from openapi_core.unmarshalling.schemas.factories import SchemaUnmarshallersFactory
from openapi_core.validation.response.validators import ResponseValidator
from openapi_schema_validator import OAS30Validator
class FixedOAS30Validator(OAS30Validator):
def iter_errors(self, instance, _schema=None):
# Use the implementation of .iter_errors() from the parent.
return super(OAS30Validator, self).iter_errors(instance, _schema)
class FixedSchemaUnmarshallersFactory(SchemaUnmarshallersFactory):
def get_validator(self, schema):
kwargs = {"resolver": self.resolver, "format_checker": self.format_checker}
if self.context is not None:
kwargs[self.CONTEXT_VALIDATION[self.context]] = True
with schema.open() as schema_dict:
return FixedOAS30Validator(schema_dict, **kwargs)
class FixedResponseValidator(ResponseValidator):
@property
def schema_unmarshallers_factory(self):
return FixedSchemaUnmarshallersFactory(
self.spec.accessor.dereferencer.resolver_manager.resolver,
self.format_checker,
self.custom_formatters,
context=UnmarshalContext.RESPONSE,
) |
We are experiencing the same issue. As the previous comment stated: Perhaps @p1c2u can shed some light on why this is/was necessary? |
That's exactly what comment says to trigger nullable validator.
It can work fine if you define |
Same here, can't reproduce the issue. @claeyswo which jsonschema version you use and do you have any example of the issue? |
3.0, but by adding nullable to every item the problem was solved. By switching the nullable om some_id in the example below we get the desired effect. schema = {
"$ref": "#/components/schemas/TestSchema",
"components": {
"schemas": {
"IntegerString": {
"anyOf": [
{"type": "integer", "nullable": True},
{"type": "string", "nullable": True},
],
"nullable": True,
},
"TestSchema": {
"type": "object",
"properties": {
"some_id": {
"$ref": "#/components/schemas/IntegerString",
"nullable": True,
}
},
},
}
},
} |
Neither work, any update on a fix for this? |
This is a known bug. Add a test for it so we can work on fixing it. Signed-off-by: Stephen Finucane <stephen@that.guru> Related-bug: python-openapi#20
There were ambiguities in the semantics of |
Fix #20 - nullable semantics with $ref, oneOf, anyOf, and allOf
Hey! I have a weird issue that happens with refs that are nullable. I have the following schema:
Essentially what I try to express is that
recent_message
can be eithernull
or an object of typeMessage
.When I run a validator it raises an exception:
After debugging the issue I have been able to find the root cause. I think the main reason why it happens is that openapi-schema-validator adds a
"nullable": false
to each ref. So the actual schema that ends being used is the following:How can I fix this issue?
Thanks!
The text was updated successfully, but these errors were encountered: