Skip to content

flask_restx_marshmallow.schema ¤

schemas of flask_restx_marshmallow.

InternalServerErrorSchema ¤

InternalServerErrorSchema(
    header_fields: Iterable[str] | None = None,
    **kwargs: Unpack[SchemaInitKwargs],
)

Bases: Schema

Internal Server Error Schema.

Response schema.

Parameters:

Name Type Description Default

header_fields ¤

Iterable[str] | None

fields in response header

None

kwargs ¤

Unpack[SchemaInitKwargs]

keyword arguments

{}
Source code in flask_restx_marshmallow/schema.py
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
def __init__(
    self: Self,
    header_fields: Iterable[str] | None = None,
    **kwargs: Unpack["SchemaInitKwargs"],
) -> None:
    """Response schema.

    Args:
        header_fields (Iterable[str] | None): fields in response header
        kwargs (Unpack["SchemaInitKwargs"]): keyword arguments
    """
    super().__init__(**kwargs)
    self.header_fields = header_fields
    for name, field_obj in self.fields.items():
        if header_fields and name in header_fields:
            cast("dict", field_obj.metadata)["header"] = True
        else:
            field_obj.dump_only = True

example property ¤

example: dict

Example of response schema.

Meta ¤

Meta for response schema.

copy_body_fields ¤

copy_body_fields() -> Schema

Return a copy of this schema with response body fields.

Source code in flask_restx_marshmallow/schema.py
50
51
52
53
54
55
56
57
58
59
60
61
def copy_body_fields(self: Self) -> "Schema":
    """Return a copy of this schema with response body fields."""
    return Schema.from_dict(
        dict(
            filter(
                lambda field: field[1].metadata.get("header") is not True
                and field[1].metadata.get("simple") is not True,
                self.fields.items(),
            ),
        ),
        name=f"{type(self).__name__}Body",
    )()

copy_header_fields ¤

copy_header_fields() -> Schema

Return a copy of this schema with response header fields.

Source code in flask_restx_marshmallow/schema.py
63
64
65
66
67
68
69
70
71
72
73
def copy_header_fields(self: Self) -> "Schema":
    """Return a copy of this schema with response header fields."""
    return Schema.from_dict(
        dict(
            filter(
                lambda field: field[1].metadata.get("header") is True,
                self.fields.items(),
            ),
        ),
        name=f"{type(self).__name__}Header",
    )()

copy_simple_string_field ¤

copy_simple_string_field() -> String | None

Return a copy of this schema with simple string fields.

Source code in flask_restx_marshmallow/schema.py
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
def copy_simple_string_field(self: Self) -> "String | None":
    """Return a copy of this schema with simple string fields."""
    return cast(
        "String | None",
        deepcopy(
            next(
                filter(
                    lambda field: isinstance(field, String)
                    and field.metadata.get("simple") is True,
                    self.fields.values(),
                ),
                None,
            ),
        ),
    )

Schema ¤

Schema(
    header_fields: Iterable[str] | None = None,
    **kwargs: Unpack[SchemaInitKwargs],
)

Bases: Schema

Response schema.

Response schema.

Parameters:

Name Type Description Default

header_fields ¤

Iterable[str] | None

fields in response header

None

kwargs ¤

Unpack[SchemaInitKwargs]

keyword arguments

{}
Source code in flask_restx_marshmallow/schema.py
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
def __init__(
    self: Self,
    header_fields: Iterable[str] | None = None,
    **kwargs: Unpack["SchemaInitKwargs"],
) -> None:
    """Response schema.

    Args:
        header_fields (Iterable[str] | None): fields in response header
        kwargs (Unpack["SchemaInitKwargs"]): keyword arguments
    """
    super().__init__(**kwargs)
    self.header_fields = header_fields
    for name, field_obj in self.fields.items():
        if header_fields and name in header_fields:
            cast("dict", field_obj.metadata)["header"] = True
        else:
            field_obj.dump_only = True

example property ¤

example: dict

Example of response schema.

Meta ¤

Meta for response schema.

copy_body_fields ¤

copy_body_fields() -> Schema

Return a copy of this schema with response body fields.

