Skip to content

flask_restx_marshmallow.parameter ¤

parameters of flask_restx_marshmallow.

Parameters ¤

Parameters(
    *,
    location: Location
    | Literal[
        "query",
        "header",
        "formData",
        "body",
        "cookie",
        "path",
    ]
    | None = None,
    **kwargs: Unpack[SchemaInitKwargs],
)

Bases: Schema

Base Parameters.

Parameters:

Name Type Description Default

location ¤

Location

location of the parameters. Defaults to None.

None

kwargs ¤

dict

other key word arguments.

{}

Base Parameters.

Parameters:

Name Type Description Default

location ¤

Location

location of the parameters. Defaults to None.

None

kwargs ¤

dict

other key word arguments.

{}
Source code in flask_restx_marshmallow/parameter.py
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
def __init__(
    self: Self,
    *,
    location: Location
    | Literal["query", "header", "formData", "body", "cookie", "path"]
    | None = None,
    **kwargs: Unpack["SchemaInitKwargs"],
) -> None:
    """Base Parameters.

    Args:
        location (Location, optional): location of the parameters. Defaults to None.
        kwargs (dict): other key word arguments.
    """
    super().__init__(**kwargs)
    self.location: (
        Location
        | Literal["query", "header", "formData", "body", "cookie", "path"]
        | None
    ) = location
    if location is not None:
        self.default_location = Location(location)
    for field in self.fields.values():
        field.load_only = True
        if location is not None:
            if isinstance(location, str):
                location = self.default_location
            set_location(field, location)

Meta ¤

Meta for Parameters.

__contains__ ¤

__contains__(field: str) -> bool

Whether field in self.fields.

Parameters:

Name Type Description Default

field ¤

str

field name

required

Returns:

Name Type Description
bool bool

whether field in self.fields

Source code in flask_restx_marshmallow/parameter.py
 96
 97
 98
 99
100
101
102
103
104
105
def __contains__(self: Self, field: str) -> bool:
    """Whether field in self.fields.

    Args:
        field (str): field name

    Returns:
        bool: whether field in self.fields
    """
    return field in self.fields

__or__ ¤

Combine two schemas.

Parameters:

Name Type Description Default

other ¤

Self

other schema

required

Returns:

Name Type Description
Self Parameters

combined schema

Source code in flask_restx_marshmallow/parameter.py
157
158
159
160
161
162
163
164
165
166
167
168
def __or__(self, other: "Parameters") -> "Parameters":
    """Combine two schemas.

    Args:
        other (Self): other schema

    Returns:
        Self: combined schema
    """
    return self.from_dict(other.fields, name=other.__class__.__name__)(
        location=other.location,
    )

__setitem__ ¤

__setitem__(key: str, value: Field) -> None

Set item.

Source code in flask_restx_marshmallow/parameter.py
116
117
118
def __setitem__(self: Self, key: str, value: "Field") -> None:
    """Set item."""
    self.fields[key] = value

combine ¤

Combine two schemas.

Parameters:

Name Type Description Default

other ¤

Self

other schema

required

Returns:

Name Type Description
Self Parameters

combined schema

Source code in flask_restx_marshmallow/parameter.py
144
145
146
147
148
149
150
151
152
153
154
155
def combine(self: Self, other: "Parameters") -> "Parameters":
    """Combine two schemas.

    Args:
        other (Self): other schema

    Returns:
        Self: combined schema
    """
    return self.from_dict(other.fields, name=other.__class__.__name__)(
        location=other.location,
    )

copy_body_fields ¤

copy_body_fields() -> Parameters

Return a copy of this schema with only fields that location is body.

Source code in flask_restx_marshmallow/parameter.py
120
121
122
123
124
125
126
127
128
129
130
def copy_body_fields(self: Self) -> "Parameters":
    """Return a copy of this schema with only fields that location is body."""
    return Parameters.from_dict(
        dict(
            filter(
                lambda field: get_location(field[1]) is Location.BODY,
                self.fields.items(),
            ),
        ),
        name=f"{type(self).__name__}Body",
    )(location=Location.BODY)

copy_form_fields ¤

copy_form_fields() -> Parameters

Return a copy of this schema with only fields that location is formdata.

Source code in flask_restx_marshmallow/parameter.py
132
133
134
135
136
137
138
139
140
141
142
def copy_form_fields(self: Self) -> "Parameters":
    """Return a copy of this schema with only fields that location is formdata."""
    return Parameters.from_dict(
        dict(
            filter(
                lambda field: get_location(field[1]) is Location.FORM_DATA,
                self.fields.items(),
            ),
        ),
        name=f"{type(self).__name__}Form",
    )(location=Location.FORM_DATA)

field_locations ¤

field_locations() -> list[FieldLocations]

Get (field_name, location, is_multiple) for each non-body field.

Returns:

Type Description
list[FieldLocations]

list[FieldLocations]: field name, location, is multiple

Source code in flask_restx_marshmallow/parameter.py
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
@cached_property
def field_locations(self: Self) -> list[FieldLocations]:
    """Get (field_name, location, is_multiple) for each non-body field.

    Returns:
        list[FieldLocations]: field name, location, is multiple
    """
    return [
        FieldLocations(
            name,
            location or self.default_location,
            isinstance(field, List | Tuple),
        )
        for name, field in self.fields.items()
        if (location := get_location(field)) is not Location.BODY
    ]

items ¤

items() -> Iterable[tuple[str, dict]]

Make dict.

Yields:

Type Description
Iterable[tuple[str, dict]]

tuple[str, dict]: field name and field dict

Source code in flask_restx_marshmallow/parameter.py
107
108
109
110
111
112
113
114
def items(self: Self) -> "Iterable[tuple[str, dict]]":
    """Make dict.

    Yields:
        tuple[str, dict]: field name and field dict
    """
    for key, value in self.fields.items():
        yield key, value.__dict__

locations ¤

locations() -> set[str]

Get locations.

Returns:

Type Description
set[str]

set[str]: locations

Source code in flask_restx_marshmallow/parameter.py
67
68
69
70
71
72
73
74
75
76
77
@cached_property
def locations(self: Self) -> set[str]:
    """Get locations.

    Returns:
        set[str]: locations
    """
    return {
        get_location(field) or self.default_location
        for field in self.fields.values()
    }