Skip to content

Commit f4fbb96

Browse files
committed
fix schema resolution
1 parent 06309d4 commit f4fbb96

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

ngff_spec/pre_build.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
import glob
44
from pathlib import Path
55
import jsonc as json
6+
import logging
7+
8+
# Suppress warnings from json-schema-for-humans about unresolvable URLs
9+
logging.getLogger().setLevel(logging.ERROR)
610

711
# change working directory to the location of this script
812
os.chdir(os.path.dirname(os.path.abspath(__file__)))
@@ -67,12 +71,21 @@ def build_json_examples():
6771
def build_json_schemas():
6872
from json_schema_for_humans.generate import generate_from_filename
6973
from json_schema_for_humans.generation_configuration import GenerationConfiguration
74+
import json
7075

7176
schema_source_dir = 'schemas'
7277
output_directory = '_generated/schemas'
7378
os.makedirs(output_directory, exist_ok=True)
7479
schema_files = glob.glob(os.path.join(schema_source_dir, '*.schema'), recursive=True)
7580

81+
# Create a resolver mapping for local schemas
82+
schema_mapping = {}
83+
for schema_file in schema_files:
84+
with open(schema_file, 'r') as f:
85+
schema_content = json.load(f)
86+
if '$id' in schema_content:
87+
schema_mapping[schema_content['$id']] = os.path.abspath(schema_file)
88+
7689
index_markdown = """# JSON Schemas
7790
7891
This section contains JSON schemas for various metadata layouts.
@@ -98,7 +111,8 @@ def build_json_schemas():
98111
template_name='md',
99112
with_footer=True,
100113
show_toc=False,
101-
link_to_reused_ref=False)
114+
link_to_reused_ref=False,
115+
custom_template_global_vars={'schema_mapping': schema_mapping})
102116
generate_from_filename(
103117
os.path.abspath(schema_file),
104118
result_file_name=os.path.abspath(output_path_md),
@@ -122,7 +136,8 @@ def build_json_schemas():
122136
template_name='js',
123137
with_footer=True,
124138
show_toc=False,
125-
link_to_reused_ref=False)
139+
link_to_reused_ref=False,
140+
custom_template_global_vars={'schema_mapping': schema_mapping})
126141

127142
generate_from_filename(
128143
os.path.abspath(schema_file),

0 commit comments

Comments
 (0)