Source code in flask_restx_marshmallow/schema.py
50
51
52
53
54
55
56
57
58
59
60
61
def copy_body_fields(self: Self) -> "Schema":
    """Return a copy of this schema with response body fields."""
    return Schema.from_dict(
        dict(
            filter(
                lambda field: field[1].metadata.get("header") is not True
                and field[1].metadata.get("simple") is not True,
                self.fields.items(),
            ),
        ),
        name=f"{type(self).__name__}Body",
    )()

copy_header_fields ¤

copy_header_fields() -> Schema

Return a copy of this schema with response header fields.

Source code in flask_restx_marshmallow/schema.py
63
64
65
66
67
68
69
70
71
72
73
def copy_header_fields(self: Self) -> "Schema":
    """Return a copy of this schema with response header fields."""
    return Schema.from_dict(
        dict(
            filter(
                lambda field: field[1].metadata.get("header") is True,
                self.fields.items(),
            ),
        ),
        name=f"{type(self).__name__}Header",
    )()

copy_simple_string_field ¤

copy_simple_string_field() -> String | None

Return a copy of this schema with simple string fields.

Source code in flask_restx_marshmallow/schema.py
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
def copy_simple_string_field(self: Self) -> "String | None":
    """Return a copy of this schema with simple string fields."""
    return cast(
        "String | None",
        deepcopy(
            next(
                filter(
                    lambda field: isinstance(field, String)
                    and field.metadata.get("simple") is True,
                    self.fields.values(),
                ),
                None,
            ),
        ),
    )

UnprocessableEntitySchema ¤

UnprocessableEntitySchema(
    header_fields: Iterable[str] | None = None,
    **kwargs: Unpack[SchemaInitKwargs],
)

Bases: Schema

Unprocessable Entity Schema.

Response schema.

Parameters:

Name Type Description Default

header_fields ¤

Iterable[str] | None

fields in response header

None

kwargs ¤

Unpack[SchemaInitKwargs]

keyword arguments

{}
Source code in flask_restx_marshmallow/schema.py
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
def __init__(
    self: Self,
    header_fields: Iterable[str] | None = None,
    **kwargs: Unpack["SchemaInitKwargs"],
) -> None:
    """Response schema.

    Args:
        header_fields (Iterable[str] | None): fields in response header
        kwargs (Unpack["SchemaInitKwargs"]): keyword arguments
    """
    super().__init__(**kwargs)
    self.header_fields = header_fields
    for name, field_obj in self.fields.items():
        if header_fields and name in header_fields:
            cast("dict", field_obj.metadata)["header"] = True
        else:
            field_obj.dump_only = True

example property ¤

example: dict

Example of response schema.

Meta ¤

Meta for response schema.

copy_body_fields ¤

copy_body_fields() -> Schema

Return a copy of this schema with response body fields.

Source code in flask_restx_marshmallow/schema.py
50
51
52
53
54
55
56
57
58
59
60
61
def copy_body_fields(self: Self) -> "Schema":
    """Return a copy of this schema with response body fields."""
    return Schema.from_dict(
        dict(
            filter(
                lambda field: field[1].metadata.get("header") is not True
                and field[1].metadata.get("simple") is not True,
                self.fields.items(),
            ),
        ),
        name=f"{type(self).__name__}Body",
    )()

copy_header_fields ¤

copy_header_fields() -> Schema

Return a copy of this schema with response header fields.

Source code in flask_restx_marshmallow/schema.py
63
64
65
66
67
68
69
70
71
72
73
def copy_header_fields(self: Self) -> "Schema":
    """Return a copy of this schema with response header fields."""
    return Schema.from_dict(
        dict(
            filter(
                lambda field: field[1].metadata.get("header") is True,
                self.fields.items(),
            ),
        ),
        name=f"{type(self).__name__}Header",
    )()

copy_simple_string_field ¤

copy_simple_string_field() -> String | None

Return a copy of this schema with simple string fields.

Source code in flask_restx_marshmallow/schema.py
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
def copy_simple_string_field(self: Self) -> "String | None":
    """Return a copy of this schema with simple string fields."""
    return cast(
        "String | None",
        deepcopy(
            next(
                filter(
                    lambda field: isinstance(field, String)
                    and field.metadata.get("simple") is True,
                    self.fields.values(),
                ),
                None,
            ),
        ),
    )