Comments (6)
oh.. i see what you mean, thanks
from python-fastjsonschema.
exclusiveMaximum
and exclusiveMinimum
can be booleans in Draft 04. Since Draft 06 it should be numeric. See the release notes: https://json-schema.org/draft-06/json-schema-release-notes.html
By default, Draft 07 is used. If you want to use Draft 04, specify that in your schema. Example:
{
"$schema": "http://json-schema.org/draft-04/schema",
"type": "object",
"properties": {
"period": {
"exclusiveMaximum": true,
"exclusiveMinimum": true,
"maximum": 1209600,
"minimum": 60,
"type": "integer"
}
}
}
from python-fastjsonschema.
This was with draft7
>>> fastjsonschema._get_code_generator_class(schema)
<class 'fastjsonschema.draft07.CodeGeneratorDraft07'>
from python-fastjsonschema.
Actually I see the schema validation failling because of exclusiveMaximum
for draft 0.7
Given the schema:
downloaded_schema = {'$id': '/properties/products/items/properties/downloaded_on',
'type': 'integer',
'title': 'The Downloaded_on Schema ',
'default': 0,
'minimum': 0,
'maximum': 2147483647,
'exclusiveMaximum': False,
'examples': [1521336798]}
Any valid number (timestamp) fails when doing this:
# valid timestamp
downloaded_on = 1567155851
validate = fastjsonschema.compile(downloaded_schema)
validate(downloaded_on)
The error being:
<ipython-input-113-d2b2a5d40dc9> in <module>
1 validate = fastjsonschema.compile(downloaded_schema)
----> 2 validate(downloaded_on)
<string> in validate__properties_products_items_properties_downloaded_on(data)
JsonSchemaException: data must be smaller than False
Removing the exclusiveMaximum
clause fixes the issue
from python-fastjsonschema.
Since draft 0.6 exclusiveMaximum
have to be number, not boolean. If you want to use it the old way, you need to state your schema is draft 0.4 as I showed before.
from python-fastjsonschema.
Oh, that makes a lot of sense!, thanks a ton!.
from python-fastjsonschema.
Related Issues (20)
- Please make a new release HOT 1
- Uniqueness enforced if uniqueItems explicitly set to False HOT 1
- 2.16.1: test_compile_to_code_custom_format fails HOT 3
- 2.16.2 not available on pypi.org HOT 1
- RFC 3339 date month and mday should be two digit HOT 2
- Getting UnboundLocalError HOT 3
- are the compiled validation functions cached? HOT 2
- Datadog's Guarddog detects exec in setup.py and complains HOT 4
- Python 3.10 venv build is failing HOT 1
- sdist is missing tests HOT 1
- Cannot parse int64 types HOT 1
- [Potential bug] not working validation for properties not defined in the schema object HOT 1
- Release request HOT 1
- Wrong tag name for 2.17.0 HOT 1
- 2.17.0 sdist contains "stray" tests/examples/lengths that breaks tests HOT 2
- errors for missing required properties
- Error occurs when fastjsonschema generates empty except block HOT 2
- Feature request: automatically add nested defaults HOT 7
- RFE: is it possible to start making github releases?🤔 HOT 1
- test_pattern_with_escape_no_warnings fails with python 3.12 HOT 2
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 python-fastjsonschema.