singer_sdk.typing.ObjectType

class singer_sdk.typing.ObjectType[source]

Object type, which wraps one or more named properties.

__init__(*properties, additional_properties=None, pattern_properties=None, **kwargs)[source]

Initialize ObjectType from its list of properties.

Parameters:
  • properties (Property) – Zero or more attributes for this JSON object.

  • additional_properties (W | type[W] | bool | None) – A schema to match against unnamed properties in this object, or a boolean indicating if extra properties are allowed.

  • pattern_properties (Mapping[str, W | type[W]] | None) – A dictionary of regex patterns to match against property names, and the schema to match against the values.

  • **kwargs (Any) – Additional keyword arguments to pass to the JSONTypeHelper.

Return type:

None

Examples

>>> t = ObjectType(
...     Property("name", StringType, required=True),
...     Property("age", IntegerType),
...     Property("height", NumberType),
...     additional_properties=False,
... )
>>> print(t.to_json(indent=2))
{
  "type": "object",
  "properties": {
    "name": {
      "type": [
        "string"
      ]
    },
    "age": {
      "type": [
        "integer",
        "null"
      ]
    },
    "height": {
      "type": [
        "number",
        "null"
      ]
    }
  },
  "required": [
    "name"
  ],
  "additionalProperties": false
}
>>> t = ObjectType(
...     Property("name", StringType, required=True),
...     Property("age", IntegerType),
...     Property("height", NumberType),
...     additional_properties=StringType,
... )
>>> print(t.to_json(indent=2))
{
  "type": "object",
  "properties": {
    "name": {
      "type": [
        "string"
      ]
    },
    "age": {
      "type": [
        "integer",
        "null"
      ]
    },
    "height": {
      "type": [
        "number",
        "null"
      ]
    }
  },
  "required": [
    "name"
  ],
  "additionalProperties": {
    "type": [
      "string"
    ]
  }
}
property type_dict: dict[source]

Get type dictionary.

Returns:

A dictionary describing the type.