Skip to content

Instantly share code, notes, and snippets.

Embed
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 = 'https://raw.githubusercontent.com/teamdigitale/io-functions-commons/3c1ce27905798f87bdae08f46697edc38bb4ca99/openapi/index.yaml#/definitions'
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}}
extra_definitions.update(_d)
return extra_definitions
print(yaml.dump(generate_definitions_from_url(url)))
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.