Skip to content

Commit

Permalink
Shorthand attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed Dec 22, 2023
1 parent 5d02f46 commit 12abcdd
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 24 deletions.
86 changes: 69 additions & 17 deletions share/openPMD/json_schema/attribute_defs.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,21 @@
# Vectors of strings #
######################

["$defs".vec_string_attribute]
[["$defs".vec_string_attribute.oneOf]]
title = "Shorthand notation"
anyOf = [
{ type = "string" },
{ type = "array", items = { "type" = "string" } },
]

[["$defs".vec_string_attribute.oneOf]]
title = "Long notation"
type = "object"
required = ["value", "datatype"]

["$defs".vec_string_attribute.properties]
["$defs".vec_string_attribute.oneOf.properties]

value.any_of = [
value.anyOf = [
{ type = "string" },
{ type = "array", items = { "type" = "string" } },
]
Expand All @@ -30,12 +39,21 @@ datatype.enum = [
# Vectors of int #
##################

["$defs".vec_int_attribute]
[["$defs".vec_int_attribute.oneOf]]
title = "Shorthand notation"
anyOf = [
{ type = "integer" },
{ type = "array", items = { "type" = "integer" } },
]

[["$defs".vec_int_attribute.oneOf]]
title = "Long notation"
type = "object"
required = ["value", "datatype"]

["$defs".vec_int_attribute.properties]
["$defs".vec_int_attribute.oneOf.properties]

value.any_of = [
value.anyOf = [
{ type = "integer" },
{ type = "array", items = { "type" = "integer" } },
]
Expand Down Expand Up @@ -63,12 +81,21 @@ datatype.enum = [
# Vectors of float #
####################

["$defs".vec_float_attribute]
[["$defs".vec_float_attribute.oneOf]]
title = "Shorthand notation"
anyOf = [
{ type = "number" },
{ type = "array", items = { "type" = "number" } },
]

[["$defs".vec_float_attribute.oneOf]]
title = "Long notation"
type = "object"
required = ["value", "datatype"]

["$defs".vec_float_attribute.properties]
["$defs".vec_float_attribute.oneOf.properties]

value.any_of = [
value.anyOf = [
{ type = "number" },
{ type = "array", items = { "type" = "number" } },
]
Expand Down Expand Up @@ -112,10 +139,17 @@ datatype.enum = [
# unitDimension attribute #
###########################

["$defs".unitDimension]
[["$defs".unitDimension.oneOf]]
title = "Shorthand notation"
type = "array"
items.type = "number"

[["$defs".unitDimension.oneOf]]
title = "Long notation"
type = "object"
required = ["value", "datatype"]

["$defs".unitDimension.properties]
["$defs".unitDimension.oneOf.properties]

value = { type = "array", items = { type = "number" } }
datatype.const = "ARR_DBL_7"
Expand All @@ -124,10 +158,16 @@ datatype.const = "ARR_DBL_7"
# string attributes #
#####################

["$defs".string_attribute]
[["$defs".string_attribute.oneOf]]
title = "Shorthand notation"
type = "string"

[["$defs".string_attribute.oneOf]]
title = "Long notation"
type = "object"
required = ["value", "datatype"]

["$defs".string_attribute.properties]
["$defs".string_attribute.oneOf.properties]

value.type = "string"
datatype.enum = ["STRING", "CHAR", "SCHAR", "UCHAR"]
Expand All @@ -136,10 +176,16 @@ datatype.enum = ["STRING", "CHAR", "SCHAR", "UCHAR"]
# int attributes #
##################

["$defs".int_attribute]
[["$defs".int_attribute.oneOf]]
title = "Shorthand notation"
type = "integer"

[["$defs".int_attribute.oneOf]]
title = "Long notation"
type = "object"
required = ["value", "datatype"]

["$defs".int_attribute.properties]
["$defs".int_attribute.oneOf.properties]

value.type = "integer"
datatype.enum = [
Expand All @@ -157,10 +203,16 @@ datatype.enum = [
# float attributes #
####################

["$defs".float_attribute]
[["$defs".float_attribute.oneOf]]
title = "Shorthand notation"
type = "number"

[["$defs".float_attribute.oneOf]]
title = "Long notation"
type = "object"
required = ["value", "datatype"]

["$defs".float_attribute.properties]
["$defs".float_attribute.oneOf.properties]

value.type = "number"
datatype.enum = [
Expand Down
21 changes: 18 additions & 3 deletions share/openPMD/json_schema/attributes.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,26 @@ type = "object"
title = "Dictionary of attributes"
description = "Generic layout of an attributes object."

[oneOf.patternProperties.".*"]
title = "A generic attribute"
[[oneOf.patternProperties.".*".oneOf]]
title = "A generic attribute - short form"
anyOf = [
# Any primitive value
{ not = { anyOf = [
{ type = "object", title = "An object" },
{ type = "array", title = "An array" },
] }, title = "No complex type" },
# Or an array of any primitive value
{ type = "array", items = { not = { anyOf = [
{ type = "object", title = "An object" },
{ type = "array", title = "An array" },
] } }, title = "An array of non-complex types" },
]

[[oneOf.patternProperties.".*".oneOf]]
title = "A generic attribute - long form"
type = "object"

[oneOf.patternProperties.".*".properties]
[oneOf.patternProperties.".*".oneOf.properties]

value.anyOf = [
# Any primitive value
Expand Down
12 changes: 8 additions & 4 deletions share/openPMD/json_schema/series.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,16 @@ machine."$ref" = "attribute_defs.json#/$defs/string_attribute"
softwareDependencies."$ref" = "attribute_defs.json#/$defs/string_attribute"

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

particlesPath.description = "Note that the particlesPath is hardcoded as its semantics are impossible to model in a JSON schema."
particlesPath.const.value = "particles/"
particlesPath.const.datatype = "STRING"
particlesPath.oneOf = [
{ const = { value = "particles/", datatype = "STRING" } },
{ const = "particles/" },
]

#################################################
# Requirement 1.2: General layout of attributes #
Expand Down

0 comments on commit 12abcdd

Please sign in to comment.