Giter VIP home page Giter VIP logo

Comments (6)

kapilt avatar kapilt commented on July 1, 2024 1

oh.. i see what you mean, thanks

from python-fastjsonschema.

horejsek avatar horejsek commented on July 1, 2024

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.

kapilt avatar kapilt commented on July 1, 2024

This was with draft7

>>> fastjsonschema._get_code_generator_class(schema)
<class 'fastjsonschema.draft07.CodeGeneratorDraft07'>

from python-fastjsonschema.

manugarri avatar manugarri commented on July 1, 2024

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.

horejsek avatar horejsek commented on July 1, 2024

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.

manugarri avatar manugarri commented on July 1, 2024

Oh, that makes a lot of sense!, thanks a ton!.

from python-fastjsonschema.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.