@@ -55,7 +55,8 @@ def load_contents(self, s: str | Path) -> tuple[dict, bool]:
5555def annotate_schema (bblock : BuildingBlock ,
5656 bblocks_register : BuildingBlockRegister ,
5757 context : Path | dict | None = None ,
58- base_url : str | None = None ) -> list [Path ]:
58+ base_url : str | None = None ,
59+ oas30_downcompile : bool = False ) -> list [Path ]:
5960 result = []
6061 schema_fn = None
6162 schema_url = None
@@ -158,26 +159,24 @@ def update_json_ref(ref: str):
158159 '\n - ' .join (potential_yaml_refs .keys ()), '\n \n ' )
159160
160161 # OAS 3.0
161- # try:
162- # if base_url:
163- # oas30_schema_fn = annotated_schema_fn.with_stem('schema-oas3.0')
164- # dump_yaml(oas30.schema_to_oas30(annotated_schema_fn,
165- # urljoin(base_url, str(os.path.relpath(oas30_schema_fn))),
166- # bblocks_register),
167- # oas30_schema_fn)
168- # result.append(oas30_schema_fn)
169- #
170- # print("oas30 yaml dumped", time.time() - start)
171- #
172- # oas30_schema_json_fn = annotated_schema_json_fn.with_stem('schema-oas3.0')
173- # with open(oas30_schema_json_fn, 'w') as f:
174- # json.dump(oas30.schema_to_oas30(annotated_schema_json_fn,
175- # urljoin(base_url, str(os.path.relpath(oas30_schema_json_fn))),
176- # bblocks_register), f, indent=2)
177- # result.append(oas30_schema_json_fn)
178- # print("oas30 json dumped", time.time() - start)
179- # except Exception as e:
180- # print('Error building OAS 3.0 documents:', e, file=sys.stderr)
162+ if oas30_downcompile :
163+ try :
164+ if base_url :
165+ oas30_schema_fn = annotated_schema_fn .with_stem ('schema-oas3.0' )
166+ dump_yaml (oas30 .schema_to_oas30 (annotated_schema_fn ,
167+ urljoin (base_url , str (os .path .relpath (oas30_schema_fn ))),
168+ bblocks_register ),
169+ oas30_schema_fn )
170+ result .append (oas30_schema_fn )
171+
172+ oas30_schema_json_fn = annotated_schema_json_fn .with_stem ('schema-oas3.0' )
173+ with open (oas30_schema_json_fn , 'w' ) as f :
174+ json .dump (oas30 .schema_to_oas30 (annotated_schema_json_fn ,
175+ urljoin (base_url , str (os .path .relpath (oas30_schema_json_fn ))),
176+ bblocks_register ), f , indent = 2 )
177+ result .append (oas30_schema_json_fn )
178+ except Exception as e :
179+ print ('Error building OAS 3.0 documents:' , e , file = sys .stderr )
181180
182181 return result
183182
0 commit comments