Skip to content

How is asserting None handled #603

Closed
@humbienri

Description

@humbienri

Given this requests response.json() (note the None instead of null):

    "version": "2.3.4",
    "result": "Multi-Status",
    "data": [
        {
            "derId": 583,
            "warnings": [],
            "status": "success",
            "error": None
        }
    ]
}

why is it that this schema isn't sufficient:

    "$schema": "http://json-schema.org/draft-04/schema#",
    "title": "",
    "description": "JSON schema for the HTTP REST API response.",
    "type": "object",
    "properties": {
        "version": {"type": "string"},
        "result": {"type": "string"},
        "data": {
            "type": "array",
            "items": {
                "type": "object",
                "properties": {
                    "derId": {"type": "integer"},
                    "warnings": {"type": "array"},
                    "status": {"type": "string"},
                    "error": {"type": ["null","string"]}
                },
                "required": ["derId", "status", "warnings", "error"]
            }
        }
    },
    "required": ["data", "result", "version"]
}

Even if I remove the requirement for the error property, jsonschema.validate() chokes on the presence of None.

I realize that None is a python thing and not valid json, as I understand it, but it is the calling of the .json() api on the API's response that introduces the None.

Thank you in advance.

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