Skip to content

Commit 55126d5

Browse files
authored
Integrate jsoncons for robust JSON schema validation (#1274)
* Integrate jsoncons for robust JSON schema validation and refactor catalog structure to use standard $defs. * test: add conformance validation tests for custom catalogs in v0.8 and v0.9 * Move get_reachable_components to A2uiStreamParserImpl and implement schema-based reference field discovery
1 parent 6799864 commit 55126d5

12 files changed

Lines changed: 1179 additions & 585 deletions

File tree

agent_sdks/conformance/suites/validator.yaml

Lines changed: 109 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@
4949
version: "0.9"
5050
common_types_schema: "test_data/simplified_common_types_v09.json"
5151
s2c_schema: "test_data/simplified_s2c_v09.json"
52-
catalog_schema:
53-
catalogId: standard
54-
components: {}
52+
catalog_schema: "test_data/simplified_catalog_v09.json"
5553
action: validate
5654
steps:
5755
- payload:
@@ -1950,9 +1948,7 @@
19501948
version: "0.9"
19511949
common_types_schema: "test_data/simplified_common_types_v09.json"
19521950
s2c_schema: "test_data/simplified_s2c_v09.json"
1953-
catalog_schema:
1954-
catalogId: standard
1955-
components: {}
1951+
catalog_schema: "test_data/simplified_catalog_v09.json"
19561952
action: validate
19571953
payload:
19581954
- version: v0.9
@@ -2653,4 +2649,110 @@
26532649
component:
26542650
Container:
26552651
child: 123
2656-
expect_error: string
2652+
expect_error: "123 is not of type 'string'"
2653+
2654+
- name: test_custom_catalog_validation_success_v09
2655+
description: Tests validation success with a custom catalog in v0.9.
2656+
catalog:
2657+
version: "0.9"
2658+
common_types_schema: "test_data/simplified_common_types_v09.json"
2659+
s2c_schema: "test_data/simplified_s2c_v09.json"
2660+
catalog_schema:
2661+
catalogId: "https://example.com/custom_catalog"
2662+
components:
2663+
Text:
2664+
type: object
2665+
properties:
2666+
component: {const: "Text"}
2667+
text: {type: string}
2668+
required: [component, text]
2669+
$defs:
2670+
anyComponent:
2671+
oneOf:
2672+
- $ref: "#/components/Text"
2673+
discriminator: {propertyName: "component"}
2674+
action: validate
2675+
payload:
2676+
- version: "v0.9"
2677+
updateComponents:
2678+
surfaceId: "s1"
2679+
components:
2680+
- id: "root"
2681+
component: "Text"
2682+
text: "hello"
2683+
2684+
- name: test_custom_catalog_validation_success_v08
2685+
description: Tests validation success with a custom catalog in v0.8.
2686+
catalog:
2687+
version: "0.8"
2688+
s2c_schema: "test_data/simplified_s2c_v08.json"
2689+
catalog_schema:
2690+
catalogId: "custom"
2691+
components:
2692+
Text:
2693+
type: object
2694+
properties:
2695+
text: {type: string}
2696+
action: validate
2697+
payload:
2698+
- surfaceUpdate:
2699+
surfaceId: "s1"
2700+
components:
2701+
- id: "root"
2702+
component:
2703+
Text:
2704+
text: "hello"
2705+
2706+
- name: test_custom_catalog_validation_failure_v08
2707+
description: Tests validation failure with a custom catalog in v0.8.
2708+
catalog:
2709+
version: "0.8"
2710+
s2c_schema: "test_data/simplified_s2c_v08.json"
2711+
catalog_schema:
2712+
catalogId: "custom"
2713+
components:
2714+
Text:
2715+
type: object
2716+
properties:
2717+
text: {type: string}
2718+
action: validate
2719+
payload:
2720+
- surfaceUpdate:
2721+
surfaceId: "s1"
2722+
components:
2723+
- id: "root"
2724+
component:
2725+
Text:
2726+
text: 123
2727+
expect_error: "123 is not of type 'string'"
2728+
2729+
- name: test_custom_catalog_validation_failure_v09
2730+
description: Tests validation failure with a custom catalog in v0.9.
2731+
catalog:
2732+
version: "0.9"
2733+
common_types_schema: "test_data/simplified_common_types_v09.json"
2734+
s2c_schema: "test_data/simplified_s2c_v09.json"
2735+
catalog_schema:
2736+
catalogId: "custom"
2737+
components:
2738+
Text:
2739+
type: object
2740+
properties:
2741+
component: {const: "Text"}
2742+
text: {type: string}
2743+
required: [component, text]
2744+
$defs:
2745+
anyComponent:
2746+
oneOf:
2747+
- $ref: "#/components/Text"
2748+
discriminator: {propertyName: "component"}
2749+
action: validate
2750+
payload:
2751+
- version: "v0.9"
2752+
updateComponents:
2753+
surfaceId: "s1"
2754+
components:
2755+
- id: "root"
2756+
component: "Text"
2757+
text: 123
2758+
expect_error: "123 is not of type 'string'"

agent_sdks/conformance/test_data/simplified_catalog_v09.json

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
{
2+
"$id": "https://a2ui.org/specification/v0_9/catalog.json",
23
"catalogId": "test_catalog",
34
"components": {
45
"Container": {
56
"type": "object",
67
"allOf": [
7-
{ "$ref": "simplified_common_types_v09.json#/$defs/ComponentCommon" },
8+
{ "$ref": "common_types.json#/$defs/ComponentCommon" },
89
{ "$ref": "#/$defs/CatalogComponentCommon" }
910
],
1011
"properties": {
@@ -19,50 +20,50 @@
1920
"Card": {
2021
"type": "object",
2122
"allOf": [
22-
{ "$ref": "simplified_common_types_v09.json#/$defs/ComponentCommon" },
23+
{ "$ref": "common_types.json#/$defs/ComponentCommon" },
2324
{ "$ref": "#/$defs/CatalogComponentCommon" }
2425
],
2526
"properties": {
2627
"component": { "const": "Card" },
27-
"child": { "$ref": "simplified_common_types_v09.json#/$defs/ComponentId" }
28+
"child": { "$ref": "common_types.json#/$defs/ComponentId" }
2829
},
2930
"required": [ "component", "child" ]
3031
},
3132
"Text": {
3233
"type": "object",
3334
"allOf": [
34-
{ "$ref": "simplified_common_types_v09.json#/$defs/ComponentCommon" },
35+
{ "$ref": "common_types.json#/$defs/ComponentCommon" },
3536
{ "$ref": "#/$defs/CatalogComponentCommon" }
3637
],
3738
"properties": {
3839
"component": { "const": "Text" },
39-
"text": { "$ref": "simplified_common_types_v09.json#/$defs/DynamicString" }
40+
"text": { "$ref": "common_types.json#/$defs/DynamicString" }
4041
},
4142
"required": [ "component", "text" ]
4243
},
4344
"Column": {
4445
"type": "object",
4546
"allOf": [
46-
{ "$ref": "simplified_common_types_v09.json#/$defs/ComponentCommon" },
47+
{ "$ref": "common_types.json#/$defs/ComponentCommon" },
4748
{ "$ref": "#/$defs/CatalogComponentCommon" }
4849
],
4950
"properties": {
5051
"component": { "const": "Column" },
51-
"children": { "$ref": "simplified_common_types_v09.json#/$defs/ChildList" }
52+
"children": { "$ref": "common_types.json#/$defs/ChildList" }
5253
},
5354
"required": [ "component", "children" ]
5455
},
5556
"AudioPlayer": {
5657
"type": "object",
5758
"allOf": [
58-
{ "$ref": "simplified_common_types_v09.json#/$defs/ComponentCommon" },
59+
{ "$ref": "common_types.json#/$defs/ComponentCommon" },
5960
{ "$ref": "#/$defs/CatalogComponentCommon" },
6061
{
6162
"type": "object",
6263
"properties": {
6364
"component": { "const": "AudioPlayer" },
64-
"url": { "$ref": "simplified_common_types_v09.json#/$defs/DynamicString" },
65-
"description": { "$ref": "simplified_common_types_v09.json#/$defs/DynamicString" }
65+
"url": { "$ref": "common_types.json#/$defs/DynamicString" },
66+
"description": { "$ref": "common_types.json#/$defs/DynamicString" }
6667
},
6768
"required": [ "component", "url" ]
6869
}
@@ -71,13 +72,13 @@
7172
"List": {
7273
"type": "object",
7374
"allOf": [
74-
{ "$ref": "simplified_common_types_v09.json#/$defs/ComponentCommon" },
75+
{ "$ref": "common_types.json#/$defs/ComponentCommon" },
7576
{ "$ref": "#/$defs/CatalogComponentCommon" },
7677
{
7778
"type": "object",
7879
"properties": {
7980
"component": { "const": "List" },
80-
"children": { "$ref": "simplified_common_types_v09.json#/$defs/ChildList" },
81+
"children": { "$ref": "common_types.json#/$defs/ChildList" },
8182
"direction": {
8283
"type": "string",
8384
"enum": [ "vertical", "horizontal" ]
@@ -90,13 +91,13 @@
9091
"Row": {
9192
"type": "object",
9293
"allOf": [
93-
{ "$ref": "simplified_common_types_v09.json#/$defs/ComponentCommon" },
94+
{ "$ref": "common_types.json#/$defs/ComponentCommon" },
9495
{ "$ref": "#/$defs/CatalogComponentCommon" },
9596
{
9697
"type": "object",
9798
"properties": {
9899
"component": { "const": "Row" },
99-
"children": { "$ref": "simplified_common_types_v09.json#/$defs/ChildList" }
100+
"children": { "$ref": "common_types.json#/$defs/ChildList" }
100101
},
101102
"required": [ "component", "children" ]
102103
}

0 commit comments

Comments
 (0)