Skip to content

CLI: Invalid "format" not detected #624

Closed
@cweiske

Description

@cweiske

I made a mistake in my schema and had "format": ["date", "datetime"], which is invalid.

I tried to validate my schema against the official JSON schema for JSON schema: http://json-schema.org/draft/2019-09/schema but jsonschema did not complain:

$ jsonschema -i test-schema.json json-schema.schema.json ; echo $?
0

My test schema:

{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "type": "object",
    "properties": {
        "foo": {
            "type": "array",
            "items": {
                "type": "string",
                "format": ["date", "datetime"]
            }
        }
    }
}

jsonschema should complain about that format not being a string.


The (not understandable for me) error I got was:

$ jsonschema -i test-data.json test-schema.json
Traceback (most recent call last):
  File "/usr/local/bin/jsonschema", line 10, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.7/dist-packages/jsonschema/cli.py", line 76, in main
    sys.exit(run(arguments=parse_args(args=args)))
  File "/usr/local/lib/python3.7/dist-packages/jsonschema/cli.py", line 83, in run
    validator.check_schema(arguments["schema"])
  File "/usr/local/lib/python3.7/dist-packages/jsonschema/validators.py", line 294, in check_schema
    raise exceptions.SchemaError.create_from(error)
jsonschema.exceptions.SchemaError: {'type': 'string', 'format': ['date', 'datetime']} is not valid under any of the given schemas

Failed validating 'anyOf' in metaschema['properties']['properties']['additionalProperties']['properties']['items']:
    {'anyOf': [{'$ref': '#'}, {'$ref': '#/definitions/schemaArray'}],
     'default': True}

On schema['properties']['foo']['items']:
    {'format': ['date', 'datetime'], 'type': 'string'}

Data:

{"foo": ["2019-10-23"]}

Metadata

Metadata

Assignees

No one assigned

    Labels

    EnhancementSome new desired functionality

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions