From 64029e0863aedefd949d6e15870f309c36e85c97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franz=20P=C3=B6schel?= Date: Mon, 7 Aug 2023 13:19:27 +0200 Subject: [PATCH] Shorthand attributes --- share/openPMD/json_schema/attribute_defs.toml | 86 +++++++++++++++---- share/openPMD/json_schema/attributes.toml | 21 ++++- share/openPMD/json_schema/series.toml | 12 ++- 3 files changed, 95 insertions(+), 24 deletions(-) diff --git a/share/openPMD/json_schema/attribute_defs.toml b/share/openPMD/json_schema/attribute_defs.toml index d8d3d19c0f..70f3b9ec16 100644 --- a/share/openPMD/json_schema/attribute_defs.toml +++ b/share/openPMD/json_schema/attribute_defs.toml @@ -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" } }, ] @@ -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" } }, ] @@ -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" } }, ] @@ -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" @@ -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"] @@ -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 = [ @@ -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 = [ diff --git a/share/openPMD/json_schema/attributes.toml b/share/openPMD/json_schema/attributes.toml index 8137554a91..18cfc36101 100644 --- a/share/openPMD/json_schema/attributes.toml +++ b/share/openPMD/json_schema/attributes.toml @@ -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 diff --git a/share/openPMD/json_schema/series.toml b/share/openPMD/json_schema/series.toml index 46c57c7153..ea5b4b1218 100644 --- a/share/openPMD/json_schema/series.toml +++ b/share/openPMD/json_schema/series.toml @@ -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 #