Skip to content

Commit 529aa68

Browse files
author
Ilyas Gasanov
committed
[DOP-21443] Add XML API schema
1 parent 882a1cb commit 529aa68

File tree

9 files changed

+83
-8
lines changed

9 files changed

+83
-8
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add XML API schema

syncmaster/schemas/v1/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
PostgresReadTransferSourceAndTarget,
3737
ReadDBTransfer,
3838
)
39-
from syncmaster.schemas.v1.transfers.file_format import CSV, JSON, Excel, JSONLine
39+
from syncmaster.schemas.v1.transfers.file_format import CSV, JSON, XML, Excel, JSONLine
4040
from syncmaster.schemas.v1.transfers.run import (
4141
CreateRunSchema,
4242
ReadRunSchema,

syncmaster/schemas/v1/file_formats.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
JSONLINE_FORMAT = Literal["jsonline"]
77
JSON_FORMAT = Literal["json"]
88
EXCEL_FORMAT = Literal["excel"]
9+
XML_FORMAT = Literal["xml"]

syncmaster/schemas/v1/transfers/file/base.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,31 @@
77

88
from pydantic import BaseModel, Field, field_validator
99

10-
from syncmaster.schemas.v1.transfers.file_format import CSV, JSON, Excel, JSONLine
10+
from syncmaster.schemas.v1.transfers.file_format import CSV, JSON, XML, Excel, JSONLine
1111

1212

1313
# At the moment the ReadTransferSourceParams and ReadTransferTargetParams
1414
# classes are identical but may change in the future
1515
class ReadFileTransferSource(BaseModel):
1616
directory_path: str
17-
file_format: CSV | JSONLine | JSON | Excel = Field(..., discriminator="type")
17+
file_format: CSV | JSONLine | JSON | Excel | XML = Field(..., discriminator="type")
1818
options: dict[str, Any]
1919

2020

2121
class ReadFileTransferTarget(BaseModel):
2222
directory_path: str
23-
file_format: CSV | JSONLine | Excel = Field(..., discriminator="type") # JSON format is not supported for writing
23+
file_format: CSV | JSONLine | Excel | XML = Field(
24+
...,
25+
discriminator="type",
26+
) # JSON format is not supported for writing
2427
options: dict[str, Any]
2528

2629

2730
# At the moment the CreateTransferSourceParams and CreateTransferTargetParams
2831
# classes are identical but may change in the future
2932
class CreateFileTransferSource(BaseModel):
3033
directory_path: str
31-
file_format: CSV | JSONLine | JSON | Excel = Field(..., discriminator="type")
34+
file_format: CSV | JSONLine | JSON | Excel | XML = Field(..., discriminator="type")
3235
options: dict[str, Any] = Field(default_factory=dict)
3336

3437
class Config:
@@ -44,7 +47,10 @@ def _directory_path_is_valid_path(cls, value):
4447

4548
class CreateFileTransferTarget(BaseModel):
4649
directory_path: str
47-
file_format: CSV | JSONLine | Excel = Field(..., discriminator="type") # JSON FORMAT IS NOT SUPPORTED AS A TARGET !
50+
file_format: CSV | JSONLine | Excel | XML = Field(
51+
...,
52+
discriminator="type",
53+
) # JSON FORMAT IS NOT SUPPORTED AS A TARGET !
4854
options: dict[str, Any] = Field(default_factory=dict)
4955

5056
class Config:

syncmaster/schemas/v1/transfers/file_format.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
EXCEL_FORMAT,
1010
JSON_FORMAT,
1111
JSONLINE_FORMAT,
12+
XML_FORMAT,
1213
)
1314

1415

@@ -38,3 +39,9 @@ class Excel(BaseModel):
3839
type: EXCEL_FORMAT
3940
include_header: bool = False
4041
start_cell: str | None = None
42+
43+
44+
class XML(BaseModel):
45+
type: XML_FORMAT
46+
root_tag: str
47+
row_tag: str

