Skip to content

Commit 0d1d284

Browse files
committed
Shorthand attributes
1 parent aaaf255 commit 0d1d284

File tree

3 files changed

+95
-24
lines changed

3 files changed

+95
-24
lines changed

share/openPMD/json_schema/attribute_defs.toml

Lines changed: 69 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,21 @@
55
# Vectors of strings #
66
######################
77

8-
["$defs".vec_string_attribute]
8+
[["$defs".vec_string_attribute.oneOf]]
9+
title = "Shorthand notation"
10+
anyOf = [
11+
{ type = "string" },
12+
{ type = "array", items = { "type" = "string" } },
13+
]
14+
15+
[["$defs".vec_string_attribute.oneOf]]
16+
title = "Long notation"
17+
type = "object"
918
required = ["value", "datatype"]
1019

11-
["$defs".vec_string_attribute.properties]
20+
["$defs".vec_string_attribute.oneOf.properties]
1221

13-
value.any_of = [
22+
value.anyOf = [
1423
{ type = "string" },
1524
{ type = "array", items = { "type" = "string" } },
1625
]
@@ -30,12 +39,21 @@ datatype.enum = [
3039
# Vectors of int #
3140
##################
3241

33-
["$defs".vec_int_attribute]
42+
[["$defs".vec_int_attribute.oneOf]]
43+
title = "Shorthand notation"
44+
anyOf = [
45+
{ type = "integer" },
46+
{ type = "array", items = { "type" = "integer" } },
47+
]
48+
49+
[["$defs".vec_int_attribute.oneOf]]
50+
title = "Long notation"
51+
type = "object"
3452
required = ["value", "datatype"]
3553

36-
["$defs".vec_int_attribute.properties]
54+
["$defs".vec_int_attribute.oneOf.properties]
3755

38-
value.any_of = [
56+
value.anyOf = [
3957
{ type = "integer" },
4058
{ type = "array", items = { "type" = "integer" } },
4159
]
@@ -63,12 +81,21 @@ datatype.enum = [
6381
# Vectors of float #
6482
####################
6583

66-
["$defs".vec_float_attribute]
84+
[["$defs".vec_float_attribute.oneOf]]
85+
title = "Shorthand notation"
86+
anyOf = [
87+
{ type = "number" },
88+
{ type = "array", items = { "type" = "number" } },
89+
]
90+
91+
[["$defs".vec_float_attribute.oneOf]]
92+
title = "Long notation"
93+
type = "object"
6794
required = ["value", "datatype"]
6895

69-
["$defs".vec_float_attribute.properties]
96+
["$defs".vec_float_attribute.oneOf.properties]
7097

71-
value.any_of = [
98+
value.anyOf = [
7299
{ type = "number" },
73100
{ type = "array", items = { "type" = "number" } },
74101
]
@@ -112,10 +139,17 @@ datatype.enum = [
112139
# unitDimension attribute #
113140
###########################
114141

115-
["$defs".unitDimension]
142+
[["$defs".unitDimension.oneOf]]
143+
title = "Shorthand notation"
144+
type = "array"
145+
items.type = "number"
146+
147+
[["$defs".unitDimension.oneOf]]
148+
title = "Long notation"
149+
type = "object"
116150
required = ["value", "datatype"]
117151

118-
["$defs".unitDimension.properties]
152+
["$defs".unitDimension.oneOf.properties]
119153

120154
value = { type = "array", items = { type = "number" } }
121155
datatype.const = "ARR_DBL_7"
@@ -124,10 +158,16 @@ datatype.const = "ARR_DBL_7"
124158
# string attributes #
125159
#####################
126160

127-
["$defs".string_attribute]
161+
[["$defs".string_attribute.oneOf]]
162+
title = "Shorthand notation"
163+
type = "string"
164+
165+
[["$defs".string_attribute.oneOf]]
166+
title = "Long notation"
167+
type = "object"
128168
required = ["value", "datatype"]
129169

130-
["$defs".string_attribute.properties]
170+
["$defs".string_attribute.oneOf.properties]
131171

132172
value.type = "string"
133173
datatype.enum = ["STRING", "CHAR", "SCHAR", "UCHAR"]
@@ -136,10 +176,16 @@ datatype.enum = ["STRING", "CHAR", "SCHAR", "UCHAR"]
136176
# int attributes #
137177
##################
138178

139-
["$defs".int_attribute]
179+
[["$defs".int_attribute.oneOf]]
180+
title = "Shorthand notation"
181+
type = "integer"
182+
183+
[["$defs".int_attribute.oneOf]]
184+
title = "Long notation"
185+
type = "object"
140186
required = ["value", "datatype"]
141187

142-
["$defs".int_attribute.properties]
188+
["$defs".int_attribute.oneOf.properties]
143189

144190
value.type = "integer"
145191
datatype.enum = [
@@ -157,10 +203,16 @@ datatype.enum = [
157203
# float attributes #
158204
####################
159205

160-
["$defs".float_attribute]
206+
[["$defs".float_attribute.oneOf]]
207+
title = "Shorthand notation"
208+
type = "number"
209+
210+
[["$defs".float_attribute.oneOf]]
211+
title = "Long notation"
212+
type = "object"
161213
required = ["value", "datatype"]
162214

163-
["$defs".float_attribute.properties]
215+
["$defs".float_attribute.oneOf.properties]
164216

165217
value.type = "number"
166218
datatype.enum = [

share/openPMD/json_schema/attributes.toml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,26 @@ type = "object"
99
title = "Dictionary of attributes"
1010
description = "Generic layout of an attributes object."
1111

12-
[oneOf.patternProperties.".*"]
13-
title = "A generic attribute"
12+
[[oneOf.patternProperties.".*".oneOf]]
13+
title = "A generic attribute - short form"
14+
anyOf = [
15+
# Any primitive value
16+
{ not = { anyOf = [
17+
{ type = "object", title = "An object" },
18+
{ type = "array", title = "An array" },
19+
] }, title = "No complex type" },
20+
# Or an array of any primitive value
21+
{ type = "array", items = { not = { anyOf = [
22+
{ type = "object", title = "An object" },
23+
{ type = "array", title = "An array" },
24+
] } }, title = "An array of non-complex types" },
25+
]
26+
27+
[[oneOf.patternProperties.".*".oneOf]]
28+
title = "A generic attribute - long form"
1429
type = "object"
1530

16-
[oneOf.patternProperties.".*".properties]
31+
[oneOf.patternProperties.".*".oneOf.properties]
1732

1833
value.anyOf = [
1934
# Any primitive value

share/openPMD/json_schema/series.toml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,16 @@ machine."$ref" = "attribute_defs.json#/$defs/string_attribute"
4848
softwareDependencies."$ref" = "attribute_defs.json#/$defs/string_attribute"
4949

5050
meshesPath.description = "Note that the meshesPath is hardcoded as its semantics are impossible to model in a JSON schema."
51-
meshesPath.const.value = "meshes/"
52-
meshesPath.const.datatype = "STRING"
51+
meshesPath.oneOf = [
52+
{ const = { value = "meshes/", datatype = "STRING" } },
53+
{ const = "meshes/" },
54+
]
5355

5456
particlesPath.description = "Note that the particlesPath is hardcoded as its semantics are impossible to model in a JSON schema."
55-
particlesPath.const.value = "particles/"
56-
particlesPath.const.datatype = "STRING"
57+
particlesPath.oneOf = [
58+
{ const = { value = "particles/", datatype = "STRING" } },
59+
{ const = "particles/" },
60+
]
5761

5862
#################################################
5963
# Requirement 1.2: General layout of attributes #

0 commit comments

Comments
 (0)