File tree 1 file changed +37
-0
lines changed
1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change
1
+ import os
2
+ import yaml
3
+
4
+ def fixfile (filename ):
5
+ #print(filename)
6
+ data = ""
7
+ with open (filename , "r" ) as tmp :
8
+ data = yaml .load (tmp .read ())
9
+
10
+ try :
11
+ # Rewrites swagger if it's wrong
12
+ version = data ["swagger" ]
13
+ if version == "3.0" :
14
+ data ["openapi" ] = "3.0.0"
15
+ del data ["swagger" ]
16
+ print ("Fixed swagger for %s" % filename )
17
+ except KeyError as e :
18
+ try :
19
+ version = data ["openapi" ]
20
+ if version == "3.0" or version == "2.0" :
21
+ data ["openapi" ] = "3.0.0"
22
+ print ("Fixed openapi for %s" % filename )
23
+ except KeyError as e :
24
+ print ("Error: %s" % e )
25
+
26
+ if isinstance (data , object ):
27
+ with open (filename , "w+" ) as tmp :
28
+ tmp .write (yaml .dump (data ))
29
+ else :
30
+ print ("Failed to write data. Type: %s" % type (data ))
31
+
32
+
33
+ newfile = "."
34
+ files = os .listdir (newfile )
35
+ for subfile in files :
36
+ if subfile .endswith (".yaml" ) or subfile .endswith (".yml" ):
37
+ fixfile ("%s/%s" % (newfile , subfile ))
You can’t perform that action at this time.
0 commit comments