Skip to content

Commit 39d32ff

Browse files
committed
Configurable OAS 3.0 downcompile
1 parent bff70fa commit 39d32ff

File tree

4 files changed

+29
-25
lines changed

4 files changed

+29
-25
lines changed

ogc/bblocks/entrypoint.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@
180180
imported_registers = []
181181
register_additional_metadata = {}
182182
sparql_conf = {}
183+
schema_oas30_downcompile = False
183184
if bb_config_file and bb_config_file.is_file():
184185
bb_config = load_yaml(filename=bb_config_file)
185186
id_prefix = bb_config.get('identifier-prefix', id_prefix)
@@ -208,6 +209,7 @@
208209
if bb_local_config_file.is_file():
209210
bb_local_config = load_yaml(filename=bb_local_config_file)
210211
import_local_mappings = bb_local_config.get('imports-local')
212+
schema_oas30_downcompile = bb_config.get('schema-oas30-downcompile', False)
211213

212214
register_additional_metadata['modified'] = datetime.datetime.now().isoformat()
213215

@@ -270,7 +272,8 @@
270272
git_repo_path=git_repo_path,
271273
viewer_path=(args.viewer_path or '.') if deploy_viewer else None,
272274
additional_metadata=register_additional_metadata,
273-
import_local_mappings=import_local_mappings)
275+
import_local_mappings=import_local_mappings,
276+
schemas_oas30_downcompile=schema_oas30_downcompile)
274277

275278
# 2. Uplift register.json
276279
print(f"Running semantic uplift of {register_file}", file=sys.stderr)

ogc/bblocks/postprocess.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ def postprocess(registered_items_path: str | Path = 'registereditems',
4242
git_repo_path: Path | None = None,
4343
viewer_path: str | Path | None = None,
4444
additional_metadata: dict | None = None,
45-
import_local_mappings: dict[str, str] | None = None) -> list[dict]:
45+
import_local_mappings: dict[str, str] | None = None,
46+
schemas_oas30_downcompile=False) -> list[dict]:
4647

4748
cwd = Path().resolve()
4849

@@ -270,7 +271,8 @@ def do_postprocess(bblock: BuildingBlock, light: bool = False) -> bool:
270271
for annotated in annotate_schema(building_block,
271272
bblocks_register=bbr,
272273
context=default_jsonld_context,
273-
base_url=base_url):
274+
base_url=base_url,
275+
oas30_downcompile=schemas_oas30_downcompile):
274276
print(f" - {annotated}", file=sys.stderr)
275277
except Exception as e:
276278
if fail_on_error:

ogc/bblocks/schema.py

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ def load_contents(self, s: str | Path) -> tuple[dict, bool]:
5555
def 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

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)