How to use fastjsonschema - 10 common examples

To help you get started, we’ve selected a few fastjsonschema examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github horejsek / python-fastjsonschema / tests / json_schema / utils.py View on Github external
def template_test(schema_version, schema, data, is_valid):
    """
    Test function to be used (imported) in final test file to run the tests
    which are generated by `pytest_generate_tests` hook.
    """
    # For debug purposes. When test fails, it will print stdout.
    resolver = RefResolver.from_schema(schema, handlers={'http': remotes_handler})

    debug_generator = _get_code_generator_class(schema_version)(schema, resolver=resolver)
    print(debug_generator.global_state_code)
    print(debug_generator.func_code)

    # JSON schema test suits do not contain schema version.
    # Our library needs to know that or it would use always the latest implementation.
    if isinstance(schema, dict):
        schema.setdefault('$schema', schema_version)

    validate = compile(schema, handlers={'http': remotes_handler})
    try:
        result = validate(data)
        print('Validate result:', result)
    except JsonSchemaException:
        if is_valid:
github horejsek / python-fastjsonschema / tests / json_schema / utils.py View on Github external
def template_test(schema_version, schema, data, is_valid):
    """
    Test function to be used (imported) in final test file to run the tests
    which are generated by `pytest_generate_tests` hook.
    """
    # For debug purposes. When test fails, it will print stdout.
    resolver = RefResolver.from_schema(schema, handlers={'http': remotes_handler})

    debug_generator = _get_code_generator_class(schema_version)(schema, resolver=resolver)
    print(debug_generator.global_state_code)
    print(debug_generator.func_code)

    # JSON schema test suits do not contain schema version.
    # Our library needs to know that or it would use always the latest implementation.
    if isinstance(schema, dict):
        schema.setdefault('$schema', schema_version)

    validate = compile(schema, handlers={'http': remotes_handler})
    try:
        result = validate(data)
        print('Validate result:', result)
    except JsonSchemaException:
        if is_valid:
            raise
    else:
github cisco-en-programmability / dnacentersdk / tests / models / validators / v1_3_0 / jsd_4bb22af046fa8f08.py View on Github external
def __init__(self):
        super(JSONSchemaValidator4Bb22Af046Fa8F08, self).__init__()
        self._validator = fastjsonschema.compile(json.loads(
            '''{
                "properties": {
                "response": {
                "properties": {
                "taskId": {},
                "url": {
                "description":
                 "",
                "type": [
                "string",
                "null"
                ]
                }
                },
                "type": [
                "object",
github cisco-en-programmability / dnacentersdk / tests / models / validators / v2_1_1 / jsd_cd98780f4888a66d.py View on Github external
def __init__(self):
        super(JSONSchemaValidatorCd98780F4888A66D, self).__init__()
        self._validator = fastjsonschema.compile(json.loads(
            '''{
                "properties": {
                "response": {
                "properties": {
                "taskId": {},
                "url": {
                "description":
                 "",
                "type": [
                "string",
                "null"
                ]
                }
                },
                "type": [
                "object",
github cisco-en-programmability / dnacentersdk / tests / models / validators / v1_3_1 / jsd_17929bc7465bb564.py View on Github external
def __init__(self):
        super(JSONSchemaValidator17929Bc7465BB564, self).__init__()
        self._validator = fastjsonschema.compile(json.loads(
            '''{
                "properties": {
                "response": {
                "properties": {
                "taskId": {},
                "url": {
                "description":
                 "",
                "type": [
                "string",
                "null"
                ]
                }
                },
                "type": [
                "object",
github cisco-en-programmability / dnacentersdk / tests / models / validators / v1_3_0 / jsd_a395fae644ca899c.py View on Github external
def __init__(self):
        super(JSONSchemaValidatorA395Fae644Ca899C, self).__init__()
        self._validator = fastjsonschema.compile(json.loads(
            '''{
                "properties": {
                "response": {
                "properties": {
                "flowAnalysisId": {
                "description":
                 "",
                "type": [
                "string",
                "null"
                ]
                },
                "taskId": {
                "description":
                 "",
                "type": [
github cisco-en-programmability / dnacentersdk / tests / models / validators / v2_1_1 / jsd_7aa3da9d4e098ef2.py View on Github external
def __init__(self):
        super(JSONSchemaValidator7Aa3Da9D4E098Ef2, self).__init__()
        self._validator = fastjsonschema.compile(json.loads(
            '''{
                "properties": {
                "response": {
                "properties": {
                "taskId": {},
                "url": {
                "description":
                 "",
                "type": [
                "string",
                "null"
                ]
                }
                },
                "type": [
                "object",
github cisco-en-programmability / dnacentersdk / tests / models / validators / v2_1_1 / jsd_1da5ebdd434aacfe.py View on Github external
def validate(self, request):
        try:
            self._validator(request)
        except fastjsonschema.exceptions.JsonSchemaException as e:
            raise MalformedRequest(
                '{} is invalid. Reason: {}'.format(request, e.message)
            )
github cisco-en-programmability / dnacentersdk / tests / models / validators / v1_3_3 / jsd_d2b4d9d04a4b884c.py View on Github external
def validate(self, request):
        try:
            self._validator(request)
        except fastjsonschema.exceptions.JsonSchemaException as e:
            raise MalformedRequest(
                '{} is invalid. Reason: {}'.format(request, e.message)
            )
github cisco-en-programmability / dnacentersdk / tests / models / validators / v1_3_3 / jsd_45bc7a8344a8bc1e.py View on Github external
def validate(self, request):
        try:
            self._validator(request)
        except fastjsonschema.exceptions.JsonSchemaException as e:
            raise MalformedRequest(
                '{} is invalid. Reason: {}'.format(request, e.message)
            )