Comments (8)
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:
- OpenAPI 3.0.x should ignore siblings of
$ref
(1) - OpenAPI 3.0.x needs special hacks for
nullable
withenum
(1, 2, 3) - This breaks
nullable
set toTrue
alongsideallOf
/anyOf
/oneOf
. (This is your case @knivets.)
The comment # append defaults to trigger validator (i.e. nullable)
doesn't seem to make sense as validation seems to work perfectly fine without it. Perhaps @p1c2u can shed some light on why this is/was necessary?
This shouldn't be an issue with OpenAPI 3.1.x when it is supported as null
is allowed as a type.
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,
)
from openapi-schema-validator.
We are experiencing the same issue. As the previous comment stated: Perhaps @p1c2u can shed some light on why this is/was necessary?
from openapi-schema-validator.
That's exactly what comment says to trigger nullable validator.
The comment # append defaults to trigger validator (i.e. nullable) doesn't seem to make sense as validation seems to work perfectly fine without it.
It can work fine if you define nullable
param explicitly.
For schema without nullable
defined (default is False
) if you pass None
value it won't raise validation error - which is incorrect. You can try to remove these lines and run tests.
from openapi-schema-validator.
Maybe the issue I was bumping into was related to #24 (solved by #26), but I haven't been able to check.
from openapi-schema-validator.
Same here, can't reproduce the issue. @claeyswo which jsonschema version you use and do you have any example of the issue?
from openapi-schema-validator.
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,
}
},
},
}
},
}
from openapi-schema-validator.
attribute:
nullable: true
$ref: '#/components/Example'
attribute:
oneOf:
- type: "null"
- $ref: '#/components/Example'
Neither work, any update on a fix for this?
from openapi-schema-validator.
There were ambiguities in the semantics of nullable
in OAS 3.0.0-2 More about the issue can be found in the following proposal. OAS 3.0.3 clarified the definition so it can be implemented properly. There shouldn't be any major backward compatibility issues.
from openapi-schema-validator.
Related Issues (20)
- Validate byte properly
- Inner any of type mismatch not raising error
- Validating schema using yaml file HOT 2
- Nullable Strings are not recognized, incorrect check for None if type is string
- Cannot import _legacy_validators HOT 5
- OAS30Validator validates readonly/writeonly incorectly
- Validate doesnt seem to match schema correctly? HOT 3
- How to resolve local references with jsonschema/referencing HOT 12
- Support for scientific notation HOT 3
- test_array_prefixitems_invalid[value0] failing on 0.6.2 HOT 2
- Incompatible with jsonschema 4.10.0 HOT 3
- Subclassing JSONSchema validator class with OAS30Validator HOT 1
- Redundant runtime dependency on `attrs`
- 0.4.2 test failures: tests/integration/test_validators.py::TestOAS{30,31}Validator::test_format_checkers HOT 1
- OpenAPI 3.0 Validator allows byte as string type
- OpenAPI 3.0 list of types raises TypeError not SchemaError HOT 1
- Formats raise error for other types
- AttributeError: module 'jsonschema._utils' has no attribute 'load_schema' HOT 2
- ERROR in validation: ... validation error: '2023-03-23 13:35:45' is not a 'date-time' - 'timestamp' HOT 2
- `readOnly` / `writeOnly` support for OpenAPI 3.1 HOT 1
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 openapi-schema-validator.