Codec

sttp.tapir.Codec$
See theCodec companion trait

Attributes

Companion:
trait
Graph
Supertypes
class Object
trait Matchable
class Any
Self type
Codec.type

Members list

Concise view

Type members

Types

type JsonCodec[T] = Codec[String, T, Json]
type PlainCodec[T] = Codec[String, T, TextPlain]
type XmlCodec[T] = Codec[String, T, Xml]

Value members

Concrete methods

def anyString[T : Schema, CF <: CodecFormat](cf: CF)(_rawDecode: String => DecodeResult[T])(_encode: T => String): Codec[String, T, CF]
def formMap(charset: Charset): Codec[String, Map[String, String], XWwwFormUrlencoded]
def formSeq(charset: Charset): Codec[String, Seq[(String, String)], XWwwFormUrlencoded]
def fromDecodeAndMeta[L, H : Schema, CF <: CodecFormat](cf: CF)(f: L => DecodeResult[H])(g: H => L): Codec[L, H, CF]
def id[L, CF <: CodecFormat](f: CF, s: Schema[L]): Codec[L, L, CF]
def idPlain[L](s: Schema[L]): Codec[L, L, TextPlain]
def json[T : Schema](_rawDecode: String => DecodeResult[T])(_encode: T => String): JsonCodec[T]
def multipart(partCodecs: Map[String, PartCodec[_, _]], defaultPartCodec: Option[PartCodec[_, _]]): MultipartCodec[ListMap[String, _]]

Attributes

defaultPartCodec

Default codec to use for parts which are not defined in partCodecs. None, if extra parts should be discarded.

partCodecs

For each supported part, a (raw body type, codec) pair which encodes the part value into a raw value of the given type. A single part value might be encoded as multiple (or none) raw values.

def parsedString[T : Schema](parse: String => T): Codec[String, T, TextPlain]
def rawPart(partCodecs: Map[String, PartCodec[_, _]], defaultCodec: Option[PartCodec[_, _]]): Codec[Seq[RawPart], ListMap[String, _], MultipartFormData]
def xml[T : Schema](_rawDecode: String => DecodeResult[T])(_encode: T => String): XmlCodec[T]

Inherited methods

Creates a codec for an enumeration, where the validator is derived using sttp.tapir.Validator.derivedEnumeration. This requires that all subtypes of the sealed hierarchy T must be objects.

Creates a codec for an enumeration, where the validator is derived using sttp.tapir.Validator.derivedEnumeration. This requires that all subtypes of the sealed hierarchy T must be objects.

This method cannot be implicit, as there's no way to constraint the type T to be a sealed trait / class enumeration, so that this would be invoked only when necessary.

Attributes

L

The type of the low-level representation of the enum, typically a String or an Int.

T

The type of the enum.

Inherited from:
CodecMacros

Creates a codec for an Enumeration, where the validator is created using the enumeration's values. Unlike the default derivedEnumerationValue method, which provides the schema implicitly, this variant allows customising how the codec is created. This is useful if the low-level representation of the schema is different than a String, or if the enumeration's values should be encoded in a different way than using .toString.

Creates a codec for an Enumeration, where the validator is created using the enumeration's values. Unlike the default derivedEnumerationValue method, which provides the schema implicitly, this variant allows customising how the codec is created. This is useful if the low-level representation of the schema is different than a String, or if the enumeration's values should be encoded in a different way than using .toString.

Because of technical limitations of macros, the customisation arguments can't be given here directly, instead being delegated to CreateDerivedEnumerationSchema.

Attributes

L

The type of the low-level representation of the enum, typically a String or an Int.

T

The type of the enum.

Inherited from:
CodecMacros
def eitherLeft[L, A, B, CF <: CodecFormat](c1: Codec[L, A, CF], c2: Codec[L, B, CF]): Codec[L, Either[A, B], CF]

Create a codec which during decoding, first tries to decode values on the left using c1. If this fails for any reason, decoding is done using c2. Both codecs must have the same low-level values and formats.

Create a codec which during decoding, first tries to decode values on the left using c1. If this fails for any reason, decoding is done using c2. Both codecs must have the same low-level values and formats.

For a right-biased variant see Codec.eitherRight.

The schema is defined to be an either schema as created by Schema.schemaForEither.

Attributes

Inherited from:
LowPriorityCodec

Givens

Inherited givens

inline given formCaseClassCodec[T](using inline c: Configuration): Codec[String, T, XWwwFormUrlencoded]

Attributes

Inherited from:
FormCodecMacros

Implicits

Implicits

implicit val bigDecimal: Codec[String, BigDecimal, TextPlain]
implicit val bigInt: Codec[String, BigInt, TextPlain]
implicit def binaryOrCloseWebSocketFrame[A, CF <: CodecFormat](implicit byteArrayCodec: Codec[Array[Byte], A, CF]): Codec[WebSocketFrame, Option[A], CF]

