sttp.tapir
Type members
Classlikes
- Type Params
- T
Type of the value of the attribute.
- Value Params
- typeName
The fully qualified name of
T
.
- Companion
- object
An attribute is arbitrary data that is attached to an endpoint or endpoint input/output. The data is not interpreted by tapir's core in any way, but might be used by interpreters.
An attribute is arbitrary data that is attached to an endpoint or endpoint input/output. The data is not interpreted by tapir's core in any way, but might be used by interpreters.
Typically, you'll add attributes using Endpoint.attribute and EndpointTransput.Basic.attribute. The attribute keys should be defined by the interpreters which are using them, and made available for import.
- Companion
- object
A bi-directional mapping between low-level values of type L
and high-level values of type H
. Low level values are formatted as CF
.
A bi-directional mapping between low-level values of type L
and high-level values of type H
. Low level values are formatted as CF
.
The mapping consists of a pair of functions, one to decode (L => H
), and one to encode (H => L
) Decoding can fail, and this is
represented as a result of type DecodeResult.
A codec also contains optional meta-data on the schema
of the high-level value, as well as an instance of the format (which determines
the media type of the low-level value).
Codec instances are used as implicit values, and are looked up when defining endpoint inputs/outputs. Depending on a particular endpoint input/output, it might require a codec which uses a specific format, or a specific low-level value.
Codec instances can be derived basing on other values (e.g. such as json encoders/decoders when integrating with json libraries). Or, they can be defined by hand for custom types, usually customising an existing, simpler codec.
Codecs can be chained with Mapping s using the map
function.
- Type Params
- CF
The format of encoded values. Corresponds to the media type.
- H
The type of the high-level value.
- L
The type of the low-level value.
- Companion
- object
Specifies the format of the encoded values. Each variant must be a proper type so that it can be used as a discriminator for different (implicit) instances of Codec values.
A description of an endpoint with the given inputs & outputs. The inputs are divided into two parts: security (A
) and regular inputs
(I
). There are also two kinds of outputs: error outputs (E
) and regular outputs (O
).
A description of an endpoint with the given inputs & outputs. The inputs are divided into two parts: security (A
) and regular inputs
(I
). There are also two kinds of outputs: error outputs (E
) and regular outputs (O
).
In case there are no security inputs, the PublicEndpoint alias can be used, which omits the A
parameter type.
An endpoint can be interpreted as a server, client or documentation. The endpoint requires that server/client interpreters meet the
capabilities specified by R
(if any).
When interpreting an endpoint as a server, the inputs are decoded and the security logic is run first, before decoding the body in the regular inputs. This allows short-circuiting further processing in case security checks fail. Server logic can be provided using EndpointServerLogicOps.serverSecurityLogic variants for secure endpoints, and EndpointServerLogicOps.serverLogic variants for public endpoints.
A concise description of an endpoint can be generated using the EndpointMetaOps.show method.
- Type Params
- A
Security input parameter types.
- E
Error output parameter types.
- I
Input parameter types.
- O
Output parameter types.
- R
The capabilities that are required by this endpoint's inputs/outputs. This might be
Any
(no requirements), sttp.capabilities.Effect (the interpreter must support the given effect type), sttp.capabilities.Streams (the ability to send and receive streaming bodies) or sttp.capabilities.WebSockets (the ability to handle websocket requests).
A transput is EITHER an input, or an output (see: https://ell.stackexchange.com/questions/21405/hypernym-for-input-and-output). The transput traits contain common functionality, shared by all inputs and outputs.
A transput is EITHER an input, or an output (see: https://ell.stackexchange.com/questions/21405/hypernym-for-input-and-output). The transput traits contain common functionality, shared by all inputs and outputs.
Note that implementations of EndpointIO
can be used BOTH as inputs and outputs.
The hierarchy is as follows:
/---> `EndpointInput` >---\
`EndpointTransput` >--- ---> `EndpointIO`
\---> `EndpointOutput` >---/
- Companion
- object
Lower-priority codec implicits, which transform other codecs. For example, when deriving a codec List[T] <-> Either[A, B]
, given
codecs ca: T <-> A
and cb: T <-> B
, we want to get listHead(eitherRight(ca, cb))
, not eitherRight(listHead(ca), listHead(cb))
(although they would function the same).
Lower-priority codec implicits, which transform other codecs. For example, when deriving a codec List[T] <-> Either[A, B]
, given
codecs ca: T <-> A
and cb: T <-> B
, we want to get listHead(eitherRight(ca, cb))
, not eitherRight(listHead(ca), listHead(cb))
(although they would function the same).
A bi-directional mapping between values of type L
and values of type H
.
A bi-directional mapping between values of type L
and values of type H
.
Low-level values of type L
can be decoded to a higher-level value of type H
. The decoding can fail; this is represented by a
result of type DecodeResult.Failure. Failures might occur due to format errors, wrong arity, exceptions, or validation errors.
Validators can be added through the validate
method.
High-level values of type H
can be encoded as a low-level value of type L
.
Mappings can be chained using one of the map
functions.
- Type Params
- H
The type of the high-level value.
- L
The type of the low-level value.
- Companion
- object
Information needed to handle a multipart body. Individual parts are decoded as described by rawBodyType, which contains codecs for
each part, as well as an optional default codec. The sequence of decoded parts can be further decoded into a high-level T
type using
codec.
Information needed to handle a multipart body. Individual parts are decoded as described by rawBodyType, which contains codecs for
each part, as well as an optional default codec. The sequence of decoded parts can be further decoded into a high-level T
type using
codec.
- Companion
- object
Information needed to read a single part of a multipart body: the raw type (rawBodyType
), and the codec which further decodes it.
Information needed to read a single part of a multipart body: the raw type (rawBodyType
), and the codec which further decodes it.
- Companion
- object
The raw format of the body: what do we need to know, to read it and pass to a codec for further decoding.
The raw format of the body: what do we need to know, to read it and pass to a codec for further decoding.
- Companion
- object
Describes the type T
: its low-level representation, meta-data and validation rules.
Describes the type T
: its low-level representation, meta-data and validation rules.
- Value Params
- format
The name of the format of the low-level representation of
T
.
- Companion
- object
Mixin containing aliases for top-level types and modules in the tapir package.
Mixin containing aliases for top-level types and modules in the tapir package.
Inherited classlikes
Types
Inherited types
Value members
Inherited methods
A body in any format, read using the given codec
, from a raw string read using charset
.
A body in any format, read using the given codec
, from a raw string read using charset
.
- Inherited from
- Tapir
A body in any format, read using the given codec
, from a raw string read using UTF-8.
A body in any format, read using the given codec
, from a raw string read using UTF-8.
- Inherited from
- Tapir
Inputs which describe authentication credentials with metadata.
Inputs which describe authentication credentials with metadata.
- Inherited from
- Tapir
Usage:
Usage:
binaryBody(RawBodyType.FileBody)[MyType]
, given that a codec between a file and MyType
is available in the implicit
scope.
binaryBody(RawBodyType.FileBody)[MyType] }}} scope.
- Inherited from
- Tapir
Requires an implicit Codec.JsonCodec in scope. Such a codec can be created using Codec.json.
Requires an implicit Codec.JsonCodec in scope. Such a codec can be created using Codec.json.
However, json codecs are usually derived from json-library-specific implicits. That's why integrations with various json libraries
define jsonBody
methods, which directly require the library-specific implicits.
Unless you have defined a custom json codec, the jsonBody
methods should be used.
- Inherited from
- Tapir
Extract a value from a server request. This input is only used by server interpreters, it is ignored by documentation interpreters and the provided value is discarded by client interpreters.
Extract a value from a server request. This input is only used by server interpreters, it is ignored by documentation interpreters and the provided value is discarded by client interpreters.
- Inherited from
- Tapir
An output which contains a number of variant outputs.
An output which contains a number of variant outputs.
All possible outputs must have a common supertype (T
). Typically, the supertype is a sealed trait, and the variants are implementing
case classes.
When encoding to a response, the first matching output is chosen, using the following rules:
- the variant's
appliesTo
method, applied to the output value (as returned by the server logic) must returntrue
. - when a fixed content type is specified by the output, it must match the request's
Accept
header (if present). This implements content negotiation.
When decoding from a response, the first output which decodes successfully is chosen.
The outputs might vary in status codes, headers (e.g. different content types), and body implementations. However, for bodies, only replayable ones can be used, and they need to have the same raw representation (e.g. all byte-array-base, or all file-based).
Note that exhaustiveness of the variants (that all subtypes of T
are covered) is not checked.
- Inherited from
- Tapir
Create a fallback variant to be used in oneOf output descriptions. Multiple such variants can be specified, with different body content types.
Create a one-of-variant which uses output
if the class of the provided value (when interpreting as a server) matches the runtime
class of T
. Adds a fixed status-code output with the given value.
Create a one-of-variant which uses output
if the class of the provided value (when interpreting as a server) matches the runtime
class of T
. Adds a fixed status-code output with the given value.
This will fail at compile-time if the type erasure of T
is different from T
, as a runtime check in this situation would give
invalid results. In such cases, use oneOfVariantClassMatcher, oneOfVariantValueMatcher or oneOfVariantFromMatchType
instead.
Should be used in oneOf output descriptions.
- Inherited from
- Tapir
Create a one-of-variant which uses output
if the class of the provided value (when interpreting as a server) matches the runtime
class of T
.
Create a one-of-variant which uses output
if the class of the provided value (when interpreting as a server) matches the runtime
class of T
.
This will fail at compile-time if the type erasure of T
is different from T
, as a runtime check in this situation would give
invalid results. In such cases, use oneOfVariantClassMatcher, oneOfVariantValueMatcher or oneOfVariantFromMatchType
instead.
Should be used in oneOf output descriptions.
- Inherited from
- Tapir
Create a one-of-variant which uses output
i the class of the provided value (when interpreting as a server) matches the given
runtimeClass
. Note that this does not take into account type erasure. Adds a fixed status-code output with the given value.
Create a one-of-variant which uses output
i the class of the provided value (when interpreting as a server) matches the given
runtimeClass
. Note that this does not take into account type erasure. Adds a fixed status-code output with the given value.
Should be used in oneOf output descriptions.
- Inherited from
- Tapir
Create a one-of-variant which uses output
if the class of the provided value (when interpreting as a server) matches the given
runtimeClass
. Note that this does not take into account type erasure.
Create a one-of-variant which uses output
if the provided value exactly matches one of the values provided in the second argument
list. Adds a fixed status-code output with the given value.
Create a one-of-variant which output
if the provided value exactly matches one of the values provided in the second argument list.
Experimental!
Experimental!
Create a one-of-variant which uses output
if the provided value matches the target type, as checked by MatchType. Instances of
MatchType are automatically derived and recursively check that classes of all fields match, to bypass issues caused by type
erasure. Adds a fixed status-code output with the given value.
Should be used in oneOf output descriptions.
- Inherited from
- Tapir
Experimental!
Experimental!
Create a one-of-variant which uses output
if the provided value matches the target type, as checked by MatchType. Instances of
MatchType are automatically derived and recursively check that classes of all fields match, to bypass issues caused by type
erasure.
Should be used in oneOf output descriptions.
- Inherited from
- Tapir
Create a one-of-variant which uses output
if the provided value (when interpreting as a server matches the matcher
predicate. Adds
a fixed status-code output with the given value.
Create a one-of-variant which uses output
if the provided value (when interpreting as a server matches the matcher
predicate.
An output which maps to the status code in the response.
An output which maps to the status code in the response.
- Inherited from
- Tapir
Creates a stream body with a binary schema. The application/octet-stream
media type will be used by default, but can be later
overridden by providing a custom Content-Type
header value.
Creates a stream body with a binary schema. The application/octet-stream
media type will be used by default, but can be later
overridden by providing a custom Content-Type
header value.
- Value Params
- s
A supported streams implementation.
- Inherited from
- Tapir
Creates a stream body with the given schema.
Creates a stream body with the given schema.
- Value Params
- charset
An optional charset of the resulting stream's data, to be used in the content type.
- format
The media type to use by default. Can be later overridden by providing a custom
Content-Type
header.- s
A supported streams implementation.
- schema
Schema of the body. This should be a schema for the "deserialized" stream.
- Inherited from
- Tapir
Creates a stream body with a text schema.
Creates a stream body with a text schema.
- Value Params
- charset
An optional charset of the resulting stream's data, to be used in the content type.
- format
The media type to use by default. Can be later overridden by providing a custom
Content-Type
header.- s
A supported streams implementation.
- Inherited from
- Tapir
- Type Params
- REQ
The type of messages that are sent to the server.
- REQ_CF
The codec format (media type) of messages that are sent to the server.
- RESP
The type of messages that are received from the server.
- RESP_CF
The codec format (media type) of messages that are received from the server.
- Inherited from
- Tapir
- Inherited from
- Tapir
Requires an implicit Codec.XmlCodec in scope. Such a codec can be created using Codec.xml.
Requires an implicit Codec.XmlCodec in scope. Such a codec can be created using Codec.xml.
- Inherited from
- Tapir
Deprecated and Inherited methods
- Deprecated
[Since version 0.18.0]
Use customJsonBody- Inherited from
- Tapir
- Deprecated
[Since version 0.19.0]
- Inherited from
- Tapir
- Deprecated
[Since version 0.19.0]
- Inherited from
- Tapir
- Deprecated
[Since version 0.19.0]
- Inherited from
- Tapir
- Deprecated
[Since version 0.19.0]
- Inherited from
- Tapir
- Deprecated
[Since version 0.19.0]
- Inherited from
- Tapir
- Deprecated
[Since version 0.19.0]
- Inherited from
- Tapir
Inherited fields
An input which matches if the request URI ends with a trailing slash, otherwise the result is a decode failure on the path. Has no effect when used by documentation or client interpreters.
An input which matches if the request URI ends with a trailing slash, otherwise the result is a decode failure on the path. Has no effect when used by documentation or client interpreters.
- Inherited from
- TapirComputedInputs
Implicits
Inherited implicits
- Inherited from
- ModifyMacroSupport
- Inherited from
- ModifyMacroSupport