Skip to content

Instantly share code, notes, and snippets.

@ioggstream
Last active June 21, 2019 09:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ioggstream/00d31539ff332d538474b6acae5e09ff to your computer and use it in GitHub Desktop.
Save ioggstream/00d31539ff332d538474b6acae5e09ff to your computer and use it in GitHub Desktop.
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