You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/BHoM_oM/JSONSchema.md
+85Lines changed: 85 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -149,6 +149,91 @@ The initial part of requiring `"_t"` to exist and match one of the types guarant
149
149
}]
150
150
}
151
151
```
152
+
### Enums
153
+
154
+
[C# enums](https://learn.microsoft.com/en-us/dotnet/api/system.enum?view=netstandard-2.0) are generally serialised into strings using the BHoM Serialiser_Engine. This means they can be validated using the [JSON schema enum](https://json-schema.org/understanding-json-schema/reference/enum) keyword.
155
+
156
+
The exception to this rule is when either the enum is serialised as a top level object, or when it is stored in json under a property of a different type, for example [System.Object](https://learn.microsoft.com/en-us/dotnet/api/system.object?view=netstandard-2.0). For this case, the enum is serialised as an object aware of the type, and with the value stored as a property.
157
+
158
+
To handle both these cases BHoM enums are turned into JSON schemas wrapped in an [anyOf](https://json-schema.org/understanding-json-schema/reference/combining#anyOf) keyword.
159
+
160
+
!!! example
161
+
Example below shows the JSON schema for the [Offset](https://bhom.xyz/api/oM/Physical/Physical/Enums/Offset/) enum. The highlighted portions in the tabs below correspond to the two different options for the handling of the enums. The anyOf pattern on line 3 makes it so that any of the two options will validate as correct.
0 commit comments