Skip to content

Instantly share code, notes, and snippets.

@swathipil
Last active April 17, 2023 19:21
Show Gist options
  • Save swathipil/58903e8b23ec7fc77ced87c2bc834f84 to your computer and use it in GitHub Desktop.
Save swathipil/58903e8b23ec7fc77ced87c2bc834f84 to your computer and use it in GitHub Desktop.
Investigation of Schema Registry Service Behavior given JSON Schema Drafts 4 + 6

TL;DR

Schemas with different draft versions will be registered as new/different versions in the schema registry. Validation only relies on actual schema structure, but not on the draft version specified in the (optional) $schema attribute.

TODO:

  • See if/how json schema is generated from data.
  • Test out implementing json "serializer" + register schema generated from json data.

Investigating service responses given the following JSON Schema samples:

Schemas are the same, except for draft version

Draft 4:

JSON_SCHEMA_D4 = {
    "$id": "https://example.com/person.schema.json",
    "$schema": "http://json-schema.org/draft-04/schema#",
    "type": "object",
    "title": "Person",
    "properties": {
        "name": {
            "type": "string",
            "description": "Name."
        },
        "age": {
            "description": "Age in years.",
            "type": "integer",
            "minimum": 0
        }
    }
}

Draft 6:

JSON_SCHEMA_D6 = {
    "$id": "https://example.com/person.schema.json",
    "$schema": "http://json-schema.org/draft-06/schema#",
    "type": "object",
    "title": "Person",
    "properties": {
        "name": {
            "type": "string",
            "description": "Name."
        },
        "age": {
            "description": "Age in years.",
            "type": "integer",
            "minimum": 0
        }
    }
}

1. Registering only one draft of a schema and getting the other

GROUP_NAME = <<SCHEMAREGISTRY_GROUP>>
NAME = <<SCHEMA_NAME>>
FORMAT = SchemaFormat.JSON

# register D6 schema (or D4)
schema_properties = client.register_schema(group_name, name, JSON_SCHEMA_D6, format)

# get D4 schema (or D6)
schema_properties = client.get_schema_properties(group_name, name, JSON_SCHEMA_D4, format)

Service Response:

(ItemNotFound) Schema azsdk_python_test_group/your-schema-name does not exist. TrackingId:5a187612-8950-4ee9-abb7-8d1139d30993_G42, SystemTracker:t6d0001ace9dfa9c8-json.servicebus.windows.net:$schemaGroups/azsdk_python_test_group/schemas/your-schema-name:get-id, Timestamp:2023-04-13T22:53:15

2. Registering both drafts of a schema and getting either

GROUP_NAME = <<SCHEMAREGISTRY_GROUP>>
NAME = <<SCHEMA_NAME>>
FORMAT = SchemaFormat.JSON

# register schemas
schema_properties = client.register_schema(group_name, name, JSON_SCHEMA_D4, format)  # SchemaProperties(id=..., ..., version=1)
schema_properties = client.register_schema(group_name, name, JSON_SCHEMA_D6, format)  # SchemaProperties(id=..., ..., version=2)

# get schemas
schema_properties = client.get_schema_properties(group_name, name, JSON_SCHEMA_D4, format)  # SchemaProperties(id=..., ..., version=1)
schema_properties = client.get_schema_properties(group_name, name, JSON_SCHEMA_D6, format)  # SchemaProperties(id=..., ..., version=2)
  • Service returns properties of different versions of schema registered in schema registry.

RANDOM QUESTIONS:

  • In draft 6, does the "dependencies" section exist?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment