Skip to main content

Encoding

This class defines the encoding rules for a single property within a request body, specifying how the property should be serialized. It supports configurations for content types, custom headers, and serialization styles, including options for exploding arrays and allowing reserved characters. This model is typically used to describe complex data structures in OpenAPI specifications.

Attributes

AttributeTypeDescription
contentTypestring = nullThe Content-Type for encoding a specific property, such as application/json or image/png.
headersdict = nullA map of headers that provides additional metadata for the specific property being encoded.
stylestring = nullDescribes how the parameter value will be serialized, determining the format of the encoded data.
explodeboolean = nullSpecifies whether arrays and objects should generate separate parameters for each element or property.
allowReservedboolean = nullDetermines whether reserved characters in the parameter value are allowed to be sent without percent-encoding.

Constructor

Signature

def Encoding(
contentType: str | None = None,
headers: dict[str, Union["Header", [Reference](reference.md?sid=fastapi_openapi_models_reference)]]| None = None,
style: str | None = None,
explode: bool | None = None,
allowReserved: bool | None = None
) - > null

Parameters

NameTypeDescription
contentType`strNone` = None
headers`dict[str, Union["Header", Reference]]None` = None
style`strNone` = None
explode`boolNone` = None
allowReserved`boolNone` = None

Methods


contentType()

def contentType() - > string

The Content-Type for encoding a specific property, such as application/json or image/png.

Returns

TypeDescription
stringThe media type string or null if not specified.

headers()

def headers() - > dict

A map of headers relative to the encoding property, allowing for custom header definitions in the response.

Returns

TypeDescription
dictA dictionary mapping header names to Header objects or References.

style()

def style() - > string

Describes how the parameter value will be serialized depending on the type of the parameter value.

Returns

TypeDescription
stringThe serialization style identifier.

explode()

def explode() - > boolean

Determines whether arrays and objects should generate separate parameters for each element or property.

Returns

TypeDescription
booleanTrue if the parameter should be exploded into multiple values.

allowReserved()

def allowReserved() - > boolean

Determines whether the parameter value should allow reserved characters as defined by RFC3986 to be included without percent-encoding.

Returns

TypeDescription
booleanTrue if reserved characters are permitted in the encoded value.