airbyte_cdk.utils.oneof_option_config

 1#
 2# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
 3#
 4
 5from typing import Any, Dict
 6
 7
 8class OneOfOptionConfig:
 9    """
10    Base class to configure a Pydantic model that's used as a oneOf option in a parent model in a way that's compatible with all Airbyte consumers.
11
12    Inherit from this class in the nested Config class in a model and set title and description (these show up in the UI) and discriminator (this is making sure it's marked as required in the schema).
13
14    Usage:
15
16        ```python
17        class OptionModel(BaseModel):
18            mode: Literal["option_a"] = Field("option_a", const=True)
19            option_a_field: str = Field(...)
20
21            class Config(OneOfOptionConfig):
22                title = "Option A"
23                description = "Option A description"
24                discriminator = "mode"
25        ```
26    """
27
28    @staticmethod
29    def schema_extra(schema: Dict[str, Any], model: Any) -> None:
30        if hasattr(model.Config, "description"):
31            schema["description"] = model.Config.description
32        if hasattr(model.Config, "discriminator"):
33            schema.setdefault("required", []).append(model.Config.discriminator)
class OneOfOptionConfig:
 9class OneOfOptionConfig:
10    """
11    Base class to configure a Pydantic model that's used as a oneOf option in a parent model in a way that's compatible with all Airbyte consumers.
12
13    Inherit from this class in the nested Config class in a model and set title and description (these show up in the UI) and discriminator (this is making sure it's marked as required in the schema).
14
15    Usage:
16
17        ```python
18        class OptionModel(BaseModel):
19            mode: Literal["option_a"] = Field("option_a", const=True)
20            option_a_field: str = Field(...)
21
22            class Config(OneOfOptionConfig):
23                title = "Option A"
24                description = "Option A description"
25                discriminator = "mode"
26        ```
27    """
28
29    @staticmethod
30    def schema_extra(schema: Dict[str, Any], model: Any) -> None:
31        if hasattr(model.Config, "description"):
32            schema["description"] = model.Config.description
33        if hasattr(model.Config, "discriminator"):
34            schema.setdefault("required", []).append(model.Config.discriminator)

Base class to configure a Pydantic model that's used as a oneOf option in a parent model in a way that's compatible with all Airbyte consumers.

Inherit from this class in the nested Config class in a model and set title and description (these show up in the UI) and discriminator (this is making sure it's marked as required in the schema).

Usage:
class OptionModel(BaseModel):
    mode: Literal["option_a"] = Field("option_a", const=True)
    option_a_field: str = Field(...)

    class Config(OneOfOptionConfig):
        title = "Option A"
        description = "Option A description"
        discriminator = "mode"
@staticmethod
def schema_extra(schema: Dict[str, Any], model: Any) -> None:
29    @staticmethod
30    def schema_extra(schema: Dict[str, Any], model: Any) -> None:
31        if hasattr(model.Config, "description"):
32            schema["description"] = model.Config.description
33        if hasattr(model.Config, "discriminator"):
34            schema.setdefault("required", []).append(model.Config.discriminator)