12
12
13
13
import os
14
14
import json
15
- import yaml
16
- import requests
17
- from collections import OrderedDict
18
15
19
16
def write_json (filename : str , object : dict ) -> None :
20
17
"""
@@ -29,28 +26,41 @@ def create_ref(path):
29
26
"""
30
27
return '#/definitions/' + path
31
28
32
- def consolidate_crds () -> object :
29
+ def consolidate_schemas () -> object :
33
30
"""
34
- Consolidate all crds in /crds into one json object
31
+ Consolidate all schemas into one json object
35
32
"""
36
- crds_dir = os .path .join ('crds' )
37
- crds = os .listdir (crds_dir )
38
- consolidated_crds_json = {
33
+ schemas_dir = os .path .join ('schemas/latest' )
34
+ consolidated_schemas_json = {
39
35
'definitions' : {},
40
36
}
41
- for file in crds :
42
- crd_file_path = os .path .join (crds_dir , file )
43
- with open (crd_file_path ) as file :
44
- yamlData = yaml .load (file , Loader = yaml .FullLoader )
45
- crd_name = yamlData ['spec' ]['names' ]['kind' ]
46
-
47
- # Add all the available schema versions
48
- for version in yamlData ['spec' ]['versions' ]:
49
- new_json_name = version ['name' ] + '.' + crd_name
50
- new_schema = version ['schema' ]['openAPIV3Schema' ]
51
- consolidated_crds_json ['definitions' ][new_json_name ] = new_schema
52
-
53
- return consolidated_crds_json
37
+
38
+ with open (os .path .join (schemas_dir , 'k8sApiVersion.txt' )) as f :
39
+ k8sApiVersion = f .readline ()
40
+
41
+ with open (os .path .join (schemas_dir , 'jsonSchemaVersion.txt' )) as f :
42
+ devfileVersion = f .readline ()
43
+ devfileVersion = devfileVersion .replace ('-alpha' , '' )
44
+
45
+ definitionName = devfileVersion + '.Devfile'
46
+ devfile_json_schema_path = os .path .join (schemas_dir , 'devfile.json' )
47
+ with open (devfile_json_schema_path , 'r' ) as devfileFile :
48
+ jsonData = json .load (devfileFile )
49
+ consolidated_schemas_json ['definitions' ][definitionName ] = jsonData
50
+
51
+ definitionName = k8sApiVersion + '.DevWorkspace'
52
+ dw_json_schema_path = os .path .join (schemas_dir , 'dev-workspace.json' )
53
+ with open (dw_json_schema_path , 'r' ) as devfileFile :
54
+ jsonData = json .load (devfileFile )
55
+ consolidated_schemas_json ['definitions' ][definitionName ] = jsonData
56
+
57
+ definitionName = k8sApiVersion + '.DevWorkspaceTemplate'
58
+ dwt_json_schema_path = os .path .join (schemas_dir , 'dev-workspace-template.json' )
59
+ with open (dwt_json_schema_path , 'r' ) as devfileFile :
60
+ jsonData = json .load (devfileFile )
61
+ consolidated_schemas_json ['definitions' ][definitionName ] = jsonData
62
+
63
+ return consolidated_schemas_json
54
64
55
65
def add_property_definition (root_definitions_object : dict , current_path : str , curr_object : dict , queue : list ) -> None :
56
66
"""
@@ -251,5 +261,6 @@ def flatten(consolidated_crds_object: dict) -> None:
251
261
write_json ('swagger.json' , flattened_swagger_object )
252
262
253
263
if __name__ == "__main__" :
254
- swagger_crds_json = consolidate_crds ()
264
+ # Get the schema and flatten them
265
+ swagger_crds_json = consolidate_schemas ()
255
266
flatten (swagger_crds_json )
0 commit comments