Skip to content

Instantly share code, notes, and snippets.

@toonsevrin
Created May 4, 2020 13:13
Show Gist options
  • Save toonsevrin/919e327bc5cd9eabc0fe6e05f699bb2f to your computer and use it in GitHub Desktop.
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'
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