A codec which expects only binary and close frames (all other frames cause a decoding error). Close frames correspond to None, while text frames are handled using the given byteArrayCodec and wrapped with Some.

A codec which expects only binary and close frames (all other frames cause a decoding error). Close frames correspond to None, while text frames are handled using the given byteArrayCodec and wrapped with Some.

Attributes

implicit def binaryWebSocketFrame[A, CF <: CodecFormat](implicit byteArrayCodec: Codec[Array[Byte], A, CF]): Codec[WebSocketFrame, A, CF]

A codec which expects only binary frames (all other frames cause a decoding error) and handles the text using the given byteArrayCodec.

A codec which expects only binary frames (all other frames cause a decoding error) and handles the text using the given byteArrayCodec.

Attributes

implicit val boolean: Codec[String, Boolean, TextPlain]
implicit val byte: Codec[String, Byte, TextPlain]
implicit val byteArray: Codec[Array[Byte], Array[Byte], OctetStream]
implicit val byteBuffer: Codec[ByteBuffer, ByteBuffer, OctetStream]
implicit val cacheDirective: Codec[String, List[CacheDirective], TextPlain]
implicit val cookieWithMeta: Codec[String, CookieWithMeta, TextPlain]
implicit val cookies: Codec[List[String], List[Cookie], TextPlain]
implicit val cookiesWithMeta: Codec[List[String], List[CookieWithMeta], TextPlain]
implicit val date: Codec[String, Date, TextPlain]
implicit val double: Codec[String, Double, TextPlain]
implicit val duration: Codec[String, Duration, TextPlain]
implicit val etag: Codec[String, ETag, TextPlain]
implicit val float: Codec[String, Float, TextPlain]
implicit val formMapUtf8: Codec[String, Map[String, String], XWwwFormUrlencoded]
implicit val formSeqUtf8: Codec[String, Seq[(String, String)], XWwwFormUrlencoded]
implicit val inputStream: Codec[InputStream, InputStream, OctetStream]
implicit val instant: Codec[String, Instant, TextPlain]
implicit val int: Codec[String, Int, TextPlain]
implicit val javaBigDecimal: Codec[String, BigDecimal, TextPlain]
implicit val javaBigInteger: Codec[String, BigInteger, TextPlain]
implicit def list[T, U, CF <: CodecFormat](implicit c: Codec[T, U, CF]): Codec[List[T], List[U], CF]

Create a codec which decodes/encodes a list of low-level values to a list of high-level values, using the given base codec c.

Create a codec which decodes/encodes a list of low-level values to a list of high-level values, using the given base codec c.

The schema is copied from the base codec.

Attributes

implicit def listHead[T, U, CF <: CodecFormat](implicit c: Codec[T, U, CF]): Codec[List[T], U, CF]

Create a codec which requires that a list of low-level values contains a single element. Otherwise a decode failure is returned. The given base codec c is used for decoding/encoding.

Create a codec which requires that a list of low-level values contains a single element. Otherwise a decode failure is returned. The given base codec c is used for decoding/encoding.

The schema and validator are copied from the base codec.

Attributes

implicit def listHeadOption[T, U, CF <: CodecFormat](implicit c: Codec[T, U, CF]): Codec[List[T], Option[U], CF]

Create a codec which requires that a list of low-level values is empty or contains a single element. If it contains multiple elements, a decode failure is returned. The given base codec c is used for decoding/encoding.

Create a codec which requires that a list of low-level values is empty or contains a single element. If it contains multiple elements, a decode failure is returned. The given base codec c is used for decoding/encoding.

The schema and validator are copied from the base codec.

Attributes

implicit val localDate: Codec[String, LocalDate, TextPlain]
implicit val localDateTime: Codec[String, LocalDateTime, TextPlain]
implicit val localTime: Codec[String, LocalTime, TextPlain]
implicit val long: Codec[String, Long, TextPlain]
implicit val mediaType: Codec[String, MediaType, TextPlain]
implicit val offsetDateTime: Codec[String, OffsetDateTime, TextPlain]
implicit val offsetTime: Codec[String, OffsetTime, TextPlain]
implicit def option[T, U, CF <: CodecFormat](implicit c: Codec[T, U, CF]): Codec[Option[T], Option[U], CF]

Create a codec which decodes/encodes an optional low-level value to an optional high-level value. The given base codec c is used for decoding/encoding.

Create a codec which decodes/encodes an optional low-level value to an optional high-level value. The given base codec c is used for decoding/encoding.

The schema and validator are copied from the base codec.

Attributes

implicit def optionHead[T, U, CF <: CodecFormat](implicit c: Codec[T, U, CF]): Codec[Option[T], U, CF]

Create a codec which requires that an optional low-level value is defined. If it is None, a decode failure is returned. The given base codec c is used for decoding/encoding.

Create a codec which requires that an optional low-level value is defined. If it is None, a decode failure is returned. The given base codec c is used for decoding/encoding.

The schema and validator are copied from the base codec.

Attributes

