Packages
oaspec
0.23.0
0.68.0
0.67.0
0.66.0
0.65.0
0.64.0
0.63.0
0.62.0
0.61.0
0.60.0
0.59.0
0.58.1
0.58.0
0.57.0
0.56.0
0.55.0
0.54.0
0.53.0
0.52.0
0.51.0
0.50.0
0.49.0
0.48.0
0.47.0
0.46.0
0.45.0
0.44.0
0.43.0
0.42.0
0.41.0
0.40.0
0.39.0
0.38.0
0.37.0
0.36.0
0.35.0
0.34.0
0.33.0
0.32.0
0.31.0
0.30.0
0.29.0
0.28.0
0.27.0
0.26.0
0.25.0
0.24.0
0.23.0
0.22.0
0.21.0
0.20.0
0.19.0
0.18.0
0.17.0
0.16.0
0.15.0
0.14.0
0.13.0
0.12.0
0.11.0
0.10.0
0.9.0
0.8.0
0.7.0
0.6.3
0.6.1
0.6.0
0.5.0
0.4.0
0.3.0
0.1.3
Generate Gleam code from OpenAPI 3.x specifications
Current section
Files
Jump to
Current section
Files
src/oaspec@codegen@server_request_decode.erl
-module(oaspec@codegen@server_request_decode).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/oaspec/codegen/server_request_decode.gleam").
-export([body_field_kind_needs_int/1, body_field_kind_needs_float/1, param_needs_result_unwrap/1, is_deep_object_param/2, deep_object_has_additional_properties/2, deep_object_param_has_optional_fields/2, request_body_uses_form_urlencoded/1, request_body_uses_multipart/1, operation_uses_form_urlencoded_body/1, operation_uses_multipart_body/1, deep_object_has_untyped_additional_properties/2, form_urlencoded_body_has_nested_object/2, multipart_body_has_optional_fields/2, form_urlencoded_body_has_optional_fields/2, query_schema_needs_string/1, deep_object_param_needs_string/2, form_urlencoded_body_needs_string/2, query_schema_needs_int/1, deep_object_param_needs_int/2, query_schema_needs_float/1, deep_object_param_needs_float/2, param_parse_expr/2, query_required_expr/2, query_optional_expr/2, deep_object_required_expr/4, deep_object_optional_expr/4, header_required_expr/2, cookie_required_expr/2, header_optional_expr/2, cookie_optional_expr/2, body_field_kind/2, schema_ref_body_field_kind/2, multipart_body_needs_int/2, multipart_body_needs_float/2, form_urlencoded_body_needs_int/2, form_urlencoded_body_needs_float/2, generate_body_decode_expr/3]).
-export_type([deep_object_property/0, body_field_kind/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
-type deep_object_property() :: {deep_object_property,
binary(),
binary(),
oaspec@openapi@schema:schema_ref(),
boolean()}.
-type body_field_kind() :: body_field_unknown |
body_field_string |
body_field_int |
body_field_float |
body_field_bool |
body_field_string_array |
body_field_int_array |
body_field_float_array |
body_field_bool_array.
-file("src/oaspec/codegen/server_request_decode.gleam", 99).
-spec body_field_kind_needs_int(body_field_kind()) -> boolean().
body_field_kind_needs_int(Kind) ->
case Kind of
body_field_int ->
true;
body_field_int_array ->
true;
_ ->
false
end.
-file("src/oaspec/codegen/server_request_decode.gleam", 106).
-spec body_field_kind_needs_float(body_field_kind()) -> boolean().
body_field_kind_needs_float(Kind) ->
case Kind of
body_field_float ->
true;
body_field_float_array ->
true;
_ ->
false
end.
-file("src/oaspec/codegen/server_request_decode.gleam", 137).
?DOC(
" Return true when the parse expression returns a Result that the router\n"
" must unwrap (int/float parsing). Bool and string params are always safe.\n"
).
-spec param_needs_result_unwrap(
oaspec@openapi@spec:parameter(oaspec@openapi@spec:resolved())
) -> boolean().
param_needs_result_unwrap(Param) ->
case oaspec@openapi@spec:parameter_schema(Param) of
{some, {inline, {integer_schema, _, _, _, _, _, _, _}}} ->
true;
{some, {inline, {number_schema, _, _, _, _, _, _, _}}} ->
true;
_ ->
false
end.
-file("src/oaspec/codegen/server_request_decode.gleam", 368).
-spec is_deep_object_param(
oaspec@openapi@spec:parameter(oaspec@openapi@spec:resolved()),
oaspec@codegen@context:context()
) -> boolean().
is_deep_object_param(Param, Ctx) ->
oaspec@codegen@operation_ir:is_deep_object_param(Param, Ctx).
-file("src/oaspec/codegen/server_request_decode.gleam", 375).
-spec deep_object_properties(
oaspec@openapi@spec:parameter(oaspec@openapi@spec:resolved()),
oaspec@codegen@context:context()
) -> list(deep_object_property()).
deep_object_properties(Param, Ctx) ->
Details = case oaspec@openapi@spec:parameter_schema(Param) of
{some, {reference, _, _} = Schema_ref} ->
case oaspec@openapi@resolver:resolve_schema_ref(
Schema_ref,
oaspec@codegen@context:spec(Ctx)
) of
{ok, {object_schema, _, Properties, Required, _, _, _}} ->
{Properties, Required};
_ ->
{maps:new(), []}
end;
{some, {inline, {object_schema, _, Properties@1, Required@1, _, _, _}}} ->
{Properties@1, Required@1};
_ ->
{maps:new(), []}
end,
{Properties@2, Required_fields} = Details,
_pipe = oaspec@codegen@ir_build:sorted_entries(Properties@2),
gleam@list:map(
_pipe,
fun(Entry) ->
{Prop_name, Prop_ref} = Entry,
{deep_object_property,
Prop_name,
oaspec@util@naming:to_snake_case(Prop_name),
Prop_ref,
gleam@list:contains(Required_fields, Prop_name)}
end
).
-file("src/oaspec/codegen/server_request_decode.gleam", 404).
-spec deep_object_type_name(
oaspec@openapi@spec:parameter(oaspec@openapi@spec:resolved()),
binary()
) -> binary().
deep_object_type_name(Param, Op_id) ->
case oaspec@openapi@spec:parameter_schema(Param) of
{some, {reference, _, Name}} ->
<<"types."/utf8,
(oaspec@util@naming:schema_to_type_name(Name))/binary>>;
_ ->
<<<<<<"types."/utf8,
(oaspec@util@naming:schema_to_type_name(Op_id))/binary>>/binary,
"Param"/utf8>>/binary,
(oaspec@util@naming:to_pascal_case(erlang:element(2, Param)))/binary>>
end.
-file("src/oaspec/codegen/server_request_decode.gleam", 511).
-spec deep_object_has_additional_properties(
oaspec@openapi@spec:parameter(oaspec@openapi@spec:resolved()),
oaspec@codegen@context:context()
) -> boolean().
deep_object_has_additional_properties(Param, Ctx) ->
case oaspec@openapi@spec:parameter_schema(Param) of
{some, {reference, _, _} = Schema_ref} ->
case oaspec@openapi@resolver:resolve_schema_ref(
Schema_ref,
oaspec@codegen@context:spec(Ctx)
) of
{ok, {object_schema, _, _, _, {typed, _}, _, _}} ->
true;
{ok, {object_schema, _, _, _, untyped, _, _}} ->
true;
_ ->
false
end;
{some, {inline, {object_schema, _, _, _, {typed, _}, _, _}}} ->
true;
{some, {inline, {object_schema, _, _, _, untyped, _, _}}} ->
true;
_ ->
false
end.
-file("src/oaspec/codegen/server_request_decode.gleam", 544).
-spec deep_object_param_has_optional_fields(
oaspec@openapi@spec:parameter(oaspec@openapi@spec:resolved()),
oaspec@codegen@context:context()
) -> boolean().
deep_object_param_has_optional_fields(Param, Ctx) ->
gleam@bool:guard(
not is_deep_object_param(Param, Ctx),
false,
fun() ->
gleam@list:any(
deep_object_properties(Param, Ctx),
fun(Prop) -> not erlang:element(5, Prop) end
)
end
).
-file("src/oaspec/codegen/server_request_decode.gleam", 579).
-spec deep_object_param_needs(
oaspec@openapi@spec:parameter(oaspec@openapi@spec:resolved()),
oaspec@codegen@context:context(),
fun((deep_object_property()) -> boolean())
) -> boolean().
deep_object_param_needs(Param, Ctx, Predicate) ->
gleam@bool:guard(
not is_deep_object_param(Param, Ctx),
false,
fun() ->
gleam@list:any(deep_object_properties(Param, Ctx), Predicate)
end
).
-file("src/oaspec/codegen/server_request_decode.gleam", 588).
-spec request_body_uses_form_urlencoded(
oaspec@openapi@spec:request_body(oaspec@openapi@spec:resolved())
) -> boolean().
request_body_uses_form_urlencoded(Rb) ->
gleam@dict:has_key(
erlang:element(3, Rb),
<<"application/x-www-form-urlencoded"/utf8>>
).
-file("src/oaspec/codegen/server_request_decode.gleam", 592).
-spec request_body_uses_multipart(
oaspec@openapi@spec:request_body(oaspec@openapi@spec:resolved())
) -> boolean().
request_body_uses_multipart(Rb) ->
gleam@dict:has_key(erlang:element(3, Rb), <<"multipart/form-data"/utf8>>).
-file("src/oaspec/codegen/server_request_decode.gleam", 596).
-spec operation_uses_form_urlencoded_body(
oaspec@openapi@spec:operation(oaspec@openapi@spec:resolved())
) -> boolean().
operation_uses_form_urlencoded_body(Operation) ->
case erlang:element(7, Operation) of
{some, {value, Rb}} ->
request_body_uses_form_urlencoded(Rb);
_ ->
false
end.
-file("src/oaspec/codegen/server_request_decode.gleam", 605).
-spec operation_uses_multipart_body(
oaspec@openapi@spec:operation(oaspec@openapi@spec:resolved())
) -> boolean().
operation_uses_multipart_body(Operation) ->
case erlang:element(7, Operation) of
{some, {value, Rb}} ->
request_body_uses_multipart(Rb);
_ ->
false
end.
-file("src/oaspec/codegen/server_request_decode.gleam", 614).
-spec object_properties_from_schema_ref(
oaspec@openapi@schema:schema_ref(),
oaspec@codegen@context:context()
) -> list(deep_object_property()).
object_properties_from_schema_ref(Schema_ref, Ctx) ->
Details = case Schema_ref of
{reference, _, _} = Schema_ref@1 ->
case oaspec@openapi@resolver:resolve_schema_ref(
Schema_ref@1,
oaspec@codegen@context:spec(Ctx)
) of
{ok, {object_schema, _, Properties, Required, _, _, _}} ->
{Properties, Required};
_ ->
{maps:new(), []}
end;
{inline, {object_schema, _, Properties@1, Required@1, _, _, _}} ->
{Properties@1, Required@1};
_ ->
{maps:new(), []}
end,
{Properties@2, Required_fields} = Details,
_pipe = oaspec@codegen@ir_build:sorted_entries(Properties@2),
gleam@list:map(
_pipe,
fun(Entry) ->
{Prop_name, Prop_ref} = Entry,
{deep_object_property,
Prop_name,
oaspec@util@naming:to_snake_case(Prop_name),
Prop_ref,
gleam@list:contains(Required_fields, Prop_name)}
end
).
-file("src/oaspec/codegen/server_request_decode.gleam", 640).
-spec form_urlencoded_body_properties(
oaspec@openapi@spec:request_body(oaspec@openapi@spec:resolved()),
oaspec@codegen@context:context()
) -> list(deep_object_property()).
form_urlencoded_body_properties(Rb, Ctx) ->
case gleam_stdlib:map_get(
erlang:element(3, Rb),
<<"application/x-www-form-urlencoded"/utf8>>
) of
{ok, Media_type} ->
case erlang:element(2, Media_type) of
{some, Schema_ref} ->
object_properties_from_schema_ref(Schema_ref, Ctx);
none ->
[]
end;
{error, _} ->
[]
end.
-file("src/oaspec/codegen/server_request_decode.gleam", 656).
-spec multipart_body_properties(
oaspec@openapi@spec:request_body(oaspec@openapi@spec:resolved()),
oaspec@codegen@context:context()
) -> list(deep_object_property()).
multipart_body_properties(Rb, Ctx) ->
case gleam_stdlib:map_get(
erlang:element(3, Rb),
<<"multipart/form-data"/utf8>>
) of
{ok, Media_type} ->
case erlang:element(2, Media_type) of
{some, Schema_ref} ->
object_properties_from_schema_ref(Schema_ref, Ctx);
none ->
[]
end;
{error, _} ->
[]
end.
-file("src/oaspec/codegen/server_request_decode.gleam", 671).
-spec schema_ref_resolves_to_object(
oaspec@openapi@schema:schema_ref(),
oaspec@codegen@context:context()
) -> boolean().
schema_ref_resolves_to_object(Schema_ref, Ctx) ->
case Schema_ref of
{inline, {object_schema, _, _, _, _, _, _}} ->
true;
{reference, _, _} = Schema_ref@1 ->
case oaspec@openapi@resolver:resolve_schema_ref(
Schema_ref@1,
oaspec@codegen@context:spec(Ctx)
) of
{ok, {object_schema, _, _, _, _, _, _}} ->
true;
_ ->
false
end;
_ ->
false
end.
-file("src/oaspec/codegen/server_request_decode.gleam", 683).
-spec schema_ref_additional_properties(
oaspec@openapi@schema:schema_ref(),
oaspec@codegen@context:context()
) -> oaspec@openapi@schema:additional_properties().
schema_ref_additional_properties(Schema_ref, Ctx) ->
case Schema_ref of
{inline, {object_schema, _, _, _, Additional_properties, _, _}} ->
Additional_properties;
{reference, _, _} = Schema_ref@1 ->
case oaspec@openapi@resolver:resolve_schema_ref(
Schema_ref@1,
oaspec@codegen@context:spec(Ctx)
) of
{ok, {object_schema, _, _, _, Additional_properties@1, _, _}} ->
Additional_properties@1;
_ ->
forbidden
end;
_ ->
forbidden
end.
-file("src/oaspec/codegen/server_request_decode.gleam", 530).
-spec deep_object_has_untyped_additional_properties(
oaspec@openapi@spec:parameter(oaspec@openapi@spec:resolved()),
oaspec@codegen@context:context()
) -> boolean().
deep_object_has_untyped_additional_properties(Param, Ctx) ->
case oaspec@openapi@spec:parameter_schema(Param) of
{some, Schema_ref} ->
case schema_ref_additional_properties(Schema_ref, Ctx) of
untyped ->
true;
_ ->
false
end;
none ->
false
end.
-file("src/oaspec/codegen/server_request_decode.gleam", 698).
-spec body_additional_properties(
oaspec@openapi@spec:request_body(oaspec@openapi@spec:resolved()),
binary(),
oaspec@codegen@context:context()
) -> oaspec@openapi@schema:additional_properties().
body_additional_properties(Rb, Content_type, Ctx) ->
case gleam_stdlib:map_get(erlang:element(3, Rb), Content_type) of
{ok, Media_type} ->
case erlang:element(2, Media_type) of
{some, Schema_ref} ->
schema_ref_additional_properties(Schema_ref, Ctx);
none ->
forbidden
end;
{error, _} ->
forbidden
end.
-file("src/oaspec/codegen/server_request_decode.gleam", 714).
-spec form_urlencoded_schema_ref_type_name(oaspec@openapi@schema:schema_ref()) -> binary().
form_urlencoded_schema_ref_type_name(Schema_ref) ->
case Schema_ref of
{reference, _, Name} ->
<<"types."/utf8,
(oaspec@util@naming:schema_to_type_name(Name))/binary>>;
_ ->
<<"String"/utf8>>
end.
-file("src/oaspec/codegen/server_request_decode.gleam", 721).
-spec form_urlencoded_body_type_name(
oaspec@openapi@spec:request_body(oaspec@openapi@spec:resolved()),
binary()
) -> binary().
form_urlencoded_body_type_name(Rb, Op_id) ->
case gleam_stdlib:map_get(
erlang:element(3, Rb),
<<"application/x-www-form-urlencoded"/utf8>>
) of
{ok, Media_type} ->
case erlang:element(2, Media_type) of
{some, {reference, _, Name}} ->
<<"types."/utf8,
(oaspec@util@naming:schema_to_type_name(Name))/binary>>;
{some, {inline, {object_schema, _, _, _, _, _, _}}} ->
<<<<"types."/utf8,
(oaspec@util@naming:schema_to_type_name(Op_id))/binary>>/binary,
"Request"/utf8>>;
_ ->
<<"String"/utf8>>
end;
{error, _} ->
<<"String"/utf8>>
end.
-file("src/oaspec/codegen/server_request_decode.gleam", 739).
-spec multipart_body_type_name(
oaspec@openapi@spec:request_body(oaspec@openapi@spec:resolved()),
binary()
) -> binary().
multipart_body_type_name(Rb, Op_id) ->
case gleam_stdlib:map_get(
erlang:element(3, Rb),
<<"multipart/form-data"/utf8>>
) of
{ok, Media_type} ->
case erlang:element(2, Media_type) of
{some, {reference, _, Name}} ->
<<"types."/utf8,
(oaspec@util@naming:schema_to_type_name(Name))/binary>>;
{some, {inline, {object_schema, _, _, _, _, _, _}}} ->
<<<<"types."/utf8,
(oaspec@util@naming:schema_to_type_name(Op_id))/binary>>/binary,
"Request"/utf8>>;
_ ->
<<"String"/utf8>>
end;
{error, _} ->
<<"String"/utf8>>
end.
-file("src/oaspec/codegen/server_request_decode.gleam", 757).
-spec form_urlencoded_key(binary(), binary()) -> binary().
form_urlencoded_key(Prefix, Name) ->
case Prefix of
<<""/utf8>> ->
Name;
_ ->
<<<<<<Prefix/binary, "["/utf8>>/binary, Name/binary>>/binary,
"]"/utf8>>
end.
-file("src/oaspec/codegen/server_request_decode.gleam", 913).
-spec form_urlencoded_body_has_nested_object(
oaspec@openapi@spec:request_body(oaspec@openapi@spec:resolved()),
oaspec@codegen@context:context()
) -> boolean().
form_urlencoded_body_has_nested_object(Rb, Ctx) ->
gleam@list:any(
form_urlencoded_body_properties(Rb, Ctx),
fun(Prop) ->
schema_ref_resolves_to_object(erlang:element(4, Prop), Ctx)
end
).
-file("src/oaspec/codegen/server_request_decode.gleam", 962).
-spec multipart_body_has_optional_fields(
oaspec@openapi@spec:request_body(oaspec@openapi@spec:resolved()),
oaspec@codegen@context:context()
) -> boolean().
multipart_body_has_optional_fields(Rb, Ctx) ->
gleam@list:any(
multipart_body_properties(Rb, Ctx),
fun(Prop) -> not erlang:element(5, Prop) end
).
-file("src/oaspec/codegen/server_request_decode.gleam", 993).
-spec form_urlencoded_properties_have_optional_fields(
list(deep_object_property()),
oaspec@codegen@context:context(),
boolean()
) -> boolean().
form_urlencoded_properties_have_optional_fields(
Props,
Ctx,
Allow_nested_objects
) ->
gleam@list:any(
Props,
fun(Prop) ->
not erlang:element(5, Prop) orelse case Allow_nested_objects andalso schema_ref_resolves_to_object(
erlang:element(4, Prop),
Ctx
) of
true ->
form_urlencoded_properties_have_optional_fields(
object_properties_from_schema_ref(
erlang:element(4, Prop),
Ctx
),
Ctx,
false
);
false ->
false
end
end
).
-file("src/oaspec/codegen/server_request_decode.gleam", 869).
-spec form_urlencoded_body_has_optional_fields(
oaspec@openapi@spec:request_body(oaspec@openapi@spec:resolved()),
oaspec@codegen@context:context()
) -> boolean().
form_urlencoded_body_has_optional_fields(Rb, Ctx) ->
form_urlencoded_properties_have_optional_fields(
form_urlencoded_body_properties(Rb, Ctx),
Ctx,
true
).
-file("src/oaspec/codegen/server_request_decode.gleam", 1051).
-spec form_urlencoded_properties_need(
list(deep_object_property()),
oaspec@codegen@context:context(),
boolean(),
fun((deep_object_property()) -> boolean())
) -> boolean().
form_urlencoded_properties_need(Props, Ctx, Allow_nested_objects, Predicate) ->
gleam@list:any(
Props,
fun(Prop) ->
Predicate(Prop) orelse case Allow_nested_objects andalso schema_ref_resolves_to_object(
erlang:element(4, Prop),
Ctx
) of
true ->
form_urlencoded_properties_need(
object_properties_from_schema_ref(
erlang:element(4, Prop),
Ctx
),
Ctx,
false,
Predicate
);
false ->
false
end
end
).
-file("src/oaspec/codegen/server_request_decode.gleam", 1075).
-spec query_schema_needs_string(
gleam@option:option(oaspec@openapi@schema:schema_ref())
) -> boolean().
query_schema_needs_string(Schema_ref) ->
case Schema_ref of
{some, {inline, {array_schema, _, _, _, _, _}}} ->
true;
{some, {inline, {boolean_schema, _}}} ->
true;
_ ->
false
end.
-file("src/oaspec/codegen/server_request_decode.gleam", 552).
-spec deep_object_param_needs_string(
oaspec@openapi@spec:parameter(oaspec@openapi@spec:resolved()),
oaspec@codegen@context:context()
) -> boolean().
deep_object_param_needs_string(Param, Ctx) ->
deep_object_param_needs(
Param,
Ctx,
fun(Prop) ->
query_schema_needs_string({some, erlang:element(4, Prop)})
end
).
-file("src/oaspec/codegen/server_request_decode.gleam", 1015).
-spec form_urlencoded_properties_need_string(
list(deep_object_property()),
oaspec@codegen@context:context(),
boolean()
) -> boolean().
form_urlencoded_properties_need_string(Props, Ctx, Allow_nested_objects) ->
form_urlencoded_properties_need(
Props,
Ctx,
Allow_nested_objects,
fun(Prop) ->
query_schema_needs_string({some, erlang:element(4, Prop)})
end
).
-file("src/oaspec/codegen/server_request_decode.gleam", 880).
-spec form_urlencoded_body_needs_string(
oaspec@openapi@spec:request_body(oaspec@openapi@spec:resolved()),
oaspec@codegen@context:context()
) -> boolean().
form_urlencoded_body_needs_string(Rb, Ctx) ->
form_urlencoded_properties_need_string(
form_urlencoded_body_properties(Rb, Ctx),
Ctx,
true
).
-file("src/oaspec/codegen/server_request_decode.gleam", 1083).
-spec query_schema_needs_int(
gleam@option:option(oaspec@openapi@schema:schema_ref())
) -> boolean().
query_schema_needs_int(Schema_ref) ->
case Schema_ref of
{some, {inline, {integer_schema, _, _, _, _, _, _, _}}} ->
true;
{some,
{inline,
{array_schema,
_,
{inline, {integer_schema, _, _, _, _, _, _, _}},
_,
_,
_}}} ->
true;
_ ->
false
end.
-file("src/oaspec/codegen/server_request_decode.gleam", 561).
-spec deep_object_param_needs_int(
oaspec@openapi@spec:parameter(oaspec@openapi@spec:resolved()),
oaspec@codegen@context:context()
) -> boolean().
deep_object_param_needs_int(Param, Ctx) ->
deep_object_param_needs(
Param,
Ctx,
fun(Prop) -> query_schema_needs_int({some, erlang:element(4, Prop)}) end
).
-file("src/oaspec/codegen/server_request_decode.gleam", 1092).
-spec query_schema_needs_float(
gleam@option:option(oaspec@openapi@schema:schema_ref())
) -> boolean().
query_schema_needs_float(Schema_ref) ->
case Schema_ref of
{some, {inline, {number_schema, _, _, _, _, _, _, _}}} ->
true;
{some,
{inline,
{array_schema,
_,
{inline, {number_schema, _, _, _, _, _, _, _}},
_,
_,
_}}} ->
true;
_ ->
false
end.
-file("src/oaspec/codegen/server_request_decode.gleam", 570).
-spec deep_object_param_needs_float(
oaspec@openapi@spec:parameter(oaspec@openapi@spec:resolved()),
oaspec@codegen@context:context()
) -> boolean().
deep_object_param_needs_float(Param, Ctx) ->
deep_object_param_needs(
Param,
Ctx,
fun(Prop) ->
query_schema_needs_float({some, erlang:element(4, Prop)})
end
).
-file("src/oaspec/codegen/server_request_decode.gleam", 1261).
?DOC(
" Parse expression for array items: int, with optional trimming.\n"
" Uses a case expression instead of `let assert` to avoid panicking on\n"
" malformed input — bad values fall back to 0 (#291).\n"
).
-spec array_item_int_parse(boolean()) -> binary().
array_item_int_parse(Trim) ->
gleam@bool:guard(
not Trim,
<<"case int.parse(item) { Ok(n) -> n _ -> 0 }"/utf8>>,
fun() ->
<<"let trimmed = string.trim(item) case int.parse(trimmed) { Ok(n) -> n _ -> 0 }"/utf8>>
end
).
-file("src/oaspec/codegen/server_request_decode.gleam", 1269).
?DOC(
" Parse expression for array items: float, with optional trimming.\n"
" Uses a case expression instead of `let assert` to avoid panicking on\n"
" malformed input — bad values fall back to 0.0 (#291).\n"
).
-spec array_item_float_parse(boolean()) -> binary().
array_item_float_parse(Trim) ->
gleam@bool:guard(
not Trim,
<<"case float.parse(item) { Ok(n) -> n _ -> 0.0 }"/utf8>>,
fun() ->
<<"let trimmed = string.trim(item) case float.parse(trimmed) { Ok(n) -> n _ -> 0.0 }"/utf8>>
end
).
-file("src/oaspec/codegen/server_request_decode.gleam", 117).
?DOC(
" Generate parse expression for a path parameter (already bound as String).\n"
" Returns a safe expression that does not crash on invalid input.\n"
" For types that need parsing (int, float), returns the raw parse call\n"
" so the router can wrap it in a case expression for error handling.\n"
).
-spec param_parse_expr(
binary(),
oaspec@openapi@spec:parameter(oaspec@openapi@spec:resolved())
) -> binary().
param_parse_expr(Var_name, Param) ->
case oaspec@openapi@spec:parameter_schema(Param) of
{some, {inline, {integer_schema, _, _, _, _, _, _, _}}} ->
<<<<"int.parse("/utf8, Var_name/binary>>/binary, ")"/utf8>>;
{some, {inline, {number_schema, _, _, _, _, _, _, _}}} ->
<<<<"float.parse("/utf8, Var_name/binary>>/binary, ")"/utf8>>;
{some, {inline, {boolean_schema, _}}} ->
<<<<<<<<"{ let v = "/utf8, Var_name/binary>>/binary, " "/utf8>>/binary,
"case string.lowercase(v) { \"true\" -> True _ -> False }"/utf8>>/binary,
" }"/utf8>>;
_ ->
Var_name
end.
-file("src/oaspec/codegen/server_request_decode.gleam", 178).
?DOC(
" Legacy lookup-based required-query expression preserved for deep object\n"
" constructor fields. Top-level required query params now go through the\n"
" safer `query_required_expr` + router-side case scaffolding (Issue #263);\n"
" deep object support is intentionally still on the old `let assert` path\n"
" pending its own fix.\n"
).
-spec deep_object_required_field_expr(
binary(),
gleam@option:option(oaspec@openapi@schema:schema_ref())
) -> binary().
deep_object_required_field_expr(Key, Schema_ref) ->
Base = <<<<"{ let assert Ok([v, ..]) = dict.get(query, \""/utf8,
Key/binary>>/binary,
"\") v }"/utf8>>,
case Schema_ref of
{some,
{inline,
{array_schema,
_,
{inline, {string_schema, _, _, _, _, _, _}},
_,
_,
_}}} ->
<<<<"{ let assert Ok(vs) = dict.get(query, \""/utf8, Key/binary>>/binary,
"\") list.map(vs, fn(item) { string.trim(item) }) }"/utf8>>;
{some,
{inline,
{array_schema,
_,
{inline, {integer_schema, _, _, _, _, _, _, _}},
_,
_,
_}}} ->
<<<<"{ let assert Ok(vs) = dict.get(query, \""/utf8, Key/binary>>/binary,
"\") list.map(vs, fn(item) { let trimmed = string.trim(item) case int.parse(trimmed) { Ok(n) -> n _ -> 0 } }) }"/utf8>>;
{some,
{inline,
{array_schema,
_,
{inline, {number_schema, _, _, _, _, _, _, _}},
_,
_,
_}}} ->
<<<<"{ let assert Ok(vs) = dict.get(query, \""/utf8, Key/binary>>/binary,
"\") list.map(vs, fn(item) { let trimmed = string.trim(item) case float.parse(trimmed) { Ok(n) -> n _ -> 0.0 } }) }"/utf8>>;
{some,
{inline, {array_schema, _, {inline, {boolean_schema, _}}, _, _, _}}} ->
<<<<<<<<"{ let assert Ok(vs) = dict.get(query, \""/utf8,
Key/binary>>/binary,
"\") list.map(vs, fn(item) { let v = string.trim(item) "/utf8>>/binary,
"case string.lowercase(v) { \"true\" -> True _ -> False }"/utf8>>/binary,
" }) }"/utf8>>;
{some, {inline, {integer_schema, _, _, _, _, _, _, _}}} ->
<<<<"{ let assert Ok([v, ..]) = dict.get(query, \""/utf8,
Key/binary>>/binary,
"\") let assert Ok(n) = int.parse(v) n }"/utf8>>;
{some, {inline, {number_schema, _, _, _, _, _, _, _}}} ->
<<<<"{ let assert Ok([v, ..]) = dict.get(query, \""/utf8,
Key/binary>>/binary,
"\") let assert Ok(n) = float.parse(v) n }"/utf8>>;
{some, {inline, {boolean_schema, _}}} ->
<<<<<<<<"{ let assert Ok([v, ..]) = dict.get(query, \""/utf8,
Key/binary>>/binary,
"\") "/utf8>>/binary,
"case string.lowercase(v) { \"true\" -> True _ -> False }"/utf8>>/binary,
" }"/utf8>>;
_ ->
Base
end.
-file("src/oaspec/codegen/server_request_decode.gleam", 220).
-spec query_required_expr_with_schema(
binary(),
gleam@option:option(oaspec@openapi@schema:schema_ref()),
gleam@option:option(boolean()),
gleam@option:option(oaspec@openapi@spec:parameter_style())
) -> binary().
query_required_expr_with_schema(Bound_var, Schema_ref, Explode, Style) ->
Delim = oaspec@codegen@operation_ir:delimiter_for_style(Style),
case Schema_ref of
{some,
{inline,
{array_schema,
_,
{inline, {string_schema, _, _, _, _, _, _}},
_,
_,
_}}} ->
case Explode of
{some, false} ->
<<<<<<<<"list.map(string.split("/utf8, Bound_var/binary>>/binary,
", \""/utf8>>/binary,
Delim/binary>>/binary,
"\"), fn(item) { string.trim(item) })"/utf8>>;
_ ->
<<<<"list.map("/utf8, Bound_var/binary>>/binary,
", fn(item) { string.trim(item) })"/utf8>>
end;
{some,
{inline,
{array_schema,
_,
{inline, {integer_schema, _, _, _, _, _, _, _}},
_,
_,
_}}} ->
<<Bound_var/binary, "_parsed_list"/utf8>>;
{some,
{inline,
{array_schema,
_,
{inline, {number_schema, _, _, _, _, _, _, _}},
_,
_,
_}}} ->
<<Bound_var/binary, "_parsed_list"/utf8>>;
{some,
{inline, {array_schema, _, {inline, {boolean_schema, _}}, _, _, _}}} ->
case Explode of
{some, false} ->
<<<<<<<<<<<<"list.map(string.split("/utf8,
Bound_var/binary>>/binary,
", \""/utf8>>/binary,
Delim/binary>>/binary,
"\"), fn(item) { let v = string.trim(item) "/utf8>>/binary,
"case string.lowercase(v) { \"true\" -> True _ -> False }"/utf8>>/binary,
" })"/utf8>>;
_ ->
<<<<<<<<"list.map("/utf8, Bound_var/binary>>/binary,
", fn(item) { let v = string.trim(item) "/utf8>>/binary,
"case string.lowercase(v) { \"true\" -> True _ -> False }"/utf8>>/binary,
" })"/utf8>>
end;
{some, {inline, {integer_schema, _, _, _, _, _, _, _}}} ->
<<Bound_var/binary, "_parsed"/utf8>>;
{some, {inline, {number_schema, _, _, _, _, _, _, _}}} ->
<<Bound_var/binary, "_parsed"/utf8>>;
{some, {inline, {boolean_schema, _}}} ->
<<<<<<<<"{ let v = "/utf8, Bound_var/binary>>/binary, " "/utf8>>/binary,
"case string.lowercase(v) { \"true\" -> True _ -> False }"/utf8>>/binary,
" }"/utf8>>;
_ ->
Bound_var
end.
-file("src/oaspec/codegen/server_request_decode.gleam", 161).
?DOC(
" Generate expression for a required query parameter.\n"
"\n"
" `bound_var` is the name of a variable that the router has already bound\n"
" in an enclosing case expression. For scalar params (string/bool/int/float)\n"
" this is the raw String value pulled out of the query dict. For array\n"
" params with `explode=true` this is the `List(String)` from the dict; with\n"
" `explode=false` it is the single raw String that still needs splitting.\n"
"\n"
" The router opens a `case dict.get(query, key) { Ok([raw, ..]) -> ...`\n"
" (or `Ok(raw_list) -> ...` for explode-true arrays) **before** asking this\n"
" helper for the value expression, so the lookup never `let assert`s.\n"
"\n"
" For numeric scalar/array parameters the router additionally opens a\n"
" `case int.parse(...)` / `float.parse(...)` (or `list.try_map(..., int.parse)`)\n"
" case, binding `<bound_var>_parsed` (or `<bound_var>_parsed_list`) on\n"
" success — that's the variable name the helper returns here.\n"
).
-spec query_required_expr(
binary(),
oaspec@openapi@spec:parameter(oaspec@openapi@spec:resolved())
) -> binary().
query_required_expr(Bound_var, Param) ->
query_required_expr_with_schema(
Bound_var,
oaspec@openapi@spec:parameter_schema(Param),
{some, oaspec@codegen@operation_ir:effective_explode(Param)},
erlang:element(7, Param)
).
-file("src/oaspec/codegen/server_request_decode.gleam", 283).
-spec query_optional_expr_with_schema(
binary(),
gleam@option:option(oaspec@openapi@schema:schema_ref()),
gleam@option:option(boolean()),
gleam@option:option(oaspec@openapi@spec:parameter_style())
) -> binary().
query_optional_expr_with_schema(Key, Schema_ref, Explode, Style) ->
Delim = oaspec@codegen@operation_ir:delimiter_for_style(Style),
case Schema_ref of
{some,
{inline,
{array_schema,
_,
{inline, {string_schema, _, _, _, _, _, _}},
_,
_,
_}}} ->
case Explode of
{some, false} ->
<<<<<<<<"case dict.get(query, \""/utf8, Key/binary>>/binary,
"\") { Ok([v, ..]) -> Some(list.map(string.split(v, \""/utf8>>/binary,
Delim/binary>>/binary,
"\"), fn(item) { string.trim(item) })) _ -> None }"/utf8>>;
_ ->
<<<<"case dict.get(query, \""/utf8, Key/binary>>/binary,
"\") { Ok(vs) -> Some(list.map(vs, fn(item) { string.trim(item) })) _ -> None }"/utf8>>
end;
{some,
{inline,
{array_schema,
_,
{inline, {integer_schema, _, _, _, _, _, _, _}},
_,
_,
_}}} ->
case Explode of
{some, false} ->
<<<<<<<<"case dict.get(query, \""/utf8, Key/binary>>/binary,
"\") { Ok([v, ..]) -> Some(list.map(string.split(v, \""/utf8>>/binary,
Delim/binary>>/binary,
"\"), fn(item) { let trimmed = string.trim(item) case int.parse(trimmed) { Ok(n) -> n _ -> 0 } })) _ -> None }"/utf8>>;
_ ->
<<<<"case dict.get(query, \""/utf8, Key/binary>>/binary,
"\") { Ok(vs) -> Some(list.map(vs, fn(item) { let trimmed = string.trim(item) case int.parse(trimmed) { Ok(n) -> n _ -> 0 } })) _ -> None }"/utf8>>
end;
{some,
{inline,
{array_schema,
_,
{inline, {number_schema, _, _, _, _, _, _, _}},
_,
_,
_}}} ->
case Explode of
{some, false} ->
<<<<<<<<"case dict.get(query, \""/utf8, Key/binary>>/binary,
"\") { Ok([v, ..]) -> Some(list.map(string.split(v, \""/utf8>>/binary,
Delim/binary>>/binary,
"\"), fn(item) { let trimmed = string.trim(item) case float.parse(trimmed) { Ok(n) -> n _ -> 0.0 } })) _ -> None }"/utf8>>;
_ ->
<<<<"case dict.get(query, \""/utf8, Key/binary>>/binary,
"\") { Ok(vs) -> Some(list.map(vs, fn(item) { let trimmed = string.trim(item) case float.parse(trimmed) { Ok(n) -> n _ -> 0.0 } })) _ -> None }"/utf8>>
end;
{some,
{inline, {array_schema, _, {inline, {boolean_schema, _}}, _, _, _}}} ->
case Explode of
{some, false} ->
<<<<<<<<<<<<"case dict.get(query, \""/utf8, Key/binary>>/binary,
"\") { Ok([v, ..]) -> Some(list.map(string.split(v, \""/utf8>>/binary,
Delim/binary>>/binary,
"\"), fn(item) { let v = string.trim(item) "/utf8>>/binary,
"case string.lowercase(v) { \"true\" -> True _ -> False }"/utf8>>/binary,
" })) _ -> None }"/utf8>>;
_ ->
<<<<<<<<"case dict.get(query, \""/utf8, Key/binary>>/binary,
"\") { Ok(vs) -> Some(list.map(vs, fn(item) { let v = string.trim(item) "/utf8>>/binary,
"case string.lowercase(v) { \"true\" -> True _ -> False }"/utf8>>/binary,
" })) _ -> None }"/utf8>>
end;
{some, {inline, {integer_schema, _, _, _, _, _, _, _}}} ->
<<<<"case dict.get(query, \""/utf8, Key/binary>>/binary,
"\") { Ok([v, ..]) -> { case int.parse(v) { Ok(n) -> Some(n) _ -> None } } _ -> None }"/utf8>>;
{some, {inline, {number_schema, _, _, _, _, _, _, _}}} ->
<<<<"case dict.get(query, \""/utf8, Key/binary>>/binary,
"\") { Ok([v, ..]) -> { case float.parse(v) { Ok(n) -> Some(n) _ -> None } } _ -> None }"/utf8>>;
{some, {inline, {boolean_schema, _}}} ->
<<<<<<<<"case dict.get(query, \""/utf8, Key/binary>>/binary,
"\") { Ok([v, ..]) -> Some("/utf8>>/binary,
"case string.lowercase(v) { \"true\" -> True _ -> False }"/utf8>>/binary,
") _ -> None }"/utf8>>;
_ ->
<<<<"case dict.get(query, \""/utf8, Key/binary>>/binary,
"\") { Ok([v, ..]) -> Some(v) _ -> None }"/utf8>>
end.
-file("src/oaspec/codegen/server_request_decode.gleam", 271).
?DOC(" Generate expression for an optional query parameter.\n").
-spec query_optional_expr(
binary(),
oaspec@openapi@spec:parameter(oaspec@openapi@spec:resolved())
) -> binary().
query_optional_expr(Key, Param) ->
query_optional_expr_with_schema(
Key,
oaspec@openapi@spec:parameter_schema(Param),
{some, oaspec@codegen@operation_ir:effective_explode(Param)},
erlang:element(7, Param)
).
-file("src/oaspec/codegen/server_request_decode.gleam", 451).
-spec deep_object_constructor_expr(
binary(),
oaspec@openapi@spec:parameter(oaspec@openapi@spec:resolved()),
binary(),
oaspec@codegen@context:context()
) -> binary().
deep_object_constructor_expr(Key, Param, Op_id, Ctx) ->
Fields = begin
_pipe = deep_object_properties(Param, Ctx),
gleam@list:map(
_pipe,
fun(Prop) ->
Prop_key = <<<<<<Key/binary, "["/utf8>>/binary,
(erlang:element(2, Prop))/binary>>/binary,
"]"/utf8>>,
Value_expr = case erlang:element(5, Prop) of
true ->
deep_object_required_field_expr(
Prop_key,
{some, erlang:element(4, Prop)}
);
false ->
query_optional_expr_with_schema(
Prop_key,
{some, erlang:element(4, Prop)},
{some, true},
none
)
end,
<<<<(erlang:element(3, Prop))/binary, ": "/utf8>>/binary,
Value_expr/binary>>
end
)
end,
Ap_kind = case oaspec@openapi@spec:parameter_schema(Param) of
{some, Schema_ref} ->
schema_ref_additional_properties(Schema_ref, Ctx);
none ->
forbidden
end,
Fields@1 = case Ap_kind of
forbidden ->
Fields;
unspecified ->
Fields;
untyped ->
Prop_names = begin
_pipe@1 = deep_object_properties(Param, Ctx),
_pipe@2 = gleam@list:map(
_pipe@1,
fun(Prop@1) ->
<<<<"\""/utf8, (erlang:element(2, Prop@1))/binary>>/binary,
"\""/utf8>>
end
),
gleam@string:join(_pipe@2, <<", "/utf8>>)
end,
Expr = <<<<<<<<"coerce_dict(deep_object_additional_properties(query, \""/utf8,
Key/binary>>/binary,
"\", ["/utf8>>/binary,
Prop_names/binary>>/binary,
"]))"/utf8>>,
lists:append(
Fields,
[<<"additional_properties: "/utf8, Expr/binary>>]
);
{typed, _} ->
lists:append(Fields, [<<"additional_properties: dict.new()"/utf8>>])
end,
Fields_str = gleam@string:join(Fields@1, <<", "/utf8>>),
<<<<<<(deep_object_type_name(Param, Op_id))/binary, "("/utf8>>/binary,
Fields_str/binary>>/binary,
")"/utf8>>.
-file("src/oaspec/codegen/server_request_decode.gleam", 418).
-spec deep_object_required_expr(
binary(),
oaspec@openapi@spec:parameter(oaspec@openapi@spec:resolved()),
binary(),
oaspec@codegen@context:context()
) -> binary().
deep_object_required_expr(Key, Param, Op_id, Ctx) ->
deep_object_constructor_expr(Key, Param, Op_id, Ctx).
-file("src/oaspec/codegen/server_request_decode.gleam", 427).
-spec deep_object_optional_expr(
binary(),
oaspec@openapi@spec:parameter(oaspec@openapi@spec:resolved()),
binary(),
oaspec@codegen@context:context()
) -> binary().
deep_object_optional_expr(Key, Param, Op_id, Ctx) ->
Props = deep_object_properties(Param, Ctx),
Prop_names = begin
_pipe = Props,
_pipe@1 = gleam@list:map(
_pipe,
fun(Prop) ->
<<<<"\""/utf8, (erlang:element(2, Prop))/binary>>/binary,
"\""/utf8>>
end
),
gleam@string:join(_pipe@1, <<", "/utf8>>)
end,
Has_untyped_ap = deep_object_has_untyped_additional_properties(Param, Ctx),
Presence_check = case Has_untyped_ap of
true ->
<<<<"deep_object_present_any(query, \""/utf8, Key/binary>>/binary,
"\")"/utf8>>;
false ->
<<<<<<<<"deep_object_present(query, \""/utf8, Key/binary>>/binary,
"\", ["/utf8>>/binary,
Prop_names/binary>>/binary,
"])"/utf8>>
end,
<<<<<<<<"case "/utf8, Presence_check/binary>>/binary,
" { True -> Some("/utf8>>/binary,
(deep_object_constructor_expr(Key, Param, Op_id, Ctx))/binary>>/binary,
") False -> None }"/utf8>>.
-file("src/oaspec/codegen/server_request_decode.gleam", 1275).
?DOC(" Parse expression for array items: bool, with optional trimming.\n").
-spec array_item_bool_parse(boolean()) -> binary().
array_item_bool_parse(Trim) ->
case Trim of
true ->
<<"let v = string.trim(item) "/utf8,
"case string.lowercase(v) { \"true\" -> True _ -> False }"/utf8>>;
false ->
<<"let v = item "/utf8,
"case string.lowercase(v) { \"true\" -> True _ -> False }"/utf8>>
end.
-file("src/oaspec/codegen/server_request_decode.gleam", 1338).
?DOC(
" Generate a required value expression for a source that returns a single\n"
" String value. Used for headers (dict.get returns single string) and\n"
" cookies. Header / cookie arrays are comma-separated in a single string.\n"
"\n"
" The lookup itself (and any int/float parse) is wrapped in an enclosing\n"
" case in the router, which binds `bound_var` (and `<bound_var>_parsed`\n"
" for numeric scalars). This helper just produces the value expression\n"
" that consumes those bound names — it never emits `let assert`.\n"
).
-spec single_value_required_expr(
binary(),
gleam@option:option(oaspec@openapi@schema:schema_ref())
) -> binary().
single_value_required_expr(Bound_var, Schema_ref) ->
case Schema_ref of
{some,
{inline,
{array_schema,
_,
{inline, {string_schema, _, _, _, _, _, _}},
_,
_,
_}}} ->
<<<<"list.map(string.split("/utf8, Bound_var/binary>>/binary,
", \",\"), fn(item) { string.trim(item) })"/utf8>>;
{some,
{inline,
{array_schema,
_,
{inline, {integer_schema, _, _, _, _, _, _, _}},
_,
_,
_}}} ->
<<Bound_var/binary, "_parsed_list"/utf8>>;
{some,
{inline,
{array_schema,
_,
{inline, {number_schema, _, _, _, _, _, _, _}},
_,
_,
_}}} ->
<<Bound_var/binary, "_parsed_list"/utf8>>;
{some,
{inline, {array_schema, _, {inline, {boolean_schema, _}}, _, _, _}}} ->
<<<<<<<<"list.map(string.split("/utf8, Bound_var/binary>>/binary,
", \",\"), fn(item) { "/utf8>>/binary,
(array_item_bool_parse(true))/binary>>/binary,
" })"/utf8>>;
{some, {inline, {integer_schema, _, _, _, _, _, _, _}}} ->
<<Bound_var/binary, "_parsed"/utf8>>;
{some, {inline, {number_schema, _, _, _, _, _, _, _}}} ->
<<Bound_var/binary, "_parsed"/utf8>>;
{some, {inline, {boolean_schema, _}}} ->
<<<<<<<<"{ let v = "/utf8, Bound_var/binary>>/binary, " "/utf8>>/binary,
"case string.lowercase(v) { \"true\" -> True _ -> False }"/utf8>>/binary,
" }"/utf8>>;
_ ->
Bound_var
end.
-file("src/oaspec/codegen/server_request_decode.gleam", 1288).
?DOC(
" Generate expression for a required header parameter.\n"
"\n"
" `bound_var` is the raw header String the router has already pulled\n"
" out of the headers dict in an enclosing `case dict.get(...) { Ok(<var>) ->`.\n"
" The router additionally opens a numeric parse case for int/float scalar\n"
" params, binding `<bound_var>_parsed` on success.\n"
).
-spec header_required_expr(
binary(),
oaspec@openapi@spec:parameter(oaspec@openapi@spec:resolved())
) -> binary().
header_required_expr(Bound_var, Param) ->
single_value_required_expr(
Bound_var,
oaspec@openapi@spec:parameter_schema(Param)
).
-file("src/oaspec/codegen/server_request_decode.gleam", 1309).
?DOC(
" Generate expression for a required cookie parameter.\n"
"\n"
" `bound_var` is the raw cookie String the router has already pulled out\n"
" via `case cookie_lookup(...) { Ok(<var>) ->`. As with the header helper\n"
" the router pre-binds `<bound_var>_parsed` for numeric scalar types.\n"
).
-spec cookie_required_expr(
binary(),
oaspec@openapi@spec:parameter(oaspec@openapi@spec:resolved())
) -> binary().
cookie_required_expr(Bound_var, Param) ->
single_value_required_expr(
Bound_var,
oaspec@openapi@spec:parameter_schema(Param)
).
-file("src/oaspec/codegen/server_request_decode.gleam", 1367).
?DOC(" Generate an optional expression for a source that returns a single value.\n").
-spec single_value_optional_expr(
binary(),
binary(),
binary(),
gleam@option:option(oaspec@openapi@schema:schema_ref())
) -> binary().
single_value_optional_expr(Lookup, Var, Miss, Schema_ref) ->
case Schema_ref of
{some,
{inline,
{array_schema,
_,
{inline, {string_schema, _, _, _, _, _, _}},
_,
_,
_}}} ->
<<<<<<<<<<<<<<<<"case "/utf8, Lookup/binary>>/binary,
" { Ok("/utf8>>/binary,
Var/binary>>/binary,
") -> Some(list.map(string.split("/utf8>>/binary,
Var/binary>>/binary,
", \",\"), fn(item) { string.trim(item) })) "/utf8>>/binary,
Miss/binary>>/binary,
" -> None }"/utf8>>;
{some,
{inline,
{array_schema,
_,
{inline, {integer_schema, _, _, _, _, _, _, _}},
_,
_,
_}}} ->
<<<<<<<<<<<<<<<<<<<<"case "/utf8, Lookup/binary>>/binary,
" { Ok("/utf8>>/binary,
Var/binary>>/binary,
") -> Some(list.map(string.split("/utf8>>/binary,
Var/binary>>/binary,
", \",\"), fn(item) { "/utf8>>/binary,
(array_item_int_parse(true))/binary>>/binary,
" })) "/utf8>>/binary,
Miss/binary>>/binary,
" -> None }"/utf8>>;
{some,
{inline,
{array_schema,
_,
{inline, {number_schema, _, _, _, _, _, _, _}},
_,
_,
_}}} ->
<<<<<<<<<<<<<<<<<<<<"case "/utf8, Lookup/binary>>/binary,
" { Ok("/utf8>>/binary,
Var/binary>>/binary,
") -> Some(list.map(string.split("/utf8>>/binary,
Var/binary>>/binary,
", \",\"), fn(item) { "/utf8>>/binary,
(array_item_float_parse(true))/binary>>/binary,
" })) "/utf8>>/binary,
Miss/binary>>/binary,
" -> None }"/utf8>>;
{some,
{inline, {array_schema, _, {inline, {boolean_schema, _}}, _, _, _}}} ->
<<<<<<<<<<<<<<<<<<<<"case "/utf8, Lookup/binary>>/binary,
" { Ok("/utf8>>/binary,
Var/binary>>/binary,
") -> Some(list.map(string.split("/utf8>>/binary,
Var/binary>>/binary,
", \",\"), fn(item) { "/utf8>>/binary,
(array_item_bool_parse(true))/binary>>/binary,
" })) "/utf8>>/binary,
Miss/binary>>/binary,
" -> None }"/utf8>>;
{some, {inline, {integer_schema, _, _, _, _, _, _, _}}} ->
<<<<<<<<<<<<<<<<"case "/utf8, Lookup/binary>>/binary,
" { Ok("/utf8>>/binary,
Var/binary>>/binary,
") -> { case int.parse("/utf8>>/binary,
Var/binary>>/binary,
") { Ok(n) -> Some(n) _ -> None } } "/utf8>>/binary,
Miss/binary>>/binary,
" -> None }"/utf8>>;
{some, {inline, {number_schema, _, _, _, _, _, _, _}}} ->
<<<<<<<<<<<<<<<<"case "/utf8, Lookup/binary>>/binary,
" { Ok("/utf8>>/binary,
Var/binary>>/binary,
") -> { case float.parse("/utf8>>/binary,
Var/binary>>/binary,
") { Ok(n) -> Some(n) _ -> None } } "/utf8>>/binary,
Miss/binary>>/binary,
" -> None }"/utf8>>;
{some, {inline, {boolean_schema, _}}} ->
<<<<<<<<<<<<<<<<"case "/utf8, Lookup/binary>>/binary,
" { Ok("/utf8>>/binary,
Var/binary>>/binary,
") -> Some("/utf8>>/binary,
"case string.lowercase(v) { \"true\" -> True _ -> False }"/utf8>>/binary,
") "/utf8>>/binary,
Miss/binary>>/binary,
" -> None }"/utf8>>;
_ ->
<<<<<<<<<<<<<<<<"case "/utf8, Lookup/binary>>/binary,
" { Ok("/utf8>>/binary,
Var/binary>>/binary,
") -> Some("/utf8>>/binary,
Var/binary>>/binary,
") "/utf8>>/binary,
Miss/binary>>/binary,
" -> None }"/utf8>>
end.
-file("src/oaspec/codegen/server_request_decode.gleam", 1296).
?DOC(" Generate expression for an optional header parameter.\n").
-spec header_optional_expr(
binary(),
oaspec@openapi@spec:parameter(oaspec@openapi@spec:resolved())
) -> binary().
header_optional_expr(Key, Param) ->
Lookup = <<<<"dict.get(headers, \""/utf8, Key/binary>>/binary, "\")"/utf8>>,
single_value_optional_expr(
Lookup,
<<"v"/utf8>>,
<<"_"/utf8>>,
oaspec@openapi@spec:parameter_schema(Param)
).
-file("src/oaspec/codegen/server_request_decode.gleam", 1317).
?DOC(" Generate expression for an optional cookie parameter.\n").
-spec cookie_optional_expr(
binary(),
oaspec@openapi@spec:parameter(oaspec@openapi@spec:resolved())
) -> binary().
cookie_optional_expr(Key, Param) ->
Lookup = <<<<"cookie_lookup(headers, \""/utf8, Key/binary>>/binary,
"\")"/utf8>>,
single_value_optional_expr(
Lookup,
<<"v"/utf8>>,
<<"Error(_)"/utf8>>,
oaspec@openapi@spec:parameter_schema(Param)
).
-file("src/oaspec/codegen/server_request_decode.gleam", 811).
-spec form_urlencoded_object_required_expr(
binary(),
oaspec@openapi@schema:schema_ref(),
oaspec@codegen@context:context(),
integer()
) -> binary().
form_urlencoded_object_required_expr(Prefix, Schema_ref, Ctx, Nesting_depth) ->
form_urlencoded_object_constructor_expr(
form_urlencoded_schema_ref_type_name(Schema_ref),
Prefix,
object_properties_from_schema_ref(Schema_ref, Ctx),
schema_ref_additional_properties(Schema_ref, Ctx),
Ctx,
Nesting_depth
).
-file("src/oaspec/codegen/server_request_decode.gleam", 764).
-spec form_urlencoded_object_constructor_expr(
binary(),
binary(),
list(deep_object_property()),
oaspec@openapi@schema:additional_properties(),
oaspec@codegen@context:context(),
integer()
) -> binary().
form_urlencoded_object_constructor_expr(
Type_name,
Prefix,
Properties,
Additional_properties,
Ctx,
Nesting_depth
) ->
Fields = begin
_pipe = Properties,
_pipe@1 = gleam@list:map(
_pipe,
fun(Prop) ->
Key = form_urlencoded_key(Prefix, erlang:element(2, Prop)),
Value_expr = case {(Nesting_depth < 5) andalso schema_ref_resolves_to_object(
erlang:element(4, Prop),
Ctx
),
erlang:element(5, Prop)} of
{true, true} ->
form_urlencoded_object_required_expr(
Key,
erlang:element(4, Prop),
Ctx,
Nesting_depth + 1
);
{true, false} ->
form_urlencoded_object_optional_expr(
Key,
erlang:element(4, Prop),
Ctx,
Nesting_depth + 1
);
{false, true} ->
form_body_required_expr_with_schema(
Key,
{some, erlang:element(4, Prop)},
Ctx
);
{false, false} ->
form_body_optional_expr_with_schema(
Key,
{some, erlang:element(4, Prop)},
Ctx
)
end,
<<<<(erlang:element(3, Prop))/binary, ": "/utf8>>/binary,
Value_expr/binary>>
end
),
gleam@string:join(_pipe@1, <<", "/utf8>>)
end,
Additional_props_suffix = case Additional_properties of
forbidden ->
<<""/utf8>>;
unspecified ->
<<""/utf8>>;
{typed, _} ->
<<", additional_properties: dict.new()"/utf8>>;
untyped ->
<<", additional_properties: dict.new()"/utf8>>
end,
<<<<<<<<Type_name/binary, "("/utf8>>/binary, Fields/binary>>/binary,
Additional_props_suffix/binary>>/binary,
")"/utf8>>.
-file("src/oaspec/codegen/server_request_decode.gleam", 827).
-spec form_urlencoded_object_optional_expr(
binary(),
oaspec@openapi@schema:schema_ref(),
oaspec@codegen@context:context(),
integer()
) -> binary().
form_urlencoded_object_optional_expr(Prefix, Schema_ref, Ctx, Nesting_depth) ->
Props = object_properties_from_schema_ref(Schema_ref, Ctx),
Prop_names = begin
_pipe = Props,
_pipe@1 = gleam@list:map(
_pipe,
fun(Prop) ->
<<<<"\""/utf8, (erlang:element(2, Prop))/binary>>/binary,
"\""/utf8>>
end
),
gleam@string:join(_pipe@1, <<", "/utf8>>)
end,
<<<<<<<<<<<<"case form_object_present(form_body, \""/utf8, Prefix/binary>>/binary,
"\", ["/utf8>>/binary,
Prop_names/binary>>/binary,
"]) { True -> Some("/utf8>>/binary,
(form_urlencoded_object_constructor_expr(
form_urlencoded_schema_ref_type_name(Schema_ref),
Prefix,
Props,
schema_ref_additional_properties(Schema_ref, Ctx),
Ctx,
Nesting_depth
))/binary>>/binary,
") False -> None }"/utf8>>.
-file("src/oaspec/codegen/server_request_decode.gleam", 854).
-spec form_urlencoded_body_constructor_expr(
oaspec@openapi@spec:request_body(oaspec@openapi@spec:resolved()),
binary(),
oaspec@codegen@context:context()
) -> binary().
form_urlencoded_body_constructor_expr(Rb, Op_id, Ctx) ->
form_urlencoded_object_constructor_expr(
form_urlencoded_body_type_name(Rb, Op_id),
<<""/utf8>>,
form_urlencoded_body_properties(Rb, Ctx),
body_additional_properties(
Rb,
<<"application/x-www-form-urlencoded"/utf8>>,
Ctx
),
Ctx,
0
).
-file("src/oaspec/codegen/server_request_decode.gleam", 78).
-spec body_field_kind_from_object(
oaspec@openapi@schema:schema_object(),
oaspec@codegen@context:context()
) -> body_field_kind().
body_field_kind_from_object(Schema_obj, Ctx) ->
case Schema_obj of
{string_schema, _, _, _, _, _, _} ->
body_field_string;
{integer_schema, _, _, _, _, _, _, _} ->
body_field_int;
{number_schema, _, _, _, _, _, _, _} ->
body_field_float;
{boolean_schema, _} ->
body_field_bool;
{array_schema, _, Items, _, _, _} ->
case body_field_kind(Items, Ctx) of
body_field_string ->
body_field_string_array;
body_field_int ->
body_field_int_array;
body_field_float ->
body_field_float_array;
body_field_bool ->
body_field_bool_array;
_ ->
body_field_unknown
end;
_ ->
body_field_unknown
end.
-file("src/oaspec/codegen/server_request_decode.gleam", 54).
-spec body_field_kind(
oaspec@openapi@schema:schema_ref(),
oaspec@codegen@context:context()
) -> body_field_kind().
body_field_kind(Schema_ref, Ctx) ->
case Schema_ref of
{inline, {string_schema, _, _, _, _, _, _}} ->
body_field_string;
{inline, {integer_schema, _, _, _, _, _, _, _}} ->
body_field_int;
{inline, {number_schema, _, _, _, _, _, _, _}} ->
body_field_float;
{inline, {boolean_schema, _}} ->
body_field_bool;
{inline, {array_schema, _, Items, _, _, _}} ->
case body_field_kind(Items, Ctx) of
body_field_string ->
body_field_string_array;
body_field_int ->
body_field_int_array;
body_field_float ->
body_field_float_array;
body_field_bool ->
body_field_bool_array;
_ ->
body_field_unknown
end;
{reference, _, _} = Schema_ref@1 ->
case oaspec@openapi@resolver:resolve_schema_ref(
Schema_ref@1,
oaspec@codegen@context:spec(Ctx)
) of
{ok, Schema_obj} ->
body_field_kind_from_object(Schema_obj, Ctx);
{error, _} ->
body_field_unknown
end;
_ ->
body_field_unknown
end.
-file("src/oaspec/codegen/server_request_decode.gleam", 44).
-spec schema_ref_body_field_kind(
gleam@option:option(oaspec@openapi@schema:schema_ref()),
oaspec@codegen@context:context()
) -> body_field_kind().
schema_ref_body_field_kind(Schema_ref, Ctx) ->
case Schema_ref of
{some, Schema_ref@1} ->
body_field_kind(Schema_ref@1, Ctx);
none ->
body_field_unknown
end.
-file("src/oaspec/codegen/server_request_decode.gleam", 969).
-spec multipart_body_needs_int(
oaspec@openapi@spec:request_body(oaspec@openapi@spec:resolved()),
oaspec@codegen@context:context()
) -> boolean().
multipart_body_needs_int(Rb, Ctx) ->
gleam@list:any(
multipart_body_properties(Rb, Ctx),
fun(Prop) ->
body_field_kind_needs_int(
schema_ref_body_field_kind({some, erlang:element(4, Prop)}, Ctx)
)
end
).
-file("src/oaspec/codegen/server_request_decode.gleam", 981).
-spec multipart_body_needs_float(
oaspec@openapi@spec:request_body(oaspec@openapi@spec:resolved()),
oaspec@codegen@context:context()
) -> boolean().
multipart_body_needs_float(Rb, Ctx) ->
gleam@list:any(
multipart_body_properties(Rb, Ctx),
fun(Prop) ->
body_field_kind_needs_float(
schema_ref_body_field_kind({some, erlang:element(4, Prop)}, Ctx)
)
end
).
-file("src/oaspec/codegen/server_request_decode.gleam", 1025).
-spec form_urlencoded_properties_need_int(
list(deep_object_property()),
oaspec@codegen@context:context(),
boolean()
) -> boolean().
form_urlencoded_properties_need_int(Props, Ctx, Allow_nested_objects) ->
form_urlencoded_properties_need(
Props,
Ctx,
Allow_nested_objects,
fun(Prop) ->
body_field_kind_needs_int(
schema_ref_body_field_kind({some, erlang:element(4, Prop)}, Ctx)
)
end
).
-file("src/oaspec/codegen/server_request_decode.gleam", 891).
-spec form_urlencoded_body_needs_int(
oaspec@openapi@spec:request_body(oaspec@openapi@spec:resolved()),
oaspec@codegen@context:context()
) -> boolean().
form_urlencoded_body_needs_int(Rb, Ctx) ->
form_urlencoded_properties_need_int(
form_urlencoded_body_properties(Rb, Ctx),
Ctx,
true
).
-file("src/oaspec/codegen/server_request_decode.gleam", 1038).
-spec form_urlencoded_properties_need_float(
list(deep_object_property()),
oaspec@codegen@context:context(),
boolean()
) -> boolean().
form_urlencoded_properties_need_float(Props, Ctx, Allow_nested_objects) ->
form_urlencoded_properties_need(
Props,
Ctx,
Allow_nested_objects,
fun(Prop) ->
body_field_kind_needs_float(
schema_ref_body_field_kind({some, erlang:element(4, Prop)}, Ctx)
)
end
).
-file("src/oaspec/codegen/server_request_decode.gleam", 902).
-spec form_urlencoded_body_needs_float(
oaspec@openapi@spec:request_body(oaspec@openapi@spec:resolved()),
oaspec@codegen@context:context()
) -> boolean().
form_urlencoded_body_needs_float(Rb, Ctx) ->
form_urlencoded_properties_need_float(
form_urlencoded_body_properties(Rb, Ctx),
Ctx,
true
).
-file("src/oaspec/codegen/server_request_decode.gleam", 1136).
?DOC(
" Generate a required body field expression.\n"
" `source` is the dict name (e.g., \"form_body\", \"multipart_body\").\n"
" `trim_items` controls whether array items are trimmed (form_body) or used raw (multipart).\n"
).
-spec body_required_expr(
binary(),
binary(),
boolean(),
gleam@option:option(oaspec@openapi@schema:schema_ref()),
oaspec@codegen@context:context()
) -> binary().
body_required_expr(Key, Source, Trim_items, Schema_ref, Ctx) ->
Lookup = <<<<<<<<"dict.get("/utf8, Source/binary>>/binary, ", \""/utf8>>/binary,
Key/binary>>/binary,
"\")"/utf8>>,
Base = <<<<"{ let assert Ok([v, ..]) = "/utf8, Lookup/binary>>/binary,
" v }"/utf8>>,
case schema_ref_body_field_kind(Schema_ref, Ctx) of
body_field_string_array ->
case Trim_items of
true ->
<<<<"{ let assert Ok(vs) = "/utf8, Lookup/binary>>/binary,
" list.map(vs, fn(item) { string.trim(item) }) }"/utf8>>;
false ->
<<<<"{ let assert Ok(vs) = "/utf8, Lookup/binary>>/binary,
" vs }"/utf8>>
end;
body_field_int_array ->
<<<<<<<<"{ let assert Ok(vs) = "/utf8, Lookup/binary>>/binary,
" list.map(vs, fn(item) { "/utf8>>/binary,
(array_item_int_parse(Trim_items))/binary>>/binary,
" }) }"/utf8>>;
body_field_float_array ->
<<<<<<<<"{ let assert Ok(vs) = "/utf8, Lookup/binary>>/binary,
" list.map(vs, fn(item) { "/utf8>>/binary,
(array_item_float_parse(Trim_items))/binary>>/binary,
" }) }"/utf8>>;
body_field_bool_array ->
<<<<<<<<"{ let assert Ok(vs) = "/utf8, Lookup/binary>>/binary,
" list.map(vs, fn(item) { "/utf8>>/binary,
(array_item_bool_parse(Trim_items))/binary>>/binary,
" }) }"/utf8>>;
body_field_int ->
<<<<"{ let assert Ok([v, ..]) = "/utf8, Lookup/binary>>/binary,
" let assert Ok(n) = int.parse(v) n }"/utf8>>;
body_field_float ->
<<<<"{ let assert Ok([v, ..]) = "/utf8, Lookup/binary>>/binary,
" let assert Ok(n) = float.parse(v) n }"/utf8>>;
body_field_bool ->
<<<<<<<<"{ let assert Ok([v, ..]) = "/utf8, Lookup/binary>>/binary,
" "/utf8>>/binary,
"case string.lowercase(v) { \"true\" -> True _ -> False }"/utf8>>/binary,
" }"/utf8>>;
_ ->
Base
end.
-file("src/oaspec/codegen/server_request_decode.gleam", 1101).
-spec form_body_required_expr_with_schema(
binary(),
gleam@option:option(oaspec@openapi@schema:schema_ref()),
oaspec@codegen@context:context()
) -> binary().
form_body_required_expr_with_schema(Key, Schema_ref, Ctx) ->
body_required_expr(Key, <<"form_body"/utf8>>, true, Schema_ref, Ctx).
-file("src/oaspec/codegen/server_request_decode.gleam", 1117).
-spec multipart_body_required_expr_with_schema(
binary(),
gleam@option:option(oaspec@openapi@schema:schema_ref()),
oaspec@codegen@context:context()
) -> binary().
multipart_body_required_expr_with_schema(Key, Schema_ref, Ctx) ->
body_required_expr(Key, <<"multipart_body"/utf8>>, false, Schema_ref, Ctx).
-file("src/oaspec/codegen/server_request_decode.gleam", 1188).
?DOC(
" Generate an optional body field expression.\n"
" `source` is the dict name, `miss` is the miss pattern (\"_\" or \"Error(_)\").\n"
).
-spec body_optional_expr(
binary(),
binary(),
boolean(),
binary(),
gleam@option:option(oaspec@openapi@schema:schema_ref()),
oaspec@codegen@context:context()
) -> binary().
body_optional_expr(Key, Source, Trim_items, Miss, Schema_ref, Ctx) ->
Lookup = <<<<<<<<"dict.get("/utf8, Source/binary>>/binary, ", \""/utf8>>/binary,
Key/binary>>/binary,
"\")"/utf8>>,
case schema_ref_body_field_kind(Schema_ref, Ctx) of
body_field_string_array ->
case Trim_items of
true ->
<<<<<<<<"case "/utf8, Lookup/binary>>/binary,
" { Ok(vs) -> Some(list.map(vs, fn(item) { string.trim(item) })) "/utf8>>/binary,
Miss/binary>>/binary,
" -> None }"/utf8>>;
false ->
<<<<<<<<"case "/utf8, Lookup/binary>>/binary,
" { Ok(vs) -> Some(vs) "/utf8>>/binary,
Miss/binary>>/binary,
" -> None }"/utf8>>
end;
body_field_int_array ->
<<<<<<<<<<<<"case "/utf8, Lookup/binary>>/binary,
" { Ok(vs) -> Some(list.map(vs, fn(item) { "/utf8>>/binary,
(array_item_int_parse(Trim_items))/binary>>/binary,
" })) "/utf8>>/binary,
Miss/binary>>/binary,
" -> None }"/utf8>>;
body_field_float_array ->
<<<<<<<<<<<<"case "/utf8, Lookup/binary>>/binary,
" { Ok(vs) -> Some(list.map(vs, fn(item) { "/utf8>>/binary,
(array_item_float_parse(Trim_items))/binary>>/binary,
" })) "/utf8>>/binary,
Miss/binary>>/binary,
" -> None }"/utf8>>;
body_field_bool_array ->
<<<<<<<<<<<<"case "/utf8, Lookup/binary>>/binary,
" { Ok(vs) -> Some(list.map(vs, fn(item) { "/utf8>>/binary,
(array_item_bool_parse(Trim_items))/binary>>/binary,
" })) "/utf8>>/binary,
Miss/binary>>/binary,
" -> None }"/utf8>>;
body_field_int ->
<<<<<<<<"case "/utf8, Lookup/binary>>/binary,
" { Ok([v, ..]) -> { case int.parse(v) { Ok(n) -> Some(n) _ -> None } } "/utf8>>/binary,
Miss/binary>>/binary,
" -> None }"/utf8>>;
body_field_float ->
<<<<<<<<"case "/utf8, Lookup/binary>>/binary,
" { Ok([v, ..]) -> { case float.parse(v) { Ok(n) -> Some(n) _ -> None } } "/utf8>>/binary,
Miss/binary>>/binary,
" -> None }"/utf8>>;
body_field_bool ->
<<<<<<<<<<<<"case "/utf8, Lookup/binary>>/binary,
" { Ok([v, ..]) -> Some("/utf8>>/binary,
"case string.lowercase(v) { \"true\" -> True _ -> False }"/utf8>>/binary,
") "/utf8>>/binary,
Miss/binary>>/binary,
" -> None }"/utf8>>;
_ ->
<<<<<<<<"case "/utf8, Lookup/binary>>/binary,
" { Ok([v, ..]) -> Some(v) "/utf8>>/binary,
Miss/binary>>/binary,
" -> None }"/utf8>>
end.
-file("src/oaspec/codegen/server_request_decode.gleam", 1109).
-spec form_body_optional_expr_with_schema(
binary(),
gleam@option:option(oaspec@openapi@schema:schema_ref()),
oaspec@codegen@context:context()
) -> binary().
form_body_optional_expr_with_schema(Key, Schema_ref, Ctx) ->
body_optional_expr(
Key,
<<"form_body"/utf8>>,
true,
<<"_"/utf8>>,
Schema_ref,
Ctx
).
-file("src/oaspec/codegen/server_request_decode.gleam", 1125).
-spec multipart_body_optional_expr_with_schema(
binary(),
gleam@option:option(oaspec@openapi@schema:schema_ref()),
oaspec@codegen@context:context()
) -> binary().
multipart_body_optional_expr_with_schema(Key, Schema_ref, Ctx) ->
body_optional_expr(
Key,
<<"multipart_body"/utf8>>,
false,
<<"_"/utf8>>,
Schema_ref,
Ctx
).
-file("src/oaspec/codegen/server_request_decode.gleam", 922).
-spec multipart_body_constructor_expr(
oaspec@openapi@spec:request_body(oaspec@openapi@spec:resolved()),
binary(),
oaspec@codegen@context:context()
) -> binary().
multipart_body_constructor_expr(Rb, Op_id, Ctx) ->
Fields = begin
_pipe = multipart_body_properties(Rb, Ctx),
_pipe@1 = gleam@list:map(
_pipe,
fun(Prop) ->
Value_expr = case erlang:element(5, Prop) of
true ->
multipart_body_required_expr_with_schema(
erlang:element(2, Prop),
{some, erlang:element(4, Prop)},
Ctx
);
false ->
multipart_body_optional_expr_with_schema(
erlang:element(2, Prop),
{some, erlang:element(4, Prop)},
Ctx
)
end,
<<<<(erlang:element(3, Prop))/binary, ": "/utf8>>/binary,
Value_expr/binary>>
end
),
gleam@string:join(_pipe@1, <<", "/utf8>>)
end,
Additional_props_suffix = case body_additional_properties(
Rb,
<<"multipart/form-data"/utf8>>,
Ctx
) of
forbidden ->
<<""/utf8>>;
unspecified ->
<<""/utf8>>;
{typed, _} ->
<<", additional_properties: dict.new()"/utf8>>;
untyped ->
<<", additional_properties: dict.new()"/utf8>>
end,
<<<<<<<<(multipart_body_type_name(Rb, Op_id))/binary, "("/utf8>>/binary,
Fields/binary>>/binary,
Additional_props_suffix/binary>>/binary,
")"/utf8>>.
-file("src/oaspec/codegen/server_request_decode.gleam", 1464).
?DOC(" Generate the body decode expression for a request body.\n").
-spec generate_body_decode_expr(
oaspec@openapi@spec:request_body(oaspec@openapi@spec:resolved()),
binary(),
oaspec@codegen@context:context()
) -> binary().
generate_body_decode_expr(Rb, Op_id, Ctx) ->
Content_entries = maps:to_list(erlang:element(3, Rb)),
case Content_entries of
[{Ct_name, Media_type}] ->
case oaspec@util@content_type:from_string(Ct_name) of
application_json ->
Decode_fn = case erlang:element(2, Media_type) of
{some, {reference, _, Name}} ->
<<<<"decode.decode_"/utf8,
(oaspec@util@naming:to_snake_case(Name))/binary>>/binary,
"(body)"/utf8>>;
_ ->
<<<<"decode.decode_"/utf8,
(oaspec@util@naming:to_snake_case(Op_id))/binary>>/binary,
"_request_body(body)"/utf8>>
end,
case erlang:element(4, Rb) of
true ->
<<<<"{ let assert Ok(decoded) = "/utf8,
Decode_fn/binary>>/binary,
" decoded }"/utf8>>;
false ->
<<<<"case body { \"\" -> None _ -> { case "/utf8,
Decode_fn/binary>>/binary,
" { Ok(decoded) -> Some(decoded) _ -> None } } }"/utf8>>
end;
form_url_encoded ->
Body_expr = form_urlencoded_body_constructor_expr(
Rb,
Op_id,
Ctx
),
case erlang:element(4, Rb) of
true ->
Body_expr;
false ->
<<<<"case body { \"\" -> None _ -> Some("/utf8,
Body_expr/binary>>/binary,
") }"/utf8>>
end;
multipart_form_data ->
Body_expr@1 = multipart_body_constructor_expr(
Rb,
Op_id,
Ctx
),
case erlang:element(4, Rb) of
true ->
Body_expr@1;
false ->
<<<<"case body { \"\" -> None _ -> Some("/utf8,
Body_expr@1/binary>>/binary,
") }"/utf8>>
end;
_ ->
case erlang:element(4, Rb) of
true ->
<<"body"/utf8>>;
false ->
<<"case body { \"\" -> None _ -> Some(body) }"/utf8>>
end
end;
_ ->
case erlang:element(4, Rb) of
true ->
<<"body"/utf8>>;
false ->
<<"case body { \"\" -> None _ -> Some(body) }"/utf8>>
end
end.