Skip to content

Support for local redirection for json schema $ref with http[s]:// uris #3103

@Chaz6

Description

@Chaz6

Is your feature request related to a problem? Please describe.
In an air-gapped environment we may want to use json schema files that contain a $ref, for example http://example.com/application/package/element/sub-element. At present the only option related to resolving http references is to either enable or disable them.

Describe the solution you'd like
I would like the api to provide an option to use a specified path to resolve any http[s]:// references, for example this can be achieved using the `referencing library:-

SCHEMA_STORE = Path("/app/data/schemas")

def retrieve(uri: str):                                                                          
  if uri.startswith("https://"):
    uri = uri[8:]
  elif uri.startswith("http://"):
    uri = uri[7:]
  file_path = SCHEMA_STORE / uri + ".json"
  if not file_path.exists():
    raise NoSuchResource(ref=uri)
  try:
    Resource.from_contents(json.loads(path.read_text(encoding="utf-8"))) 
  except Exception as ex:
    raise Unretrievable(ref=uri) from ex

Describe alternatives you've considered
I am not sure if there is any suitable alternative.

Additional context
See also #1820

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions