Packages
oaspec
0.26.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@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([build_param_field_names/1, field_name_for/2, build_request_object_call_args/5, 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, generate_multipart_body/4, generate_form_urlencoded_body/4, is_exploded_array_param/2, is_delimited_array_param/2, is_deep_object_param/2, generate_delimited_array_query_param/5, generate_exploded_array_query_param/4, 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", 26).
?DOC(
" Build a `(name, in)` → deduped-field-name map for a single operation.\n"
" The dedup order matches the spec's parameter order, so all codegen\n"
" callers that use this map agree on the final field names.\n"
).
-spec build_param_field_names(
oaspec@openapi@spec:operation(oaspec@openapi@spec:resolved())
) -> gleam@dict:dict({binary(), oaspec@openapi@spec:parameter_in()}, binary()).
build_param_field_names(Operation) ->
Resolved = gleam@list:filter_map(
erlang:element(6, Operation),
fun(R) -> case R of
{value, P} ->
{ok, P};
_ ->
{error, nil}
end end
),
Deduped = oaspec@openapi@dedup:dedup_param_field_names(Resolved),
_pipe = gleam@list:zip(Resolved, Deduped),
gleam@list:fold(
_pipe,
maps:new(),
fun(Acc, Pair) ->
{Param, Name} = Pair,
gleam@dict:insert(
Acc,
{erlang:element(2, Param), erlang:element(3, Param)},
Name
)
end
).
-file("src/oaspec/codegen/client_request.gleam", 48).
?DOC(
" Look up the deduped field name for a parameter. The map is built from\n"
" the same operation the caller iterates, so the lookup always hits —\n"
" the fallback is just a safety net that keeps the output valid Gleam\n"
" if a caller ever passes a mismatched map.\n"
).
-spec field_name_for(
gleam@dict:dict({binary(), oaspec@openapi@spec:parameter_in()}, binary()),
oaspec@openapi@spec:parameter(oaspec@openapi@spec:resolved())
) -> binary().
field_name_for(Map, Param) ->
case gleam_stdlib:map_get(
Map,
{erlang:element(2, Param), erlang:element(3, Param)}
) of
{ok, Name} ->
Name;
{error, _} ->
oaspec@util@naming:to_snake_case(erlang:element(2, Param))
end.
-file("src/oaspec/codegen/client_request.gleam", 64).
?DOC(
" Build the call-site argument list for the `_with_request` wrapper that\n"
" unpacks a `request_types.*Request` record into the flat client function\n"
" it delegates to. Returns `None` if the operation uses a multi-content\n"
" body (where the flat API also takes a `content_type` argument that the\n"
" request type does not carry).\n"
).
-spec build_request_object_call_args(
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())
) -> gleam@option:option(binary()).
build_request_object_call_args(
Path_params,
Query_params,
Header_params,
Cookie_params,
Operation
) ->
All_params = begin
_pipe = lists:append(Path_params, Query_params),
_pipe@1 = lists:append(_pipe, Header_params),
lists:append(_pipe@1, Cookie_params)
end,
Has_body = case erlang:element(7, Operation) of
{some, _} ->
true;
none ->
false
end,
case {gleam@list:is_empty(All_params), Has_body} of
{true, false} ->
none;
{_, _} ->
Field_names = build_param_field_names(Operation),
Param_refs = gleam@list:map(
All_params,
fun(P) ->
<<"req."/utf8, (field_name_for(Field_names, P))/binary>>
end
),
case erlang:element(7, Operation) of
{some, {value, Rb}} ->
Content_entries = oaspec@codegen@ir_build:sorted_entries(
erlang:element(3, Rb)
),
case Content_entries of
[_, _ | _] ->
none;
_ ->
{some,
gleam@string:join(
lists:append(
Param_refs,
[<<"req.body"/utf8>>]
),
<<", "/utf8>>
)}
end;
_ ->
{some, gleam@string:join(Param_refs, <<", "/utf8>>)}
end
end.
-file("src/oaspec/codegen/client_request.gleam", 145).
?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),
oaspec@codegen@context:spec(Ctx)
),
case erlang:element(5, Param) of
true ->
Base;
false ->
<<<<"Option("/utf8, Base/binary>>/binary, ")"/utf8>>
end.
-file("src/oaspec/codegen/client_request.gleam", 158).
?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,
oaspec@codegen@context:spec(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,
oaspec@codegen@context:spec(Ctx)
) of
{ok, {array_schema, _, Items@1, _, _, _}} ->
Item_to_str@1 = oaspec@codegen@schema_dispatch:to_string_fn(
Items@1,
oaspec@codegen@context:spec(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,
oaspec@codegen@context:spec(Ctx)
)
end;
_ ->
Param_name
end.
-file("src/oaspec/codegen/client_request.gleam", 198).
?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", 207).
?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,
oaspec@codegen@context:spec(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,
oaspec@codegen@context:spec(Ctx)
) of
{ok, {array_schema, _, Items@1, _, _, _}} ->
Item_to_str@1 = oaspec@codegen@schema_dispatch:to_string_fn(
Items@1,
oaspec@codegen@context:spec(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>>,
oaspec@codegen@context:spec(Ctx)
)
end;
_ ->
<<"v"/utf8>>
end.
-file("src/oaspec/codegen/client_request.gleam", 237).
?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", 102).
?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,
Field_names = build_param_field_names(Operation),
Param_strs = gleam@list:map(
All_params,
fun(P) ->
Param_name = field_name_for(Field_names, P),
Param_type = param_to_type(P, Ctx),
<<<<<<", "/utf8, Param_name/binary>>/binary, ": "/utf8>>/binary,
Param_type/binary>>
end
),
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", 259).
?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", 398).
-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,
oaspec@codegen@context:spec(Ctx)
) of
{ok, {string_schema, _, {some, <<"binary"/utf8>>}, _, _, _, _}} ->
true;
_ ->
false
end;
_ ->
false
end.
-file("src/oaspec/codegen/client_request.gleam", 413).
-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,
oaspec@codegen@context:spec(Ctx)
),
case Result of
<<"fn(x) { x }"/utf8>> ->
<<""/utf8>>;
_ ->
Result
end.
-file("src/oaspec/codegen/client_request.gleam", 291).
?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,
oaspec@codegen@context:spec(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", 427).
?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>>,
oaspec@codegen@context:spec(Ctx)
);
_ ->
<<"string.inspect(item)"/utf8>>
end.
-file("src/oaspec/codegen/client_request.gleam", 581).
?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,
oaspec@codegen@context:spec(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,
oaspec@codegen@context:spec(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", 444).
?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,
oaspec@codegen@context:spec(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,
oaspec@codegen@context:spec(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", 684).
?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,
oaspec@codegen@context:spec(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,
oaspec@codegen@context:spec(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,
oaspec@codegen@context:spec(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", 845).
?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,
oaspec@codegen@context:spec(Ctx)
) of
{ok, {array_schema, _, _, _, _, _}} ->
true;
_ ->
false
end;
_ ->
false
end,
case Is_array of
false ->
false;
true ->
oaspec@codegen@operation_ir:effective_explode(Param)
end.
-file("src/oaspec/codegen/client_request.gleam", 867).
?DOC(
" Returns Some(joiner) if the parameter is a non-exploded delimited array\n"
" (pipeDelimited or spaceDelimited). Returns None for everything else\n"
" including form arrays — we keep that on the existing path.\n"
).
-spec is_delimited_array_param(
oaspec@openapi@spec:parameter(oaspec@openapi@spec:resolved()),
oaspec@codegen@context:context()
) -> gleam@option:option(binary()).
is_delimited_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,
oaspec@codegen@context:spec(Ctx)
) of
{ok, {array_schema, _, _, _, _, _}} ->
true;
_ ->
false
end;
_ ->
false
end,
Is_non_exploded = not oaspec@codegen@operation_ir:effective_explode(Param),
case {Is_array, Is_non_exploded, erlang:element(7, Param)} of
{true, true, {some, pipe_delimited_style}} ->
{some,
oaspec@codegen@operation_ir:delimiter_for_style(
erlang:element(7, Param)
)};
{true, true, {some, space_delimited_style}} ->
{some,
oaspec@codegen@operation_ir:delimiter_for_style(
erlang:element(7, Param)
)};
{_, _, _} ->
none
end.
-file("src/oaspec/codegen/client_request.gleam", 1017).
?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) ->
oaspec@codegen@operation_ir:is_deep_object_param(Param, Ctx).
-file("src/oaspec/codegen/client_request.gleam", 1225).
?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,
oaspec@codegen@context:spec(Ctx)
).
-file("src/oaspec/codegen/client_request.gleam", 1239).
?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,
oaspec@codegen@context:spec(Ctx)
).
-file("src/oaspec/codegen/client_request.gleam", 893).
?DOC(
" Generate non-exploded delimited array query parameter:\n"
" tags=a|b|c (pipeDelimited) or tags=a%20b%20c (spaceDelimited).\n"
).
-spec generate_delimited_array_query_param(
gleam@string_tree:string_tree(),
oaspec@openapi@spec:parameter(oaspec@openapi@spec:resolved()),
binary(),
binary(),
oaspec@codegen@context:context()
) -> gleam@string_tree:string_tree().
generate_delimited_array_query_param(Sb, Param, Param_name, Joiner, 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,
oaspec@codegen@context:spec(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 = case "/utf8, Param_name/binary>>/binary,
" {"/utf8>>
),
_pipe@2 = oaspec@util@string_extra:indent(
_pipe@1,
2,
<<"[] -> query_parts"/utf8>>
),
_pipe@3 = oaspec@util@string_extra:indent(
_pipe@2,
2,
<<"items -> {"/utf8>>
),
_pipe@4 = oaspec@util@string_extra:indent(
_pipe@3,
3,
<<<<<<<<"let joined = string.join(list.map(items, "/utf8,
Item_to_str/binary>>/binary,
"), \""/utf8>>/binary,
Joiner/binary>>/binary,
"\")"/utf8>>
),
_pipe@5 = oaspec@util@string_extra:indent(
_pipe@4,
3,
<<<<"[\""/utf8, (erlang:element(2, Param))/binary>>/binary,
"=\" <> uri.percent_encode(joined), ..query_parts]"/utf8>>
),
_pipe@6 = oaspec@util@string_extra:indent(_pipe@5, 2, <<"}"/utf8>>),
oaspec@util@string_extra:indent(_pipe@6, 1, <<"}"/utf8>>);
false ->
_pipe@7 = Sb,
_pipe@8 = oaspec@util@string_extra:indent(
_pipe@7,
1,
<<<<"let query_parts = case "/utf8, Param_name/binary>>/binary,
" {"/utf8>>
),
_pipe@9 = oaspec@util@string_extra:indent(
_pipe@8,
2,
<<"Some([]) -> query_parts"/utf8>>
),
_pipe@10 = oaspec@util@string_extra:indent(
_pipe@9,
2,
<<"Some(items) -> {"/utf8>>
),
_pipe@11 = oaspec@util@string_extra:indent(
_pipe@10,
3,
<<<<<<<<"let joined = string.join(list.map(items, "/utf8,
Item_to_str/binary>>/binary,
"), \""/utf8>>/binary,
Joiner/binary>>/binary,
"\")"/utf8>>
),
_pipe@12 = oaspec@util@string_extra:indent(
_pipe@11,
3,
<<<<"[\""/utf8, (erlang:element(2, Param))/binary>>/binary,
"=\" <> uri.percent_encode(joined), ..query_parts]"/utf8>>
),
_pipe@13 = oaspec@util@string_extra:indent(
_pipe@12,
2,
<<"}"/utf8>>
),
_pipe@14 = oaspec@util@string_extra:indent(
_pipe@13,
2,
<<"None -> query_parts"/utf8>>
),
oaspec@util@string_extra:indent(_pipe@14, 1, <<"}"/utf8>>)
end.
-file("src/oaspec/codegen/client_request.gleam", 960).
?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,
oaspec@codegen@context:spec(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", 1244).
?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>>,
oaspec@codegen@context:spec(Ctx)
);
_ ->
<<"item"/utf8>>
end.
-file("src/oaspec/codegen/client_request.gleam", 1025).
?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,
oaspec@codegen@context:spec(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.