Skip to content

Commit 8c64c21

Browse files
committed
Pass full pre-extraction code to transforms as snippet['full-code']
When json-path is used, transforms can now access the full source document via ctx.snippet['full-code'] alongside the extracted input_data. Warn when multiple matches are found. Strip full-code before json-full output.
1 parent 0f69a58 commit 8c64c21

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

ogc/bblocks/models.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,10 @@ def _load_examples(self):
239239
logger.warning('json-path %s found no matches in ref %s - skipping snippet',
240240
snippet['json-path'], ref)
241241
continue
242+
if len(matches) > 1:
243+
logger.warning('json-path %s found %d matches in ref %s - using first match only',
244+
snippet['json-path'], len(matches), ref)
245+
snippet['full-code'] = code
242246
snippet['code'] = dumper(matches[0].value)
243247
filtered_snippets.append(snippet)
244248
if 'snippets' in example:

ogc/bblocks/templates/json-full/index.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ output = {**bblock.metadata}
88
if bblock.description:
99
output['description'] = bblock.description
1010
if bblock.examples:
11-
output['examples'] = bblock.examples
11+
output['examples'] = [
12+
{**example, 'snippets': [{k: v for k, v in s.items() if k != 'full-code'}
13+
for s in example.get('snippets', [])]}
14+
if 'snippets' in example else example
15+
for example in bblock.examples
16+
]
1217
if bblock.example_prefixes:
1318
output['examplePrefixes'] = bblock.example_prefixes
1419
if bblock.annotated_schema:

0 commit comments

Comments
 (0)