implicit def part[T, U, CF <: CodecFormat](implicit c: Codec[T, U, CF]): Codec[Part[T], Part[U], CF]
implicit val range: Codec[String, Range, TextPlain]
implicit val scalaDuration: Codec[String, Duration, TextPlain]
implicit def set[T, U, CF <: CodecFormat](implicit c: Codec[T, U, CF]): Codec[List[T], Set[U], CF]

Create a codec which decodes/encodes a list of low-level values to a set of high-level values, using the given base codec c.

Create a codec which decodes/encodes a list of low-level values to a set of high-level values, using the given base codec c.

The schema is copied from the base codec.

Attributes

implicit val short: Codec[String, Short, TextPlain]
implicit val string: Codec[String, String, TextPlain]
implicit def textOrCloseWebSocketFrame[A, CF <: CodecFormat](implicit stringCodec: Codec[String, A, CF]): Codec[WebSocketFrame, Option[A], CF]

A codec which expects only text and close frames (all other frames cause a decoding error). Close frames correspond to None, while text frames are handled using the given stringCodec and wrapped with Some.

A codec which expects only text and close frames (all other frames cause a decoding error). Close frames correspond to None, while text frames are handled using the given stringCodec and wrapped with Some.

Attributes

implicit def textWebSocketFrame[A, CF <: CodecFormat](implicit stringCodec: Codec[String, A, CF]): Codec[WebSocketFrame, A, CF]

A codec which expects only text frames (all other frames cause a decoding error) and handles the text using the given stringCodec.

A codec which expects only text frames (all other frames cause a decoding error) and handles the text using the given stringCodec.

Attributes

implicit def tupledWithRaw[L, H, CF <: CodecFormat](implicit codec: Codec[L, H, CF]): Codec[L, (L, H), CF]
implicit def unwrapPart[T, U, CF <: CodecFormat](implicit c: Codec[T, U, CF]): Codec[Part[T], U, CF]
implicit val uri: PlainCodec[Uri]
implicit val uuid: Codec[String, UUID, TextPlain]
implicit def vector[T, U, CF <: CodecFormat](implicit c: Codec[T, U, CF]): Codec[List[T], Vector[U], CF]

Create a codec which decodes/encodes a list of low-level values to a vector of high-level values, using the given base codec c.

Create a codec which decodes/encodes a list of low-level values to a vector of high-level values, using the given base codec c.

The schema and validator are copied from the base codec.

Attributes

implicit val webSocketFrame: Codec[WebSocketFrame, WebSocketFrame, TextPlain]
implicit val zoneOffset: Codec[String, ZoneOffset, TextPlain]
implicit val zonedDateTime: Codec[String, ZonedDateTime, TextPlain]

Inherited implicits

implicit def delimited[D <: String, T](implicit codec: Codec[String, T, TextPlain], delimiter: ValueOf[D]): Codec[String, Delimited[D, T], TextPlain]

Creates a codec which handles values delimited using D. The implicit T-codec is used for handling each individual value.

Creates a codec which handles values delimited using D. The implicit T-codec is used for handling each individual value.

Upon decoding, the string is split using the delimiter, and then decoded using the T-codec. Upon encoding, the values are first encoded using the T-codec, and then combined using the delimiter.

The codec's schema has the explode attribute set to false.

Attributes

Inherited from:
CodecExtensions2
implicit inline def derivedEnumerationValue[T <: Value]: Codec[String, T, TextPlain]

A default codec for enumerations, which returns a string-based enumeration codec, using the enum's .toString to encode values, and performing a case-insensitive search through the possible values, converted to strings using .toString.

A default codec for enumerations, which returns a string-based enumeration codec, using the enum's .toString to encode values, and performing a case-insensitive search through the possible values, converted to strings using .toString.

To customise the enum encoding/decoding functions, provide a custom implicit created using derivedEnumerationValueCustomise.

Attributes

Inherited from:
CodecMacros
implicit inline def derivedValueClass[T <: AnyVal]: Codec[String, T, TextPlain]

Creates a codec for value class based on codecs defined in Codec companion

Creates a codec for value class based on codecs defined in Codec companion

Attributes

Inherited from:
CodecMacros
implicit def eitherRight[L, A, B, CF <: CodecFormat](implicit c1: Codec[L, A, CF], c2: Codec[L, B, CF]): Codec[L, Either[A, B], CF]

Create a codec which during decoding, first tries to decode values on the right using c2. If this fails for any reason, decoding is done using c1. Both codecs must have the same low-level values and formats.

Create a codec which during decoding, first tries to decode values on the right using c2. If this fails for any reason, decoding is done using c1. Both codecs must have the same low-level values and formats.

For a left-biased variant see Codec.eitherLeft. This right-biased version is the default when using implicit codec resolution.

The schema is defined to be an either schema as created by Schema.schemaForEither.

Attributes

Inherited from:
LowPriorityCodec
implicit lazy val path: Codec[FileRange, Path, OctetStream]

Attributes

Inherited from:
CodecExtensions