jspg union fixes

This commit is contained in:
2025-10-07 20:43:23 -04:00
parent 9ddc899411
commit 44cde90c3d
3 changed files with 250 additions and 2 deletions

View File

@ -906,5 +906,106 @@ pub fn type_matching_schemas() -> JsonB {
"required": ["root_job", "nested_or_super_job"]
}]
}]);
cache_json_schemas(jsonb(enums), jsonb(types), jsonb(puncs))
}
pub fn union_schemas() -> JsonB {
let enums = json!([]);
let types = json!([
{
"name": "union_a",
"schemas": [{
"$id": "union_a",
"type": "object",
"properties": {
"type": { "const": "union_a" },
"prop_a": { "type": "string" }
},
"required": ["type", "prop_a"]
}]
},
{
"name": "union_b",
"schemas": [{
"$id": "union_b",
"type": "object",
"properties": {
"type": { "const": "union_b" },
"prop_b": { "type": "number" }
},
"required": ["type", "prop_b"]
}]
},
{
"name": "union_c",
"schemas": [{
"$id": "union_c",
"type": "object",
"properties": {
"type": { "const": "union_c" },
"prop_c": { "type": "boolean" }
},
"required": ["type", "prop_c"]
}]
}
]);
let puncs = json!([{
"name": "union_test",
"public": false,
"schemas": [{
"$id": "union_test.request",
"type": "object",
"properties": {
"union_prop": {
"oneOf": [
{ "$ref": "union_a" },
{ "$ref": "union_b" },
{ "$ref": "union_c" }
]
}
},
"required": ["union_prop"]
}]
}]);
cache_json_schemas(jsonb(enums), jsonb(types), jsonb(puncs))
}
pub fn nullable_union_schemas() -> JsonB {
let enums = json!([]);
let types = json!([
{
"name": "thing_a",
"schemas": [{
"$id": "thing_a",
"type": "object",
"properties": {
"type": { "const": "thing_a" },
"prop_a": { "type": "string" }
},
"required": ["type", "prop_a"]
}]
}
]);
let puncs = json!([{
"name": "nullable_union_test",
"public": false,
"schemas": [{
"$id": "nullable_union_test.request",
"type": "object",
"properties": {
"nullable_prop": {
"oneOf": [
{ "$ref": "thing_a" },
{ "type": "null" }
]
}
},
"required": ["nullable_prop"]
}]
}]);
cache_json_schemas(jsonb(enums), jsonb(types), jsonb(puncs))
}