offstage/dynamic/serialize
Types
A decoder for a specific type t that knows how to parse a dynamic value
and contains the openapi specification of that type.
pub type Decoder(t) {
Decoder(
decoder: decode.Decoder(t),
doc: fn() -> openapi_type.OpenAPIType,
)
}
Constructors
-
Decoder( decoder: decode.Decoder(t), doc: fn() -> openapi_type.OpenAPIType, )
An encoder for a specific type t that knows how to encode a value into a
dynamic spec and contains the openapi specification of that type.
pub type Encoder(t) {
Encoder(
encoder: fn(t) -> spec.Spec,
doc: fn() -> openapi_type.OpenAPIType,
)
}
Constructors
-
Encoder( encoder: fn(t) -> spec.Spec, doc: fn() -> openapi_type.OpenAPIType, )
A serializer that allows encoding and decoding values
pub type Serializer(t) {
Serializer(
decoder: decode.Decoder(t),
encoder: fn(t) -> spec.Spec,
doc: fn() -> openapi_type.OpenAPIType,
)
}
Constructors
-
Serializer( decoder: decode.Decoder(t), encoder: fn(t) -> spec.Spec, doc: fn() -> openapi_type.OpenAPIType, )
Values
pub fn bool() -> Serializer(Bool)
pub fn build(
context: Context(t),
value: t,
) -> decode.Decoder(#(Context(t), t))
pub fn decode(
value: dynamic.Dynamic,
serializer: Serializer(t),
) -> Result(t, List(decode.DecodeError))
pub fn decoder(serializer: Serializer(t)) -> Decoder(t)
pub fn empty_object() -> Serializer(Nil)
pub fn encode(
value: t,
of serializer: Serializer(t),
) -> spec.Spec
pub fn encode_json(
a: a,
of serializer: Serializer(a),
) -> json.Json
Directly encode a value using the given serializer to JSON.
pub fn encode_yaml(
a: a,
of serializer: Serializer(a),
) -> value.YamlValue
Directly encode a value using the given serializer to JSON.
pub fn encoder(serializer: Serializer(t)) -> Encoder(t)
pub fn field(
context context: Context(final),
name name: String,
serializer serializer: Serializer(t),
getter getter: fn(final) -> t,
next next: fn(Context(final), t) -> decode.Decoder(
#(Context(final), final),
),
) -> decode.Decoder(#(Context(final), final))
pub fn float() -> Serializer(Float)
pub fn indexed_field(
context context: Context(final),
name name: String,
count count: Int,
serializer serializer: Serializer(t),
getter getter: fn(final, Int) -> t,
next next: fn(Context(final), List(t)) -> decode.Decoder(
#(Context(final), final),
),
) -> decode.Decoder(#(Context(final), final))
pub fn int() -> Serializer(Int)
pub fn json_value() -> Serializer(json_value.JsonValue)
pub fn list(of inner: Serializer(t)) -> Serializer(List(t))
pub fn object(
next: fn(Context(t)) -> decode.Decoder(#(Context(t), t)),
) -> Serializer(t)
pub fn optional(
of inner: Serializer(t),
) -> Serializer(option.Option(t))
pub fn optional_decoder(
of inner: Decoder(t),
) -> Decoder(option.Option(t))
pub fn optional_encoder(
of inner: Encoder(t),
) -> Encoder(option.Option(t))
pub fn optional_field(
context context: Context(final),
name name: String,
default default: t,
serializer serializer: Serializer(t),
getter getter: fn(final) -> t,
next next: fn(Context(final), t) -> decode.Decoder(
#(Context(final), final),
),
) -> decode.Decoder(#(Context(final), final))
pub fn optional_indexed_field(
context context: Context(final),
name name: String,
count count: Int,
default default: t,
serializer serializer: Serializer(t),
getter getter: fn(final, Int) -> t,
next next: fn(Context(final), List(t)) -> decode.Decoder(
#(Context(final), final),
),
) -> decode.Decoder(#(Context(final), final))
pub fn string_enum(
values: List(a),
to_string: fn(a) -> String,
) -> Serializer(a)
pub fn success(value: t) -> decode.Decoder(t)
pub fn timestamp() -> Serializer(timestamp.Timestamp)
pub fn with_default(
serializer: Serializer(a),
default: spec.Spec,
) -> Serializer(a)
Add a default value to the openapi specification of the given serializer.
pub fn with_example(
serializer: Serializer(a),
example: spec.Spec,
) -> Serializer(a)
Add an example to the openapi specification of the given serializer.
pub fn with_max(
serializer: Serializer(a),
max: spec.Spec,
) -> Serializer(a)
Add an maximum value to the openapi specification of the given serializer.
pub fn with_min(
serializer: Serializer(a),
min: spec.Spec,
) -> Serializer(a)
Add an minimum value to the openapi specification of the given serializer.
pub fn with_pattern(
serializer: Serializer(a),
pattern: String,
) -> Serializer(a)
Add a pattern to the openapi specification of the given serializer.