tests/test_unit/test_transfers/test_create_transfer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -636,11 +636,11 @@ async def test_developer_plus_can_not_create_transfer_with_target_format_json(
636636
"context": {
637637
"discriminator": "'type'",
638638
"tag": "json",
639-
"expected_tags": "'csv', 'jsonline', 'excel'",
639+
"expected_tags": "'csv', 'jsonline', 'excel', 'xml'",
640640
},
641641
"input": {"type": "json", "lineSep": "\n", "encoding": "utf-8"},
642642
"location": ["body", "target_params", "s3", "file_format"],
643-
"message": "Input tag 'json' found using 'type' does not match any of the expected tags: 'csv', 'jsonline', 'excel'",
643+
"message": "Input tag 'json' found using 'type' does not match any of the expected tags: 'csv', 'jsonline', 'excel', 'xml'",
644644
"code": "union_tag_invalid",
645645
},
646646
],

tests/test_unit/test_transfers/test_file_transfers/test_create_transfer.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,18 @@
5151
"some": "option",
5252
},
5353
},
54+
{
55+
"type": "s3",
56+
"directory_path": "/some/xml/path",
57+
"file_format": {
58+
"type": "xml",
59+
"root_tag": "data",
60+
"row_tag": "record",
61+
},
62+
"options": {
63+
"some": "option",
64+
},
65+
},
5466
],
5567
)
5668
async def test_developer_plus_can_create_s3_transfer(
@@ -127,6 +139,11 @@ async def test_developer_plus_can_create_s3_transfer(
127139
"include_header": True,
128140
"start_cell": "A1",
129141
},
142+
"xml": {
143+
"type": "xml",
144+
"root_tag": "data",
145+
"row_tag": "record",
146+
},
130147
}
131148

132149
for params in (transfer.source_params, transfer.target_params):
@@ -165,6 +182,15 @@ async def test_developer_plus_can_create_s3_transfer(
165182
"start_cell": "A1",
166183
},
167184
},
185+
{
186+
"type": "hdfs",
187+
"directory_path": "/some/xml/path",
188+
"file_format": {
189+
"type": "xml",
190+
"root_tag": "data",
191+
"row_tag": "record",
192+
},
193+
},
168194
],
169195
)
170196
async def test_developer_plus_can_create_hdfs_transfer(
@@ -242,6 +268,11 @@ async def test_developer_plus_can_create_hdfs_transfer(
242268
"include_header": True,
243269
"start_cell": "A1",
244270
},
271+
"xml": {
272+
"type": "xml",
273+
"root_tag": "data",
274+
"row_tag": "record",
275+
},
245276
}
246277

247278
for params in (transfer.source_params, transfer.target_params):
@@ -280,6 +311,15 @@ async def test_developer_plus_can_create_hdfs_transfer(
280311
"include_header": True,
281312
},
282313
},
314+
{
315+
"type": "s3",
316+
"directory_path": "some/path",
317+
"file_format": {
318+
"type": "xml",
319+
"root_tag": "data",
320+
"row_tag": "record",
321+
},
322+
},
283323
],
284324
)
285325
async def test_cannot_create_file_transfer_with_relative_path(

tests/test_unit/test_transfers/test_file_transfers/test_read_transfer.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@
3333
},
3434
"options": {},
3535
},
36+
{
37+
"type": "s3",
38+
"directory_path": "/some/xml/path",
39+
"file_format": {
40+
"type": "xml",
41+
"root_tag": "data",
42+
"row_tag": "record",
43+
},
44+
"options": {},
45+
},
3646
],
3747
)
3848
@pytest.mark.parametrize(

tests/test_unit/test_transfers/test_file_transfers/test_update_transfer.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@
3333
},
3434
"options": {},
3535
},
36+
{
37+
"type": "s3",
38+
"directory_path": "/some/xml/path",
39+
"file_format": {
40+
"type": "xml",
41+
"root_tag": "data",
42+
"row_tag": "record",
43+
},
44+
"options": {},
45+
},
3646
],
3747
)
3848
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)