Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changelog/next_release/141.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add XML API schema
2 changes: 1 addition & 1 deletion syncmaster/schemas/v1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
PostgresReadTransferSourceAndTarget,
ReadDBTransfer,
)
from syncmaster.schemas.v1.transfers.file_format import CSV, JSON, Excel, JSONLine
from syncmaster.schemas.v1.transfers.file_format import CSV, JSON, XML, Excel, JSONLine
from syncmaster.schemas.v1.transfers.run import (
CreateRunSchema,
ReadRunSchema,
Expand Down
1 change: 1 addition & 0 deletions syncmaster/schemas/v1/file_formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
JSONLINE_FORMAT = Literal["jsonline"]
JSON_FORMAT = Literal["json"]
EXCEL_FORMAT = Literal["excel"]
XML_FORMAT = Literal["xml"]
16 changes: 11 additions & 5 deletions syncmaster/schemas/v1/transfers/file/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,31 @@

from pydantic import BaseModel, Field, field_validator

from syncmaster.schemas.v1.transfers.file_format import CSV, JSON, Excel, JSONLine
from syncmaster.schemas.v1.transfers.file_format import CSV, JSON, XML, Excel, JSONLine


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


class ReadFileTransferTarget(BaseModel):
directory_path: str
file_format: CSV | JSONLine | Excel = Field(..., discriminator="type") # JSON format is not supported for writing
file_format: CSV | JSONLine | Excel | XML = Field(
...,
discriminator="type",
) # JSON format is not supported for writing
options: dict[str, Any]


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

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

class CreateFileTransferTarget(BaseModel):
directory_path: str
file_format: CSV | JSONLine | Excel = Field(..., discriminator="type") # JSON FORMAT IS NOT SUPPORTED AS A TARGET !
file_format: CSV | JSONLine | Excel | XML = Field(
...,
discriminator="type",
) # JSON FORMAT IS NOT SUPPORTED AS A TARGET !
options: dict[str, Any] = Field(default_factory=dict)

class Config:
Expand Down
7 changes: 7 additions & 0 deletions syncmaster/schemas/v1/transfers/file_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
EXCEL_FORMAT,
JSON_FORMAT,
JSONLINE_FORMAT,
XML_FORMAT,
)


Expand Down Expand Up @@ -38,3 +39,9 @@ class Excel(BaseModel):
type: EXCEL_FORMAT
include_header: bool = False
start_cell: str | None = None


class XML(BaseModel):
type: XML_FORMAT
root_tag: str
row_tag: str
4 changes: 2 additions & 2 deletions tests/test_unit/test_transfers/test_create_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,11 +636,11 @@ async def test_developer_plus_can_not_create_transfer_with_target_format_json(
"context": {
"discriminator": "'type'",
"tag": "json",
"expected_tags": "'csv', 'jsonline', 'excel'",
"expected_tags": "'csv', 'jsonline', 'excel', 'xml'",
},
"input": {"type": "json", "lineSep": "\n", "encoding": "utf-8"},
"location": ["body", "target_params", "s3", "file_format"],
"message": "Input tag 'json' found using 'type' does not match any of the expected tags: 'csv', 'jsonline', 'excel'",
"message": "Input tag 'json' found using 'type' does not match any of the expected tags: 'csv', 'jsonline', 'excel', 'xml'",
"code": "union_tag_invalid",
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@
"some": "option",
},
},
{
"type": "s3",
"directory_path": "/some/xml/path",
"file_format": {
"type": "xml",
"root_tag": "data",
"row_tag": "record",
},
"options": {
"some": "option",
},
},
],
)
async def test_developer_plus_can_create_s3_transfer(
Expand Down Expand Up @@ -127,6 +139,11 @@ async def test_developer_plus_can_create_s3_transfer(
"include_header": True,
"start_cell": "A1",
},
"xml": {
"type": "xml",
"root_tag": "data",
"row_tag": "record",
},
}

for params in (transfer.source_params, transfer.target_params):
Expand Down Expand Up @@ -165,6 +182,15 @@ async def test_developer_plus_can_create_s3_transfer(
"start_cell": "A1",
},
},
{
"type": "hdfs",
"directory_path": "/some/xml/path",
"file_format": {
"type": "xml",
"root_tag": "data",
"row_tag": "record",
},
},
],
)
async def test_developer_plus_can_create_hdfs_transfer(
Expand Down Expand Up @@ -242,6 +268,11 @@ async def test_developer_plus_can_create_hdfs_transfer(
"include_header": True,
"start_cell": "A1",
},
"xml": {
"type": "xml",
"root_tag": "data",
"row_tag": "record",
},
}

for params in (transfer.source_params, transfer.target_params):
Expand Down Expand Up @@ -280,6 +311,15 @@ async def test_developer_plus_can_create_hdfs_transfer(
"include_header": True,
},
},
{
"type": "s3",
"directory_path": "some/path",
"file_format": {
"type": "xml",
"root_tag": "data",
"row_tag": "record",
},
},
],
)
async def test_cannot_create_file_transfer_with_relative_path(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@
},
"options": {},
},
{
"type": "s3",
"directory_path": "/some/xml/path",
"file_format": {
"type": "xml",
"root_tag": "data",
"row_tag": "record",
},
"options": {},
},
],
)
@pytest.mark.parametrize(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@
},
"options": {},
},
{
"type": "s3",
"directory_path": "/some/xml/path",
"file_format": {
"type": "xml",
"root_tag": "data",
"row_tag": "record",
},
"options": {},
},
],
)
@pytest.mark.parametrize(
Expand Down