Skip to content

Commit 1edf755

Browse files
author
James (ODSC)
authored
Merge pull request #369 from OpenDataServices/use-referring-title-if-available
use-titles: Use $ref'erring title if available
2 parents 1682c70 + 7d14a6c commit 1edf755

File tree

10 files changed

+72
-2
lines changed

10 files changed

+72
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
66

77
## [Unreleased]
88

9+
### Fixed
10+
11+
- use-titles: Use $ref'erring title if available https://github.com/OpenDataServices/flatten-tool/pull/368
12+
913
## [0.15.2] - 2020-10-29
1014

1115
### Fixed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
$ flatten-tool flatten --root-list-path=weather --main-sheet-name=weather --use-titles --schema=examples/titles-ref/schema.json examples/titles-ref/flatten/data.json -f csv -o examples/titles-ref/flatten/actual
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"weather": [
3+
{
4+
"id": "monday",
5+
"rain": "tons and tons",
6+
"thunder": "none"
7+
},
8+
{
9+
"id": "tuesday",
10+
"rain": "dry as a bone",
11+
"thunder": "loud as fireworks night"
12+
}
13+
]
14+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Identifier,Was it soggy?,Was it noisy?
2+
monday,tons and tons,none
3+
tuesday,dry as a bone,loud as fireworks night

examples/titles-ref/schema.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-04/schema#",
3+
"definitions": {
4+
"Value": {
5+
"type": "string",
6+
"title": "A lowly string"
7+
}
8+
},
9+
"type": "object",
10+
"properties": {
11+
"id": {
12+
"type": "string",
13+
"title": "Identifier"
14+
},
15+
"rain": {
16+
"$ref": "#/definitions/Value",
17+
"title": "Was it soggy?"
18+
},
19+
"thunder": {
20+
"$ref": "#/definitions/Value",
21+
"title": "Was it noisy?"
22+
}
23+
}
24+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
$ flatten-tool unflatten -f csv --root-list-path=weather --convert-titles --schema=examples/titles-ref/schema.json examples/titles-ref/unflatten/data
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Identifier,Was it soggy?,Was it noisy?
2+
1st,tons and tons,none
3+
2nd,dry as a bone,loud as fireworks night
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"weather": [
3+
{
4+
"id": "1st",
5+
"rain": "tons and tons",
6+
"thunder": "none"
7+
},
8+
{
9+
"id": "2nd",
10+
"rain": "dry as a bone",
11+
"thunder": "loud as fireworks night"
12+
}
13+
]
14+
}

flattentool/schema.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,13 @@ def parse_schema_dict(
245245

246246
property_type_set = get_property_type_set(property_schema_dict)
247247

248-
title = property_schema_dict.get("title")
248+
if (
249+
hasattr(property_schema_dict, "__reference__")
250+
and "title" in property_schema_dict.__reference__
251+
):
252+
title = property_schema_dict.__reference__["title"]
253+
else:
254+
title = property_schema_dict.get("title")
249255
if title:
250256
title_lookup[title] = TitleLookup()
251257
title_lookup[title].property_name = property_name

flattentool/tests/test_docs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def test_example_in_doc(root, filename):
133133

134134

135135
def test_expected_number_of_examples_in_docs_data():
136-
assert len(examples_in_docs_data) == 57
136+
assert len(examples_in_docs_data) == 59
137137

138138

139139
def _simplify_warnings(lines):

0 commit comments

Comments
 (0)