1
0
mirror of synced 2025-12-31 06:05:12 -05:00
Files
airbyte/airbyte-cdk/python/unit_tests/sources/utils/test_schema_models.py
Cole Snodgrass 2e099acc52 update headers from 2022 -> 2023 (#22594)
* It's 2023!

* 2022 -> 2023

---------

Co-authored-by: evantahler <evan@airbyte.io>
2023-02-08 13:01:16 -08:00

66 lines
1.8 KiB
Python

#
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
#
from typing import List, Optional
from airbyte_cdk.sources.utils.schema_models import AllOptional, BaseSchemaModel
class InnerClass(BaseSchemaModel):
field1: Optional[str]
field2: int
class SchemaWithFewNullables(BaseSchemaModel):
name: Optional[str]
optional_item: Optional[InnerClass]
items: List[InnerClass]
class SchemaWithAllOptional(BaseSchemaModel, metaclass=AllOptional):
object_id: int
item: InnerClass
class TestSchemaWithFewNullables:
EXPECTED_SCHEMA = {
"type": "object",
"properties": {
"name": {"type": ["null", "string"]},
"optional_item": {
"oneOf": [
{"type": "null"},
{"type": "object", "properties": {"field1": {"type": ["null", "string"]}, "field2": {"type": "integer"}}},
]
},
"items": {
"type": "array",
"items": {"type": "object", "properties": {"field1": {"type": ["null", "string"]}, "field2": {"type": "integer"}}},
},
},
}
def test_schema_postprocessing(self):
schema = SchemaWithFewNullables.schema()
assert schema == self.EXPECTED_SCHEMA
class TestSchemaWithAllOptional:
EXPECTED_SCHEMA = {
"type": "object",
"properties": {
"object_id": {"type": ["null", "integer"]},
"item": {
"oneOf": [
{"type": "null"},
{"type": "object", "properties": {"field1": {"type": ["null", "string"]}, "field2": {"type": "integer"}}},
]
},
},
}
def test_schema_postprocessing(self):
schema = SchemaWithAllOptional.schema()
assert schema == self.EXPECTED_SCHEMA