Created
May 4, 2020 13:13
-
-
Save toonsevrin/919e327bc5cd9eabc0fe6e05f699bb2f to your computer and use it in GitHub Desktop.
Rewrites the openapi spec to use "time" instead of "date-time" for fields ending in 'date'
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
import yaml | |
input = "./swagger/specification.yaml" # Which file to read | |
output = "./swagger/specification.yaml" # which file to write to | |
def Fix(obj: object, isDate: bool) -> object: | |
if type(obj) != dict: | |
return obj | |
for k, v in obj.items(): | |
valIsDate = type(k) == str and k.lower().endswith("date") | |
obj[k] = Fix(v, valIsDate) | |
if isDate and k == "format": | |
obj[k] = "date" | |
return obj | |
if __name__ == '__main__': | |
print("Started fixer...") | |
parsed = None | |
with open(input, "r") as file: | |
parsed = yaml.safe_load(file) | |
fixed = Fix(parsed, False) | |
with open(output, "w") as file: | |
yaml.dump(fixed, file) | |
print("Fixer finished!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment