Skip to content

Commit

Permalink
Configurable OAS 3.0 downcompile
Browse files Browse the repository at this point in the history
  • Loading branch information
avillar committed Nov 14, 2024
1 parent bff70fa commit 39d32ff
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 25 deletions.
5 changes: 4 additions & 1 deletion ogc/bblocks/entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@
imported_registers = []
register_additional_metadata = {}
sparql_conf = {}
schema_oas30_downcompile = False
if bb_config_file and bb_config_file.is_file():
bb_config = load_yaml(filename=bb_config_file)
id_prefix = bb_config.get('identifier-prefix', id_prefix)
Expand Down Expand Up @@ -208,6 +209,7 @@
if bb_local_config_file.is_file():
bb_local_config = load_yaml(filename=bb_local_config_file)
import_local_mappings = bb_local_config.get('imports-local')
schema_oas30_downcompile = bb_config.get('schema-oas30-downcompile', False)

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

Expand Down Expand Up @@ -270,7 +272,8 @@
git_repo_path=git_repo_path,
viewer_path=(args.viewer_path or '.') if deploy_viewer else None,
additional_metadata=register_additional_metadata,
import_local_mappings=import_local_mappings)
import_local_mappings=import_local_mappings,
schemas_oas30_downcompile=schema_oas30_downcompile)

# 2. Uplift register.json
print(f"Running semantic uplift of {register_file}", file=sys.stderr)
Expand Down
6 changes: 4 additions & 2 deletions ogc/bblocks/postprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ def postprocess(registered_items_path: str | Path = 'registereditems',
git_repo_path: Path | None = None,
viewer_path: str | Path | None = None,
additional_metadata: dict | None = None,
import_local_mappings: dict[str, str] | None = None) -> list[dict]:
import_local_mappings: dict[str, str] | None = None,
schemas_oas30_downcompile=False) -> list[dict]:

cwd = Path().resolve()

Expand Down Expand Up @@ -270,7 +271,8 @@ def do_postprocess(bblock: BuildingBlock, light: bool = False) -> bool:
for annotated in annotate_schema(building_block,
bblocks_register=bbr,
context=default_jsonld_context,
base_url=base_url):
base_url=base_url,
oas30_downcompile=schemas_oas30_downcompile):
print(f" - {annotated}", file=sys.stderr)
except Exception as e:
if fail_on_error:
Expand Down
41 changes: 20 additions & 21 deletions ogc/bblocks/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ def load_contents(self, s: str | Path) -> tuple[dict, bool]:
def annotate_schema(bblock: BuildingBlock,
bblocks_register: BuildingBlockRegister,
context: Path | dict | None = None,
base_url: str | None = None) -> list[Path]:
base_url: str | None = None,
oas30_downcompile: bool = False) -> list[Path]:
result = []
schema_fn = None
schema_url = None
Expand Down Expand Up @@ -158,26 +159,24 @@ def update_json_ref(ref: str):
'\n - '.join(potential_yaml_refs.keys()), '\n\n')

# OAS 3.0
# try:
# if base_url:
# oas30_schema_fn = annotated_schema_fn.with_stem('schema-oas3.0')
# dump_yaml(oas30.schema_to_oas30(annotated_schema_fn,
# urljoin(base_url, str(os.path.relpath(oas30_schema_fn))),
# bblocks_register),
# oas30_schema_fn)
# result.append(oas30_schema_fn)
#
# print("oas30 yaml dumped", time.time() - start)
#
# oas30_schema_json_fn = annotated_schema_json_fn.with_stem('schema-oas3.0')
# with open(oas30_schema_json_fn, 'w') as f:
# json.dump(oas30.schema_to_oas30(annotated_schema_json_fn,
# urljoin(base_url, str(os.path.relpath(oas30_schema_json_fn))),
# bblocks_register), f, indent=2)
# result.append(oas30_schema_json_fn)
# print("oas30 json dumped", time.time() - start)
# except Exception as e:
# print('Error building OAS 3.0 documents:', e, file=sys.stderr)
if oas30_downcompile:
try:
if base_url:
oas30_schema_fn = annotated_schema_fn.with_stem('schema-oas3.0')
dump_yaml(oas30.schema_to_oas30(annotated_schema_fn,
urljoin(base_url, str(os.path.relpath(oas30_schema_fn))),
bblocks_register),
oas30_schema_fn)
result.append(oas30_schema_fn)

oas30_schema_json_fn = annotated_schema_json_fn.with_stem('schema-oas3.0')
with open(oas30_schema_json_fn, 'w') as f:
json.dump(oas30.schema_to_oas30(annotated_schema_json_fn,
urljoin(base_url, str(os.path.relpath(oas30_schema_json_fn))),
bblocks_register), f, indent=2)
result.append(oas30_schema_json_fn)
except Exception as e:
print('Error building OAS 3.0 documents:', e, file=sys.stderr)

return result

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 39d32ff

Please sign in to comment.