Created
July 16, 2024 19:07
-
-
Save dblock/c783e208abe1cf3f989f29cb52e71558 to your computer and use it in GitHub Desktop.
Expabnd Refs
This file contains hidden or 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
def expand_refs(element: Any, data: Any) -> Any: | |
""" | |
Recursively expand $ref's. | |
""" | |
if isinstance(element, dict): | |
if "$ref" in element: | |
common_schema_path_ref = element["$ref"].split("/")[-1] | |
schema = data["components"]["schemas"][common_schema_path_ref] | |
del element["$ref"] | |
element = element | expand_refs(schema, data) | |
for key in element: | |
element[key] = expand_refs(element[key], data) | |
return element | |
if isinstance(element, list): | |
result = [] | |
for item in element: | |
result.append(expand_refs(item, data)) | |
return result | |
return element |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment