Last active
June 21, 2019 09:25
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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