-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfix-swagger.py
45 lines (32 loc) · 1.23 KB
/
fix-swagger.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import yaml
"""
There are some issues with the serverless plugin adding the options (cors) endpoints to the swagger spec,
without using correct path parameters etc. This clears the options endpoints from the swagger file, as they are
generally not needed / implicit.
This also adds the extra info properties that are not working (also a serverless plugin problem)
"""
def filterOptions(path):
if "options" in path:
del path["options"]
return path
def addInfo(contents):
contents["info"][
"description"
] = """Api for å registrere og redigere metadata for datasett i dataplattformen.
Create og Update endepunktene krever autorisasjon, mens resten er åpent."""
contents["info"]["contact"] = {
"name": "Origo dataplattform",
"email": "[email protected]",
}
return contents
def read():
with open("swagger.yaml", "r") as f:
swagger = yaml.safe_load(f)
paths = swagger["paths"]
swagger["paths"] = {name: filterOptions(paths[name]) for name in paths}
return addInfo(swagger)
def write(content):
with open("swagger.yaml", "w") as f:
f.write(content)
fixed = read()
write(yaml.dump(fixed, sort_keys=False, allow_unicode=True))