Current section

Files

Jump to
oaspec src oaspec@codegen@client_request.erl
Raw

src/oaspec@codegen@client_request.erl

-module(oaspec@codegen@client_request).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/oaspec/codegen/client_request.gleam").
-export([param_to_type/2, param_to_string_expr/3, to_str_for_required/3, to_str_for_optional_value/2, get_body_type/2, build_param_list/7, get_body_encode_expr/3, multipart_field_is_binary/2, multipart_field_to_string_fn/2, generate_multipart_body/4, form_array_item_to_string/2, generate_form_bracket_fields/8, generate_form_nested_object/6, generate_form_urlencoded_body/4, is_exploded_array_param/2, is_deep_object_param/2, schema_ref_to_string_expr/3, array_item_to_string_fn/2, generate_exploded_array_query_param/4, deep_object_array_item_to_string/2, generate_deep_object_query_param/4]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
-file("src/oaspec/codegen/client_request.gleam", 57).
?DOC(" Convert a parameter to its Gleam type string.\n").
-spec param_to_type(
oaspec@openapi@spec:parameter(oaspec@openapi@spec:resolved()),
oaspec@codegen@context:context()
) -> binary().
param_to_type(Param, Ctx) ->
Base = oaspec@codegen@schema_dispatch:resolve_param_type(
oaspec@openapi@spec:parameter_schema(Param),
erlang:element(2, Ctx)
),
case erlang:element(5, Param) of
true ->
Base;
false ->
<<<<"Option("/utf8, Base/binary>>/binary, ")"/utf8>>
end.
-file("src/oaspec/codegen/client_request.gleam", 67).
?DOC(" Convert a parameter value to its String representation for URL/header use.\n").
-spec param_to_string_expr(
oaspec@openapi@spec:parameter(oaspec@openapi@spec:resolved()),
binary(),
oaspec@codegen@context:context()
) -> binary().
param_to_string_expr(Param, Param_name, Ctx) ->
case erlang:element(6, Param) of
{parameter_schema, {inline, {array_schema, _, Items, _, _, _}}} ->
Item_to_str = oaspec@codegen@schema_dispatch:to_string_fn(
Items,
erlang:element(2, Ctx)
),
<<<<<<<<"string.join(list.map("/utf8, Param_name/binary>>/binary,
", "/utf8>>/binary,
Item_to_str/binary>>/binary,
"), \",\")"/utf8>>;
{parameter_schema, {inline, S}} ->
oaspec@codegen@schema_dispatch:to_string_expr(S, Param_name);
{parameter_schema, {reference, _, _} = Schema_ref} ->
case oaspec@openapi@resolver:resolve_schema_ref(
Schema_ref,
erlang:element(2, Ctx)
) of
{ok, {array_schema, _, Items@1, _, _, _}} ->
Item_to_str@1 = oaspec@codegen@schema_dispatch:to_string_fn(
Items@1,
erlang:element(2, Ctx)
),
<<<<<<<<"string.join(list.map("/utf8, Param_name/binary>>/binary,
", "/utf8>>/binary,
Item_to_str@1/binary>>/binary,
"), \",\")"/utf8>>;
_ ->
oaspec@codegen@schema_dispatch:schema_ref_to_string_expr(
Schema_ref,
Param_name,
erlang:element(2, Ctx)
)
end;
_ ->
Param_name
end.
-file("src/oaspec/codegen/client_request.gleam", 106).
?DOC(" Convert a required param to string for query building.\n").
-spec to_str_for_required(
oaspec@openapi@spec:parameter(oaspec@openapi@spec:resolved()),
binary(),
oaspec@codegen@context:context()
) -> binary().
to_str_for_required(Param, Param_name, Ctx) ->
param_to_string_expr(Param, Param_name, Ctx).
-file("src/oaspec/codegen/client_request.gleam", 115).
?DOC(" Convert an optional param value (bound to `v`) to string.\n").
-spec to_str_for_optional_value(
oaspec@openapi@spec:parameter(oaspec@openapi@spec:resolved()),
oaspec@codegen@context:context()
) -> binary().
to_str_for_optional_value(Param, Ctx) ->
case erlang:element(6, Param) of
{parameter_schema, {inline, {array_schema, _, Items, _, _, _}}} ->
Item_to_str = oaspec@codegen@schema_dispatch:to_string_fn(
Items,
erlang:element(2, Ctx)
),
<<<<"string.join(list.map(v, "/utf8, Item_to_str/binary>>/binary,
"), \",\")"/utf8>>;
{parameter_schema, {inline, S}} ->
oaspec@codegen@schema_dispatch:to_string_expr(S, <<"v"/utf8>>);
{parameter_schema, {reference, _, _} = Schema_ref} ->
case oaspec@openapi@resolver:resolve_schema_ref(
Schema_ref,
erlang:element(2, Ctx)
) of
{ok, {array_schema, _, Items@1, _, _, _}} ->
Item_to_str@1 = oaspec@codegen@schema_dispatch:to_string_fn(
Items@1,
erlang:element(2, Ctx)
),
<<<<"string.join(list.map(v, "/utf8, Item_to_str@1/binary>>/binary,
"), \",\")"/utf8>>;
_ ->
oaspec@codegen@schema_dispatch:schema_ref_to_string_expr(
Schema_ref,
<<"v"/utf8>>,
erlang:element(2, Ctx)
)
end;
_ ->
<<"v"/utf8>>
end.
-file("src/oaspec/codegen/client_request.gleam", 140).
?DOC(" Get the Gleam type for a request body parameter.\n").
-spec get_body_type(
oaspec@openapi@spec:request_body(oaspec@openapi@spec:resolved()),
binary()
) -> binary().
get_body_type(Rb, Op_id) ->
Content_entries = oaspec@codegen@ir_build:sorted_entries(
erlang:element(3, Rb)
),
case Content_entries of
[_, _ | _] ->
<<"String"/utf8>>;
[{_, 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, {string_schema, _, _, _, _, _, _}}} ->
<<"String"/utf8>>;
{some, {inline, {integer_schema, _, _, _, _, _, _, _}}} ->
<<"Int"/utf8>>;
{some, {inline, {number_schema, _, _, _, _, _, _, _}}} ->
<<"Float"/utf8>>;
{some, {inline, {boolean_schema, _}}} ->
<<"Bool"/utf8>>;
{some, {inline, _}} ->
<<<<"types."/utf8,
(oaspec@util@naming:schema_to_type_name(Op_id))/binary>>/binary,
"RequestBody"/utf8>>;
_ ->
<<"String"/utf8>>
end;
[] ->
<<"String"/utf8>>
end.
-file("src/oaspec/codegen/client_request.gleam", 14).
?DOC(" Build parameter list for function signature.\n").
-spec build_param_list(
list(oaspec@openapi@spec:parameter(oaspec@openapi@spec:resolved())),
list(oaspec@openapi@spec:parameter(oaspec@openapi@spec:resolved())),
list(oaspec@openapi@spec:parameter(oaspec@openapi@spec:resolved())),
list(oaspec@openapi@spec:parameter(oaspec@openapi@spec:resolved())),
oaspec@openapi@spec:operation(oaspec@openapi@spec:resolved()),
binary(),
oaspec@codegen@context:context()
) -> binary().
build_param_list(
Path_params,
Query_params,
Header_params,
Cookie_params,
Operation,
Op_id,
Ctx
) ->
All_params = begin
_pipe = lists:append(Path_params, Query_params),
_pipe@1 = lists:append(_pipe, Header_params),
lists:append(_pipe@1, Cookie_params)
end,
Param_strs = gleam@list:map(
All_params,
fun(P) ->
Param_name = oaspec@util@naming:to_snake_case(erlang:element(2, P)),
Param_type = param_to_type(P, Ctx),
<<<<<<", "/utf8, Param_name/binary>>/binary, ": "/utf8>>/binary,
Param_type/binary>>
end
),
_ = Ctx,
Body_param = case erlang:element(7, Operation) of
{some, {value, Rb}} ->
Body_type = get_body_type(Rb, Op_id),
Wrapped_type = case erlang:element(4, Rb) of
true ->
Body_type;
false ->
<<<<"Option("/utf8, Body_type/binary>>/binary, ")"/utf8>>
end,
Content_entries = oaspec@codegen@ir_build:sorted_entries(
erlang:element(3, Rb)
),
case Content_entries of
[_, _ | _] ->
[<<", content_type: String"/utf8>>,
<<", body: "/utf8, Wrapped_type/binary>>];
_ ->
[<<", body: "/utf8, Wrapped_type/binary>>]
end;
_ ->
[]
end,
gleam@string:join(lists:append(Param_strs, Body_param), <<""/utf8>>).
-file("src/oaspec/codegen/client_request.gleam", 162).
?DOC(" Get the encode expression for a request body.\n").
-spec get_body_encode_expr(
oaspec@openapi@spec:request_body(oaspec@openapi@spec:resolved()),
binary(),
oaspec@codegen@context:context()
) -> binary().
get_body_encode_expr(Rb, Op_id, _) ->
Content_entries = oaspec@codegen@ir_build:sorted_entries(
erlang:element(3, Rb)
),
case Content_entries of
[{_, Media_type} | _] ->
case erlang:element(2, Media_type) of
{some, {reference, _, Name}} ->
<<<<"encode.encode_"/utf8,
(oaspec@util@naming:to_snake_case(Name))/binary>>/binary,
"(body)"/utf8>>;
{some, {inline, {string_schema, _, _, _, _, _, _}}} ->
<<"json.to_string(json.string(body))"/utf8>>;
{some, {inline, {integer_schema, _, _, _, _, _, _, _}}} ->
<<"json.to_string(json.int(body))"/utf8>>;
{some, {inline, {number_schema, _, _, _, _, _, _, _}}} ->
<<"json.to_string(json.float(body))"/utf8>>;
{some, {inline, {boolean_schema, _}}} ->
<<"json.to_string(json.bool(body))"/utf8>>;
{some, {inline, _}} ->
Fn_name = <<<<"encode_"/utf8,
(oaspec@util@naming:to_snake_case(Op_id))/binary>>/binary,
"_request_body"/utf8>>,
<<<<"encode."/utf8, Fn_name/binary>>/binary, "(body)"/utf8>>;
_ ->
<<"body"/utf8>>
end;
[] ->
<<"body"/utf8>>
end.
-file("src/oaspec/codegen/client_request.gleam", 301).
-spec multipart_field_is_binary(
oaspec@openapi@schema:schema_ref(),
oaspec@codegen@context:context()
) -> boolean().
multipart_field_is_binary(Field_schema, Ctx) ->
case Field_schema of
{inline, {string_schema, _, {some, <<"binary"/utf8>>}, _, _, _, _}} ->
true;
{reference, _, _} = Schema_ref ->
case oaspec@openapi@resolver:resolve_schema_ref(
Schema_ref,
erlang:element(2, Ctx)
) of
{ok, {string_schema, _, {some, <<"binary"/utf8>>}, _, _, _, _}} ->
true;
_ ->
false
end;
_ ->
false
end.
-file("src/oaspec/codegen/client_request.gleam", 316).
-spec multipart_field_to_string_fn(
oaspec@openapi@schema:schema_ref(),
oaspec@codegen@context:context()
) -> binary().
multipart_field_to_string_fn(Field_schema, Ctx) ->
Result = oaspec@codegen@schema_dispatch:to_string_fn(
Field_schema,
erlang:element(2, Ctx)
),
case Result of
<<"fn(x) { x }"/utf8>> ->
<<""/utf8>>;
_ ->
Result
end.
-file("src/oaspec/codegen/client_request.gleam", 194).
?DOC(" Generate multipart/form-data body encoding in the client function.\n").
-spec generate_multipart_body(
gleam@string_tree:string_tree(),
oaspec@openapi@spec:request_body(oaspec@openapi@spec:resolved()),
binary(),
oaspec@codegen@context:context()
) -> gleam@string_tree:string_tree().
generate_multipart_body(Sb, Rb, _, Ctx) ->
Boundary = <<"----oaspec-boundary"/utf8>>,
Content_entries = oaspec@codegen@ir_build:sorted_entries(
erlang:element(3, Rb)
),
{Properties@2, Required_fields} = case Content_entries of
[{_, Media_type} | _] ->
case erlang:element(2, Media_type) of
{some,
{inline, {object_schema, _, Properties, Required, _, _, _}}} ->
{oaspec@codegen@ir_build:sorted_entries(Properties),
Required};
{some, {reference, _, _} = Schema_ref} ->
case oaspec@openapi@resolver:resolve_schema_ref(
Schema_ref,
erlang:element(2, Ctx)
) of
{ok,
{object_schema,
_,
Properties@1,
Required@1,
_,
_,
_}} ->
{oaspec@codegen@ir_build:sorted_entries(
Properties@1
),
Required@1};
_ ->
{[], []}
end;
_ ->
{[], []}
end;
_ ->
{[], []}
end,
Sb@1 = begin
_pipe = Sb,
_pipe@1 = oaspec@util@string_extra:indent(
_pipe,
1,
<<<<"let boundary = \""/utf8, Boundary/binary>>/binary, "\""/utf8>>
),
oaspec@util@string_extra:indent(_pipe@1, 1, <<"let parts = []"/utf8>>)
end,
Sb@3 = gleam@list:fold(
Properties@2,
Sb@1,
fun(Sb@2, Prop) ->
{Field_name, Field_schema} = Prop,
Gleam_field = oaspec@util@naming:to_snake_case(Field_name),
Is_required = gleam@list:contains(Required_fields, Field_name),
Is_binary = multipart_field_is_binary(Field_schema, Ctx),
To_string_fn = case Is_binary of
true ->
<<""/utf8>>;
false ->
multipart_field_to_string_fn(Field_schema, Ctx)
end,
Part_header_binary = <<<<<<<<"\"--\" <> boundary <> \"\\r\\nContent-Disposition: form-data; name=\\\""/utf8,
Field_name/binary>>/binary,
"\\\"; filename=\\\""/utf8>>/binary,
Field_name/binary>>/binary,
"\\\"\\r\\nContent-Type: application/octet-stream\\r\\n\\r\\n\""/utf8>>,
Part_header_text = <<<<"\"--\" <> boundary <> \"\\r\\nContent-Disposition: form-data; name=\\\""/utf8,
Field_name/binary>>/binary,
"\\\"\\r\\n\\r\\n\""/utf8>>,
Part_header = case Is_binary of
true ->
Part_header_binary;
false ->
Part_header_text
end,
case Is_required of
true ->
Value_expr = case To_string_fn of
<<""/utf8>> ->
<<"body."/utf8, Gleam_field/binary>>;
Fn_name ->
<<<<<<Fn_name/binary, "(body."/utf8>>/binary,
Gleam_field/binary>>/binary,
")"/utf8>>
end,
_pipe@2 = Sb@2,
oaspec@util@string_extra:indent(
_pipe@2,
1,
<<<<<<<<"let parts = ["/utf8, Part_header/binary>>/binary,
" <> "/utf8>>/binary,
Value_expr/binary>>/binary,
" <> \"\\r\\n\", ..parts]"/utf8>>
);
false ->
Value_expr@1 = case To_string_fn of
<<""/utf8>> ->
<<"v"/utf8>>;
Fn_name@1 ->
<<Fn_name@1/binary, "(v)"/utf8>>
end,
_pipe@3 = Sb@2,
_pipe@4 = oaspec@util@string_extra:indent(
_pipe@3,
1,
<<<<"let parts = case body."/utf8, Gleam_field/binary>>/binary,
" {"/utf8>>
),
_pipe@5 = oaspec@util@string_extra:indent(
_pipe@4,
2,
<<<<<<<<"Some(v) -> ["/utf8, Part_header/binary>>/binary,
" <> "/utf8>>/binary,
Value_expr@1/binary>>/binary,
" <> \"\\r\\n\", ..parts]"/utf8>>
),
_pipe@6 = oaspec@util@string_extra:indent(
_pipe@5,
2,
<<"None -> parts"/utf8>>
),
oaspec@util@string_extra:indent(_pipe@6, 1, <<"}"/utf8>>)
end
end
),
_pipe@7 = Sb@3,
_pipe@8 = oaspec@util@string_extra:indent(
_pipe@7,
1,
<<"let body_str = string.join(parts, \"\") <> \"--\" <> boundary <> \"--\\r\\n\""/utf8>>
),
_pipe@9 = oaspec@util@string_extra:indent(
_pipe@8,
1,
<<"let req = request.set_header(req, \"content-type\", \"multipart/form-data; boundary=\" <> boundary)"/utf8>>
),
oaspec@util@string_extra:indent(
_pipe@9,
1,
<<"let req = request.set_body(req, body_str)"/utf8>>
).
-file("src/oaspec/codegen/client_request.gleam", 330).
?DOC(
" Convert an array field's items to a string expression for form-urlencoded encoding.\n"
" Returns an expression that converts `item` to a String.\n"
).
-spec form_array_item_to_string(
oaspec@openapi@schema:schema_ref(),
oaspec@codegen@context:context()
) -> binary().
form_array_item_to_string(Field_schema, Ctx) ->
case Field_schema of
{inline, {array_schema, _, Items, _, _, _}} ->
oaspec@codegen@schema_dispatch:schema_ref_to_string_expr(
Items,
<<"item"/utf8>>,
erlang:element(2, Ctx)
);
_ ->
<<"string.inspect(item)"/utf8>>
end.
-file("src/oaspec/codegen/client_request.gleam", 479).
?DOC(
" Recursively generate bracket-encoded form fields for nested objects.\n"
" Produces key[sub]=value for leaf fields and recurses for object children.\n"
).
-spec generate_form_bracket_fields(
gleam@string_tree:string_tree(),
binary(),
binary(),
oaspec@openapi@schema:schema_ref(),
boolean(),
integer(),
binary(),
oaspec@codegen@context:context()
) -> gleam@string_tree:string_tree().
generate_form_bracket_fields(
Sb,
Key_prefix,
Accessor_prefix,
Field_schema,
_,
Indent_base,
Parts_var,
Ctx
) ->
Resolved = case Field_schema of
{inline, S} ->
{ok, S};
{reference, _, _} ->
oaspec@openapi@resolver:resolve_schema_ref(
Field_schema,
erlang:element(2, Ctx)
)
end,
case Resolved of
{ok, {object_schema, _, Properties, Required, _, _, _}} ->
Props = oaspec@codegen@ir_build:sorted_entries(Properties),
gleam@list:fold(
Props,
Sb,
fun(Sb@1, Entry) ->
{Prop_name, Prop_ref} = Entry,
Prop_field = oaspec@util@naming:to_snake_case(Prop_name),
Prop_accessor = <<<<Accessor_prefix/binary, "."/utf8>>/binary,
Prop_field/binary>>,
Prop_required = gleam@list:contains(Required, Prop_name),
Is_obj = case Prop_ref of
{inline, {object_schema, _, _, _, _, _, _}} ->
true;
{reference, _, _} = Sr ->
case oaspec@openapi@resolver:resolve_schema_ref(
Sr,
erlang:element(2, Ctx)
) of
{ok, {object_schema, _, _, _, _, _, _}} ->
true;
_ ->
false
end;
_ ->
false
end,
case Is_obj of
true ->
generate_form_bracket_fields(
Sb@1,
<<<<<<Key_prefix/binary, "["/utf8>>/binary,
Prop_name/binary>>/binary,
"]"/utf8>>,
Prop_accessor,
Prop_ref,
Prop_required,
Indent_base,
Parts_var,
Ctx
);
false ->
To_str = multipart_field_to_string_fn(Prop_ref, Ctx),
case Prop_required of
true ->
Value_expr = case To_str of
<<""/utf8>> ->
Prop_accessor;
Fn_name ->
<<<<<<Fn_name/binary, "("/utf8>>/binary,
Prop_accessor/binary>>/binary,
")"/utf8>>
end,
_pipe = Sb@1,
oaspec@util@string_extra:indent(
_pipe,
Indent_base,
<<<<<<<<<<<<<<<<<<<<"let "/utf8,
Parts_var/binary>>/binary,
" = [\""/utf8>>/binary,
Key_prefix/binary>>/binary,
"["/utf8>>/binary,
Prop_name/binary>>/binary,
"]=\" <> uri.percent_encode("/utf8>>/binary,
Value_expr/binary>>/binary,
"), .."/utf8>>/binary,
Parts_var/binary>>/binary,
"]"/utf8>>
);
false ->
_pipe@1 = Sb@1,
_pipe@2 = oaspec@util@string_extra:indent(
_pipe@1,
Indent_base,
<<<<<<<<"let "/utf8, Parts_var/binary>>/binary,
" = case "/utf8>>/binary,
Prop_accessor/binary>>/binary,
" {"/utf8>>
),
_pipe@3 = oaspec@util@string_extra:indent(
_pipe@2,
Indent_base + 1,
<<<<<<<<<<<<<<<<"Some(v) -> [\""/utf8,
Key_prefix/binary>>/binary,
"["/utf8>>/binary,
Prop_name/binary>>/binary,
"]=\" <> uri.percent_encode("/utf8>>/binary,
((case To_str of
<<""/utf8>> ->
<<"v"/utf8>>;
Fn_name@1 ->
<<Fn_name@1/binary,
"(v)"/utf8>>
end))/binary>>/binary,
"), .."/utf8>>/binary,
Parts_var/binary>>/binary,
"]"/utf8>>
),
_pipe@4 = oaspec@util@string_extra:indent(
_pipe@3,
Indent_base + 1,
<<"None -> "/utf8, Parts_var/binary>>
),
oaspec@util@string_extra:indent(
_pipe@4,
Indent_base,
<<"}"/utf8>>
)
end
end
end
);
_ ->
Sb
end.
-file("src/oaspec/codegen/client_request.gleam", 343).
?DOC(
" Generate form encoding for a nested object property.\n"
" Serializes as field[subkey]=value for each sub-property.\n"
).
-spec generate_form_nested_object(
gleam@string_tree:string_tree(),
binary(),
binary(),
oaspec@openapi@schema:schema_ref(),
boolean(),
oaspec@codegen@context:context()
) -> gleam@string_tree:string_tree().
generate_form_nested_object(
Sb,
Field_name,
Gleam_field,
Field_schema,
Is_required,
Ctx
) ->
Resolved = case Field_schema of
{inline, S} ->
{ok, S};
{reference, _, _} ->
oaspec@openapi@resolver:resolve_schema_ref(
Field_schema,
erlang:element(2, Ctx)
)
end,
Sub_props = case Resolved of
{ok, {object_schema, _, Properties, Required, _, _, _}} ->
{oaspec@codegen@ir_build:sorted_entries(Properties), Required};
_ ->
{[], []}
end,
{Props, Required_fields} = Sub_props,
Accessor_prefix = case Is_required of
true ->
<<"body."/utf8, Gleam_field/binary>>;
false ->
<<"obj"/utf8>>
end,
Sb@1 = case Is_required of
true ->
Sb;
false ->
_pipe = Sb,
_pipe@1 = oaspec@util@string_extra:indent(
_pipe,
1,
<<<<"let form_parts = case body."/utf8, Gleam_field/binary>>/binary,
" {"/utf8>>
),
_pipe@2 = oaspec@util@string_extra:indent(
_pipe@1,
2,
<<"Some(obj) -> {"/utf8>>
),
oaspec@util@string_extra:indent(
_pipe@2,
3,
<<"let fp = form_parts"/utf8>>
)
end,
Indent_base = case Is_required of
true ->
1;
false ->
3
end,
Parts_var = case Is_required of
true ->
<<"form_parts"/utf8>>;
false ->
<<"fp"/utf8>>
end,
Sb@3 = gleam@list:fold(
Props,
Sb@1,
fun(Sb@2, Entry) ->
{Sub_name, Sub_ref} = Entry,
Sub_field = oaspec@util@naming:to_snake_case(Sub_name),
Sub_accessor = <<<<Accessor_prefix/binary, "."/utf8>>/binary,
Sub_field/binary>>,
Sub_required = gleam@list:contains(Required_fields, Sub_name),
Is_sub_object = case Sub_ref of
{inline, {object_schema, _, _, _, _, _, _}} ->
true;
{reference, _, _} = Sr ->
case oaspec@openapi@resolver:resolve_schema_ref(
Sr,
erlang:element(2, Ctx)
) of
{ok, {object_schema, _, _, _, _, _, _}} ->
true;
_ ->
false
end;
_ ->
false
end,
case Is_sub_object of
true ->
generate_form_bracket_fields(
Sb@2,
<<<<<<Field_name/binary, "["/utf8>>/binary,
Sub_name/binary>>/binary,
"]"/utf8>>,
Sub_accessor,
Sub_ref,
Sub_required,
Indent_base,
Parts_var,
Ctx
);
false ->
To_str = multipart_field_to_string_fn(Sub_ref, Ctx),
case Sub_required of
true ->
Value_expr = case To_str of
<<""/utf8>> ->
Sub_accessor;
Fn_name ->
<<<<<<Fn_name/binary, "("/utf8>>/binary,
Sub_accessor/binary>>/binary,
")"/utf8>>
end,
_pipe@3 = Sb@2,
oaspec@util@string_extra:indent(
_pipe@3,
Indent_base,
<<<<<<<<<<<<<<<<<<<<"let "/utf8,
Parts_var/binary>>/binary,
" = [\""/utf8>>/binary,
Field_name/binary>>/binary,
"["/utf8>>/binary,
Sub_name/binary>>/binary,
"]=\" <> uri.percent_encode("/utf8>>/binary,
Value_expr/binary>>/binary,
"), .."/utf8>>/binary,
Parts_var/binary>>/binary,
"]"/utf8>>
);
false ->
_pipe@4 = Sb@2,
_pipe@5 = oaspec@util@string_extra:indent(
_pipe@4,
Indent_base,
<<<<<<<<"let "/utf8, Parts_var/binary>>/binary,
" = case "/utf8>>/binary,
Sub_accessor/binary>>/binary,
" {"/utf8>>
),
_pipe@6 = oaspec@util@string_extra:indent(
_pipe@5,
Indent_base + 1,
<<<<<<<<<<<<<<<<"Some(v) -> [\""/utf8,
Field_name/binary>>/binary,
"["/utf8>>/binary,
Sub_name/binary>>/binary,
"]=\" <> uri.percent_encode("/utf8>>/binary,
((case To_str of
<<""/utf8>> ->
<<"v"/utf8>>;
Fn_name@1 ->
<<Fn_name@1/binary,
"(v)"/utf8>>
end))/binary>>/binary,
"), .."/utf8>>/binary,
Parts_var/binary>>/binary,
"]"/utf8>>
),
_pipe@7 = oaspec@util@string_extra:indent(
_pipe@6,
Indent_base + 1,
<<"None -> "/utf8, Parts_var/binary>>
),
oaspec@util@string_extra:indent(
_pipe@7,
Indent_base,
<<"}"/utf8>>
)
end
end
end
),
case Is_required of
true ->
Sb@3;
false ->
_pipe@8 = Sb@3,
_pipe@9 = oaspec@util@string_extra:indent(_pipe@8, 3, <<"fp"/utf8>>),
_pipe@10 = oaspec@util@string_extra:indent(_pipe@9, 2, <<"}"/utf8>>),
_pipe@11 = oaspec@util@string_extra:indent(
_pipe@10,
2,
<<"None -> form_parts"/utf8>>
),
oaspec@util@string_extra:indent(_pipe@11, 1, <<"}"/utf8>>)
end.
-file("src/oaspec/codegen/client_request.gleam", 581).
?DOC(" Generate application/x-www-form-urlencoded body encoding in the client function.\n").
-spec generate_form_urlencoded_body(
gleam@string_tree:string_tree(),
oaspec@openapi@spec:request_body(oaspec@openapi@spec:resolved()),
binary(),
oaspec@codegen@context:context()
) -> gleam@string_tree:string_tree().
generate_form_urlencoded_body(Sb, Rb, _, Ctx) ->
Content_entries = oaspec@codegen@ir_build:sorted_entries(
erlang:element(3, Rb)
),
{Properties@2, Required_fields} = case Content_entries of
[{_, Media_type} | _] ->
case erlang:element(2, Media_type) of
{some,
{inline, {object_schema, _, Properties, Required, _, _, _}}} ->
{oaspec@codegen@ir_build:sorted_entries(Properties),
Required};
{some, {reference, _, _} = Schema_ref} ->
case oaspec@openapi@resolver:resolve_schema_ref(
Schema_ref,
erlang:element(2, Ctx)
) of
{ok,
{object_schema,
_,
Properties@1,
Required@1,
_,
_,
_}} ->
{oaspec@codegen@ir_build:sorted_entries(
Properties@1
),
Required@1};
_ ->
{[], []}
end;
_ ->
{[], []}
end;
_ ->
{[], []}
end,
Sb@1 = begin
_pipe = Sb,
oaspec@util@string_extra:indent(
_pipe,
1,
<<"let form_parts = []"/utf8>>
)
end,
Sb@3 = gleam@list:fold(
Properties@2,
Sb@1,
fun(Sb@2, Prop) ->
{Field_name, Field_schema} = Prop,
Gleam_field = oaspec@util@naming:to_snake_case(Field_name),
Is_required = gleam@list:contains(Required_fields, Field_name),
Is_array = case Field_schema of
{inline, {array_schema, _, _, _, _, _}} ->
true;
{reference, _, _} = Sr ->
case oaspec@openapi@resolver:resolve_schema_ref(
Sr,
erlang:element(2, Ctx)
) of
{ok, {array_schema, _, _, _, _, _}} ->
true;
_ ->
false
end;
_ ->
false
end,
Is_object = case Field_schema of
{inline, {object_schema, _, _, _, _, _, _}} ->
true;
{reference, _, _} = Sr@1 ->
case oaspec@openapi@resolver:resolve_schema_ref(
Sr@1,
erlang:element(2, Ctx)
) of
{ok, {object_schema, _, _, _, _, _, _}} ->
true;
_ ->
false
end;
_ ->
false
end,
case Is_object of
true ->
generate_form_nested_object(
Sb@2,
Field_name,
Gleam_field,
Field_schema,
Is_required,
Ctx
);
false ->
case Is_array of
true ->
case Is_required of
true ->
_pipe@1 = Sb@2,
_pipe@2 = oaspec@util@string_extra:indent(
_pipe@1,
1,
<<<<"let form_parts = list.fold(body."/utf8,
Gleam_field/binary>>/binary,
", form_parts, fn(acc, item) {"/utf8>>
),
_pipe@3 = oaspec@util@string_extra:indent(
_pipe@2,
2,
<<<<<<<<"[\""/utf8, Field_name/binary>>/binary,
"=\" <> uri.percent_encode("/utf8>>/binary,
(form_array_item_to_string(
Field_schema,
Ctx
))/binary>>/binary,
"), ..acc]"/utf8>>
),
oaspec@util@string_extra:indent(
_pipe@3,
1,
<<"})"/utf8>>
);
false ->
_pipe@4 = Sb@2,
_pipe@5 = oaspec@util@string_extra:indent(
_pipe@4,
1,
<<<<"let form_parts = case body."/utf8,
Gleam_field/binary>>/binary,
" {"/utf8>>
),
_pipe@6 = oaspec@util@string_extra:indent(
_pipe@5,
2,
<<"Some(items) -> list.fold(items, form_parts, fn(acc, item) {"/utf8>>
),
_pipe@7 = oaspec@util@string_extra:indent(
_pipe@6,
3,
<<<<<<<<"[\""/utf8, Field_name/binary>>/binary,
"=\" <> uri.percent_encode("/utf8>>/binary,
(form_array_item_to_string(
Field_schema,
Ctx
))/binary>>/binary,
"), ..acc]"/utf8>>
),
_pipe@8 = oaspec@util@string_extra:indent(
_pipe@7,
2,
<<"})"/utf8>>
),
_pipe@9 = oaspec@util@string_extra:indent(
_pipe@8,
2,
<<"None -> form_parts"/utf8>>
),
oaspec@util@string_extra:indent(
_pipe@9,
1,
<<"}"/utf8>>
)
end;
false ->
To_str = multipart_field_to_string_fn(
Field_schema,
Ctx
),
case Is_required of
true ->
Value_expr = case To_str of
<<""/utf8>> ->
<<"body."/utf8, Gleam_field/binary>>;
Fn_name ->
<<<<<<Fn_name/binary,
"(body."/utf8>>/binary,
Gleam_field/binary>>/binary,
")"/utf8>>
end,
_pipe@10 = Sb@2,
oaspec@util@string_extra:indent(
_pipe@10,
1,
<<<<<<<<"let form_parts = [\""/utf8,
Field_name/binary>>/binary,
"=\" <> uri.percent_encode("/utf8>>/binary,
Value_expr/binary>>/binary,
"), ..form_parts]"/utf8>>
);
false ->
_pipe@11 = Sb@2,
_pipe@12 = oaspec@util@string_extra:indent(
_pipe@11,
1,
<<<<"let form_parts = case body."/utf8,
Gleam_field/binary>>/binary,
" {"/utf8>>
),
_pipe@13 = oaspec@util@string_extra:indent(
_pipe@12,
2,
<<<<<<<<"Some(v) -> [\""/utf8,
Field_name/binary>>/binary,
"=\" <> uri.percent_encode("/utf8>>/binary,
((case To_str of
<<""/utf8>> ->
<<"v"/utf8>>;
Fn_name@1 ->
<<Fn_name@1/binary,
"(v)"/utf8>>
end))/binary>>/binary,
"), ..form_parts]"/utf8>>
),
_pipe@14 = oaspec@util@string_extra:indent(
_pipe@13,
2,
<<"None -> form_parts"/utf8>>
),
oaspec@util@string_extra:indent(
_pipe@14,
1,
<<"}"/utf8>>
)
end
end
end
end
),
_pipe@15 = Sb@3,
_pipe@16 = oaspec@util@string_extra:indent(
_pipe@15,
1,
<<"let body_str = string.join(form_parts, \"&\")"/utf8>>
),
_pipe@17 = oaspec@util@string_extra:indent(
_pipe@16,
1,
<<"let req = request.set_header(req, \"content-type\", \"application/x-www-form-urlencoded\")"/utf8>>
),
oaspec@util@string_extra:indent(
_pipe@17,
1,
<<"let req = request.set_body(req, body_str)"/utf8>>
).
-file("src/oaspec/codegen/client_request.gleam", 742).
?DOC(
" Check if a parameter is an array with explode behavior.\n"
" OpenAPI default: style: form has explode: true by default.\n"
).
-spec is_exploded_array_param(
oaspec@openapi@spec:parameter(oaspec@openapi@spec:resolved()),
oaspec@codegen@context:context()
) -> boolean().
is_exploded_array_param(Param, Ctx) ->
Is_array = case erlang:element(6, Param) of
{parameter_schema, {inline, {array_schema, _, _, _, _, _}}} ->
true;
{parameter_schema, {reference, _, _} = Sr} ->
case oaspec@openapi@resolver:resolve_schema_ref(
Sr,
erlang:element(2, Ctx)
) of
{ok, {array_schema, _, _, _, _, _}} ->
true;
_ ->
false
end;
_ ->
false
end,
case Is_array of
false ->
false;
true ->
Effective_explode = case erlang:element(8, Param) of
{some, V} ->
V;
none ->
case erlang:element(7, Param) of
{some, form_style} ->
true;
none ->
true;
_ ->
false
end
end,
Effective_explode
end.
-file("src/oaspec/codegen/client_request.gleam", 830).
?DOC(" Check if a parameter uses deepObject style with an object schema.\n").
-spec is_deep_object_param(
oaspec@openapi@spec:parameter(oaspec@openapi@spec:resolved()),
oaspec@codegen@context:context()
) -> boolean().
is_deep_object_param(Param, Ctx) ->
case erlang:element(6, Param) of
{parameter_schema, {reference, _, _} = Schema_ref} ->
case oaspec@openapi@resolver:resolve_schema_ref(
Schema_ref,
erlang:element(2, Ctx)
) of
{ok, {object_schema, _, _, _, _, _, _}} ->
true;
_ ->
false
end;
{parameter_schema, {inline, {object_schema, _, _, _, _, _, _}}} ->
true;
_ ->
false
end.
-file("src/oaspec/codegen/client_request.gleam", 1046).
?DOC(" Convert a SchemaRef to a string expression for a given accessor.\n").
-spec schema_ref_to_string_expr(
oaspec@openapi@schema:schema_ref(),
binary(),
oaspec@codegen@context:context()
) -> binary().
schema_ref_to_string_expr(Schema_ref, Accessor, Ctx) ->
oaspec@codegen@schema_dispatch:schema_ref_to_string_expr(
Schema_ref,
Accessor,
erlang:element(2, Ctx)
).
-file("src/oaspec/codegen/client_request.gleam", 1056).
?DOC(
" Return a function expression that converts an array item to String.\n"
" Used in generated code: `list.map(param, <fn>)`.\n"
).
-spec array_item_to_string_fn(
oaspec@openapi@schema:schema_ref(),
oaspec@codegen@context:context()
) -> binary().
array_item_to_string_fn(Items, Ctx) ->
oaspec@codegen@schema_dispatch:to_string_fn(Items, erlang:element(2, Ctx)).
-file("src/oaspec/codegen/client_request.gleam", 773).
?DOC(" Generate exploded array query parameter: tags=a&tags=b\n").
-spec generate_exploded_array_query_param(
gleam@string_tree:string_tree(),
oaspec@openapi@spec:parameter(oaspec@openapi@spec:resolved()),
binary(),
oaspec@codegen@context:context()
) -> gleam@string_tree:string_tree().
generate_exploded_array_query_param(Sb, Param, Param_name, Ctx) ->
Item_to_str = case erlang:element(6, Param) of
{parameter_schema, {inline, {array_schema, _, Items, _, _, _}}} ->
array_item_to_string_fn(Items, Ctx);
{parameter_schema, {reference, _, _} = Sr} ->
case oaspec@openapi@resolver:resolve_schema_ref(
Sr,
erlang:element(2, Ctx)
) of
{ok, {array_schema, _, Items@1, _, _, _}} ->
array_item_to_string_fn(Items@1, Ctx);
_ ->
<<"fn(x) { x }"/utf8>>
end;
_ ->
<<"fn(x) { x }"/utf8>>
end,
case erlang:element(5, Param) of
true ->
_pipe = Sb,
_pipe@1 = oaspec@util@string_extra:indent(
_pipe,
1,
<<<<"let query_parts = list.fold("/utf8, Param_name/binary>>/binary,
", query_parts, fn(acc, item) {"/utf8>>
),
_pipe@2 = oaspec@util@string_extra:indent(
_pipe@1,
2,
<<<<<<<<"[\""/utf8, (erlang:element(2, Param))/binary>>/binary,
"=\" <> uri.percent_encode("/utf8>>/binary,
Item_to_str/binary>>/binary,
"(item)), ..acc]"/utf8>>
),
oaspec@util@string_extra:indent(_pipe@2, 1, <<"})"/utf8>>);
false ->
_pipe@3 = Sb,
_pipe@4 = oaspec@util@string_extra:indent(
_pipe@3,
1,
<<<<"let query_parts = case "/utf8, Param_name/binary>>/binary,
" {"/utf8>>
),
_pipe@5 = oaspec@util@string_extra:indent(
_pipe@4,
2,
<<"Some(items) -> list.fold(items, query_parts, fn(acc, item) {"/utf8>>
),
_pipe@6 = oaspec@util@string_extra:indent(
_pipe@5,
3,
<<<<<<<<"[\""/utf8, (erlang:element(2, Param))/binary>>/binary,
"=\" <> uri.percent_encode("/utf8>>/binary,
Item_to_str/binary>>/binary,
"(item)), ..acc]"/utf8>>
),
_pipe@7 = oaspec@util@string_extra:indent(_pipe@6, 2, <<"})"/utf8>>),
_pipe@8 = oaspec@util@string_extra:indent(
_pipe@7,
2,
<<"None -> query_parts"/utf8>>
),
oaspec@util@string_extra:indent(_pipe@8, 1, <<"}"/utf8>>)
end.
-file("src/oaspec/codegen/client_request.gleam", 1061).
?DOC(" Convert a deepObject array item to a string expression.\n").
-spec deep_object_array_item_to_string(
oaspec@openapi@schema:schema_ref(),
oaspec@codegen@context:context()
) -> binary().
deep_object_array_item_to_string(Prop_ref, Ctx) ->
case Prop_ref of
{inline, {array_schema, _, Items, _, _, _}} ->
oaspec@codegen@schema_dispatch:schema_ref_to_string_expr(
Items,
<<"item"/utf8>>,
erlang:element(2, Ctx)
);
_ ->
<<"item"/utf8>>
end.
-file("src/oaspec/codegen/client_request.gleam", 846).
?DOC(" Generate deepObject-style query parameters: key[prop]=value for each property.\n").
-spec generate_deep_object_query_param(
gleam@string_tree:string_tree(),
oaspec@openapi@spec:parameter(oaspec@openapi@spec:resolved()),
binary(),
oaspec@codegen@context:context()
) -> gleam@string_tree:string_tree().
generate_deep_object_query_param(Sb, Param, Param_name, Ctx) ->
Properties@2 = case erlang:element(6, Param) of
{parameter_schema, {reference, _, _} = Schema_ref} ->
case oaspec@openapi@resolver:resolve_schema_ref(
Schema_ref,
erlang:element(2, Ctx)
) of
{ok, {object_schema, _, Properties, Required, _, _, _}} ->
{oaspec@codegen@ir_build:sorted_entries(Properties),
Required};
_ ->
{[], []}
end;
{parameter_schema,
{inline, {object_schema, _, Properties@1, Required@1, _, _, _}}} ->
{oaspec@codegen@ir_build:sorted_entries(Properties@1), Required@1};
_ ->
{[], []}
end,
{Props, Required_fields} = Properties@2,
case erlang:element(5, Param) of
true ->
gleam@list:fold(
Props,
Sb,
fun(Sb@1, Entry) ->
{Prop_name, Prop_ref} = Entry,
Field_name = oaspec@util@naming:to_snake_case(Prop_name),
Accessor = <<<<Param_name/binary, "."/utf8>>/binary,
Field_name/binary>>,
Is_required = gleam@list:contains(
Required_fields,
Prop_name
),
Is_array = case Prop_ref of
{inline, {array_schema, _, _, _, _, _}} ->
true;
_ ->
false
end,
case {Is_array, Is_required} of
{true, true} ->
_pipe = Sb@1,
_pipe@1 = oaspec@util@string_extra:indent(
_pipe,
1,
<<<<"let query_parts = list.fold("/utf8,
Accessor/binary>>/binary,
", query_parts, fn(acc, item) {"/utf8>>
),
_pipe@2 = oaspec@util@string_extra:indent(
_pipe@1,
2,
<<<<<<<<<<<<"[\""/utf8,
(erlang:element(
2,
Param
))/binary>>/binary,
"["/utf8>>/binary,
Prop_name/binary>>/binary,
"]=\" <> uri.percent_encode("/utf8>>/binary,
(deep_object_array_item_to_string(
Prop_ref,
Ctx
))/binary>>/binary,
"), ..acc]"/utf8>>
),
oaspec@util@string_extra:indent(
_pipe@2,
1,
<<"})"/utf8>>
);
{true, false} ->
_pipe@3 = Sb@1,
_pipe@4 = oaspec@util@string_extra:indent(
_pipe@3,
1,
<<<<"let query_parts = case "/utf8,
Accessor/binary>>/binary,
" {"/utf8>>
),
_pipe@5 = oaspec@util@string_extra:indent(
_pipe@4,
2,
<<"Some(items) -> list.fold(items, query_parts, fn(acc, item) {"/utf8>>
),
_pipe@6 = oaspec@util@string_extra:indent(
_pipe@5,
3,
<<<<<<<<<<<<"[\""/utf8,
(erlang:element(
2,
Param
))/binary>>/binary,
"["/utf8>>/binary,
Prop_name/binary>>/binary,
"]=\" <> uri.percent_encode("/utf8>>/binary,
(deep_object_array_item_to_string(
Prop_ref,
Ctx
))/binary>>/binary,
"), ..acc]"/utf8>>
),
_pipe@7 = oaspec@util@string_extra:indent(
_pipe@6,
2,
<<"})"/utf8>>
),
_pipe@8 = oaspec@util@string_extra:indent(
_pipe@7,
2,
<<"None -> query_parts"/utf8>>
),
oaspec@util@string_extra:indent(
_pipe@8,
1,
<<"}"/utf8>>
);
{false, true} ->
To_str = schema_ref_to_string_expr(
Prop_ref,
Accessor,
Ctx
),
_pipe@9 = Sb@1,
oaspec@util@string_extra:indent(
_pipe@9,
1,
<<<<<<<<<<<<"let query_parts = [\""/utf8,
(erlang:element(
2,
Param
))/binary>>/binary,
"["/utf8>>/binary,
Prop_name/binary>>/binary,
"]=\" <> uri.percent_encode("/utf8>>/binary,
To_str/binary>>/binary,
"), ..query_parts]"/utf8>>
);
{false, false} ->
_pipe@10 = Sb@1,
_pipe@11 = oaspec@util@string_extra:indent(
_pipe@10,
1,
<<<<"let query_parts = case "/utf8,
Accessor/binary>>/binary,
" {"/utf8>>
),
_pipe@12 = oaspec@util@string_extra:indent(
_pipe@11,
2,
<<<<<<<<<<<<"Some(v) -> [\""/utf8,
(erlang:element(
2,
Param
))/binary>>/binary,
"["/utf8>>/binary,
Prop_name/binary>>/binary,
"]=\" <> uri.percent_encode("/utf8>>/binary,
(schema_ref_to_string_expr(
Prop_ref,
<<"v"/utf8>>,
Ctx
))/binary>>/binary,
"), ..query_parts]"/utf8>>
),
_pipe@13 = oaspec@util@string_extra:indent(
_pipe@12,
2,
<<"None -> query_parts"/utf8>>
),
oaspec@util@string_extra:indent(
_pipe@13,
1,
<<"}"/utf8>>
)
end
end
);
false ->
Sb@2 = begin
_pipe@14 = Sb,
oaspec@util@string_extra:indent(
_pipe@14,
1,
<<<<"let query_parts = case "/utf8, Param_name/binary>>/binary,
" {"/utf8>>
)
end,
Sb@3 = begin
_pipe@15 = Sb@2,
oaspec@util@string_extra:indent(
_pipe@15,
2,
<<"Some(obj) -> {"/utf8>>
)
end,
Sb@4 = begin
_pipe@16 = Sb@3,
oaspec@util@string_extra:indent(
_pipe@16,
3,
<<"let qp = query_parts"/utf8>>
)
end,
Sb@6 = gleam@list:fold(
Props,
Sb@4,
fun(Sb@5, Entry@1) ->
{Prop_name@1, Prop_ref@1} = Entry@1,
Field_name@1 = oaspec@util@naming:to_snake_case(Prop_name@1),
Accessor@1 = <<"obj."/utf8, Field_name@1/binary>>,
Is_required@1 = gleam@list:contains(
Required_fields,
Prop_name@1
),
Is_array@1 = case Prop_ref@1 of
{inline, {array_schema, _, _, _, _, _}} ->
true;
_ ->
false
end,
case {Is_array@1, Is_required@1} of
{true, true} ->
_pipe@17 = Sb@5,
_pipe@18 = oaspec@util@string_extra:indent(
_pipe@17,
3,
<<<<"let qp = list.fold("/utf8,
Accessor@1/binary>>/binary,
", qp, fn(acc, item) {"/utf8>>
),
_pipe@19 = oaspec@util@string_extra:indent(
_pipe@18,
4,
<<<<<<<<<<<<"[\""/utf8,
(erlang:element(
2,
Param
))/binary>>/binary,
"["/utf8>>/binary,
Prop_name@1/binary>>/binary,
"]=\" <> uri.percent_encode("/utf8>>/binary,
(deep_object_array_item_to_string(
Prop_ref@1,
Ctx
))/binary>>/binary,
"), ..acc]"/utf8>>
),
oaspec@util@string_extra:indent(
_pipe@19,
3,
<<"})"/utf8>>
);
{true, false} ->
_pipe@20 = Sb@5,
_pipe@21 = oaspec@util@string_extra:indent(
_pipe@20,
3,
<<<<"let qp = case "/utf8, Accessor@1/binary>>/binary,
" {"/utf8>>
),
_pipe@22 = oaspec@util@string_extra:indent(
_pipe@21,
4,
<<"Some(items) -> list.fold(items, qp, fn(acc, item) {"/utf8>>
),
_pipe@23 = oaspec@util@string_extra:indent(
_pipe@22,
5,
<<<<<<<<<<<<"[\""/utf8,
(erlang:element(
2,
Param
))/binary>>/binary,
"["/utf8>>/binary,
Prop_name@1/binary>>/binary,
"]=\" <> uri.percent_encode("/utf8>>/binary,
(deep_object_array_item_to_string(
Prop_ref@1,
Ctx
))/binary>>/binary,
"), ..acc]"/utf8>>
),
_pipe@24 = oaspec@util@string_extra:indent(
_pipe@23,
4,
<<"})"/utf8>>
),
_pipe@25 = oaspec@util@string_extra:indent(
_pipe@24,
4,
<<"None -> qp"/utf8>>
),
oaspec@util@string_extra:indent(
_pipe@25,
3,
<<"}"/utf8>>
);
{false, true} ->
To_str@1 = schema_ref_to_string_expr(
Prop_ref@1,
Accessor@1,
Ctx
),
_pipe@26 = Sb@5,
oaspec@util@string_extra:indent(
_pipe@26,
3,
<<<<<<<<<<<<"let qp = [\""/utf8,
(erlang:element(
2,
Param
))/binary>>/binary,
"["/utf8>>/binary,
Prop_name@1/binary>>/binary,
"]=\" <> uri.percent_encode("/utf8>>/binary,
To_str@1/binary>>/binary,
"), ..qp]"/utf8>>
);
{false, false} ->
_pipe@27 = Sb@5,
_pipe@28 = oaspec@util@string_extra:indent(
_pipe@27,
3,
<<<<"let qp = case "/utf8, Accessor@1/binary>>/binary,
" {"/utf8>>
),
_pipe@29 = oaspec@util@string_extra:indent(
_pipe@28,
4,
<<<<<<<<<<<<"Some(v) -> [\""/utf8,
(erlang:element(
2,
Param
))/binary>>/binary,
"["/utf8>>/binary,
Prop_name@1/binary>>/binary,
"]=\" <> uri.percent_encode("/utf8>>/binary,
(schema_ref_to_string_expr(
Prop_ref@1,
<<"v"/utf8>>,
Ctx
))/binary>>/binary,
"), ..qp]"/utf8>>
),
_pipe@30 = oaspec@util@string_extra:indent(
_pipe@29,
4,
<<"None -> qp"/utf8>>
),
oaspec@util@string_extra:indent(
_pipe@30,
3,
<<"}"/utf8>>
)
end
end
),
Sb@7 = begin
_pipe@31 = Sb@6,
oaspec@util@string_extra:indent(_pipe@31, 3, <<"qp"/utf8>>)
end,
Sb@8 = begin
_pipe@32 = Sb@7,
oaspec@util@string_extra:indent(_pipe@32, 2, <<"}"/utf8>>)
end,
Sb@9 = begin
_pipe@33 = Sb@8,
oaspec@util@string_extra:indent(
_pipe@33,
2,
<<"None -> query_parts"/utf8>>
)
end,
_pipe@34 = Sb@9,
oaspec@util@string_extra:indent(_pipe@34, 1, <<"}"/utf8>>)
end.