Skip to content

How to migrate from RefResolver to referencing  #1079

@cscetbon

Description

@cscetbon

Trying to follow https://python-jsonschema.readthedocs.io/en/latest/referencing/#migrating-from-refresolver using the latest alpha version but I can't get it to work. I currently have

def get_schema():
  return {
{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "definitions": {
        "edm": {...},
        "eem": {...}
    },
    "anyOf": [
        {
            "$ref": "#/definitions/eem/events/SISAddress"
        },
        {
            "$ref": "#/definitions/eem/events/SISEnrollment"
        },
        {
            "$ref": "#/definitions/eem/events/SISPerson"
        },
        {
            "$ref": "#/definitions/eem/events/SISRestriction"
        },
        {
            "$ref": "#/definitions/eem/events/SISSection"
        }
    ]
}
  }
my_schema = get_schema()
schemastore = {
  'https://my_url/EDM.json': my_schema['definitions']['edm'],
  'https://my_url/EEM.json': my_schema['definitions']['eem']
}

resolver = jsonschema.RefResolver(base_uri='', referrer=my_schema, store=schemastore)
jsonschema.validate(payload, my_schema, resolver=resolver)

I tried to do

my_schema = get_schema()
schema = Resource.from_contents(my_schema)
registry = Registry().with_resources([
  ('https://my_url/EDM.json', my_schema['definitions']['edm']),
  ('https://my_url/EEM.json', my_schema['definitions']['eem'])
])
validator = Draft4Validator(schema=my_schema, registry=registry)
validator.validate(payload)

but I get

...
File ~/.virtualenvs/sds/lib/python3.10/site-packages/referencing/_core.py:394, in Registry.crawl(self)
    391 while uncrawled:
    392     uri, resource = uncrawled.pop()
--> 394     id = resource.id()
    395     if id is not None:
    396         uri = urljoin(uri, id)

AttributeError: 'dict' object has no attribute 'id'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions