Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Retrieve a set of schemas defined in an URL and generate a set of definitions referencing those schemas
from requests import get
import yaml
from urllib.parse import urlparse
url = ''
def generate_definitions_from_url(url):
ret = get(url)
fragment = urlparse(url).fragment.strip('/')
definitions = yaml.load(ret.content)
for f in fragment.split("/"):
definitions = definitions[f]
extra_definitions = {}
for x in definitions:
_schema = '/'.join((ret.url, x))
_d = {x: {"$ref": _schema}}
return extra_definitions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.