Skip to content

Commit

Permalink
recurrent data type
Browse files Browse the repository at this point in the history
  • Loading branch information
yuhao-su committed Feb 19, 2025
1 parent c4ab9d7 commit 94c9b00
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 20 deletions.
3 changes: 2 additions & 1 deletion src/connector/codec/src/decoder/json/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ impl JsonRef {
}
let mut new_used_refs = used_refs.clone();
new_used_refs.push(ref_url_string);

Box::pin(self.deref(&mut schema, &ref_url_no_fragment, &new_used_refs)).await?;

*value = schema;
}

Expand Down
83 changes: 64 additions & 19 deletions src/connector/codec/tests/integration_tests/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@ async fn test_json_schema_parse() {
"type": "string"
}}
}}
}},
"recurrentType": {{
"type": "object",
"properties": {{
"id": {{
"$ref": "file://{test_id_type_file_path}#/definitions/idType"
}},
"next": {{
"$ref": "file://{test_id_type_file_path}#/definitions/recurrentType"
}}
}}
}}
}},
"properties": {{
Expand All @@ -73,6 +84,9 @@ async fn test_json_schema_parse() {
"$ref": "#/definitions/marketArray"
}}
}}
}},
"recurrent": {{
"$ref": "#/definitions/recurrentType"
}}
}},
"required": [
Expand Down Expand Up @@ -108,18 +122,33 @@ async fn test_json_schema_parse() {
},
"marketObj": {
"additionalProperties": {
"__reference__": {},
"type": "string"
},
"type": "object"
},
"recurrentType": {
"properties": {
"id": {
"type": "string"
},
"next": {
"properties": {
"id": {
"type": "string"
},
"next": {}
},
"type": "object"
}
},
"type": "object"
},
"stringType": {
"type": "string"
}
},
"properties": {
"cats": {
"__reference__": {},
"additionalProperties": {
"items": {
"type": "string"
Expand All @@ -129,21 +158,17 @@ async fn test_json_schema_parse() {
"type": "object"
},
"id": {
"__reference__": {},
"type": "string"
},
"meta": {
"properties": {
"active": {
"__reference__": {},
"additionalProperties": {
"__reference__": {},
"type": "string"
},
"type": "object"
},
"tags": {
"__reference__": {},
"additionalProperties": {
"items": {
"type": "string"
Expand All @@ -156,14 +181,27 @@ async fn test_json_schema_parse() {
"type": "object"
},
"name": {
"__reference__": {
"description": "Name of the market subject"
},
"additionalProperties": {
"__reference__": {},
"type": "string"
},
"type": "object"
},
"recurrent": {
"properties": {
"id": {
"type": "string"
},
"next": {
"properties": {
"id": {
"type": "string"
},
"next": {}
},
"type": "object"
}
},
"type": "object"
}
},
"required": [
Expand All @@ -175,15 +213,22 @@ async fn test_json_schema_parse() {
.assert_eq(&serde_json::to_string_pretty(&json_schema.0).unwrap());

expect![[r#"
[
cats(#1): Jsonb,
id(#2): Varchar,
meta(#3): Struct {
active: Jsonb,
tags: Jsonb,
[
cats(#1): Jsonb,
id(#2): Varchar,
meta(#3): Struct {
active: Jsonb,
tags: Jsonb,
},
name(#4): Jsonb,
recurrent(#5): Struct {
id: Varchar,
next: Struct {
id: Varchar,
next: Varchar,
},
name(#4): Jsonb,
]
"#]]
},
]
"#]]
.assert_debug_eq(&column_display);
}
11 changes: 11 additions & 0 deletions src/connector/codec/tests/test_data/id_type.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@
"definitions": {
"idType": {
"type": "string"
},
"recurrentType": {
"type": "object",
"properties": {
"id": {
"$ref": "#/definitions/idType"
},
"next": {
"$ref": "#/definitions/recurrentType"
}
}
}
}
}

0 comments on commit 94c9b00

Please sign in to comment.