Skip to content

Numbers converted into scientific notation are not considered valid numbers #308

Description

@gaurav

The property pvalue_threshold in https://nodenormalization-sri.renci.org/openapi.json fails validation because the default value (0.000001) is converted into scientific notation in Python (1e-06), which is judged to not be a valid number (Could not validate OpenAPI at https://nodenormalization-sri.renci.org/openapi.json: '1e-06' is not of type 'number'). Is there any way to work around this?

May be related to #115

Activity

  1. choward18 commented on Nov 27, 2023

    @choward18

    I am seeing the same exact issue, it works with 1.0e+23 but not 1e+23 using version 0.2.9

  2. kurtmckee commented on Jun 26, 2025

    @kurtmckee
    Contributor

    The core issue is a 6-year-old bug in PyYAML, and the fact that openapi-spec-validator is deferring its I/O to jsonschema-path, which relies on PyYAML.

    The error reported above is this (from the CLI):

    $ openapi-spec-validator example.json 
    example.json: Validation Error: '1e-06' is not of type 'number'
    
    Failed validating 'type' in schema:
        {'type': 'number',
         'maximum': 1.0,
         'minimum': 0.0,
         'title': 'Pvalue Threshold',
         'default': '1e-06'}
    
    On instance:
        '1e-06'
    

    There are several possible ways that this could be addressed in the tool chain:

    • The bug gets fixed and released in PyYAML
    • jsonschema-path switches to another YAML parsing library, like ruamel.yaml
    • jsonschema-path speculatively tries parsing using a JSON library first, then falls back to YAML
    • openapi-spec-validator stops relying on jsonschema-path and instead loads files using JSON, then YAML if needed

    To work around this without a change in the tool chain, users can load the schemas using requests:

    import requests
    import openapi_spec_validator
    
    url = "https://nodenormalization-sri.renci.org/openapi.json"
    schema = requests.get(url).json()
    
    openapi_spec_validator.validate(schema)

    (which reveals that the schema is invalid, actually, so fixing that file could also include adding decimal points to numbers in scientific notation).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions