From 94c9b003bdea58a5ea1f74a9db297b640f443784 Mon Sep 17 00:00:00 2001 From: Yuhao Su Date: Wed, 19 Feb 2025 03:04:01 -0600 Subject: [PATCH] recurrent data type --- src/connector/codec/src/decoder/json/mod.rs | 3 +- .../codec/tests/integration_tests/json.rs | 83 ++++++++++++++----- .../codec/tests/test_data/id_type.json | 11 +++ 3 files changed, 77 insertions(+), 20 deletions(-) diff --git a/src/connector/codec/src/decoder/json/mod.rs b/src/connector/codec/src/decoder/json/mod.rs index 08bac83c9a855..8b4fe4cf4f468 100644 --- a/src/connector/codec/src/decoder/json/mod.rs +++ b/src/connector/codec/src/decoder/json/mod.rs @@ -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; } diff --git a/src/connector/codec/tests/integration_tests/json.rs b/src/connector/codec/tests/integration_tests/json.rs index 2161045cae6f1..32abd1fd640f2 100644 --- a/src/connector/codec/tests/integration_tests/json.rs +++ b/src/connector/codec/tests/integration_tests/json.rs @@ -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": {{ @@ -73,6 +84,9 @@ async fn test_json_schema_parse() { "$ref": "#/definitions/marketArray" }} }} + }}, + "recurrent": {{ + "$ref": "#/definitions/recurrentType" }} }}, "required": [ @@ -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" @@ -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" @@ -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": [ @@ -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); } diff --git a/src/connector/codec/tests/test_data/id_type.json b/src/connector/codec/tests/test_data/id_type.json index 443e0be28a8d1..758e5469f13e0 100644 --- a/src/connector/codec/tests/test_data/id_type.json +++ b/src/connector/codec/tests/test_data/id_type.json @@ -2,6 +2,17 @@ "definitions": { "idType": { "type": "string" + }, + "recurrentType": { + "type": "object", + "properties": { + "id": { + "$ref": "#/definitions/idType" + }, + "next": { + "$ref": "#/definitions/recurrentType" + } + } } } } \ No newline at end of file