Skip to content

Commit 93d2e00

Browse files
committed
feat(views): include example;
- Allow including examples for published resource schemas.
1 parent 4dc4415 commit 93d2e00

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

changes/0017.changes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added `include_example` URI parameter option to the `published_schema_json` route to allow for more robust DEPs.

ckanext/recombinant/views.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,8 @@ def published_data_dictionary(dataset_type: str) -> Response:
441441
return _data_dictionary(dataset_type, published_resource=True)
442442

443443

444-
def _schema_json(dataset_type: str, published_resource: bool = False) -> Response:
444+
def _schema_json(dataset_type: str, published_resource: bool = False,
445+
include_example: bool = True) -> Response:
445446
try:
446447
geno = get_geno(dataset_type)
447448
except RecombinantException:
@@ -526,7 +527,7 @@ def _schema_json(dataset_type: str, published_resource: bool = False) -> Respons
526527
for ck, cv in choice_fields[fld['id']]:
527528
choices[ck] = cv
528529

529-
if not published_resource and 'examples' in chromo:
530+
if include_example and 'examples' in chromo:
530531
ex_record = chromo['examples']['record']
531532
example = {}
532533
for field in chromo['fields']:
@@ -554,7 +555,9 @@ def schema_json(dataset_type: str) -> Response:
554555
@recombinant.route('/recombinant-published-schema/<dataset_type>.json')
555556
@nocache_store
556557
def published_schema_json(dataset_type: str) -> Response:
557-
return _schema_json(dataset_type, published_resource=True)
558+
include_example = asbool(request.args.get('include_example', False))
559+
return _schema_json(dataset_type, published_resource=True,
560+
include_example=include_example)
558561

559562

560563
@recombinant.route('/recombinant/<resource_name>')

0 commit comments

Comments
 (0)