Current section

Files

Jump to
oas_generator src oas@generator.erl
Raw

src/oas@generator.erl

-module(oas@generator).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-define(FILEPATH, "src/oas/generator.gleam").
-export([name_for_gleam_type/1, name_for_gleam_field_or_var/1, gen_operations_and_top_files/3, json_decode_error_to_string/1, gen_schema_file/2, build/4]).
-export_type([module_/0]).
-type module_() :: schema | operations.
-file("src/oas/generator.gleam", 76).
-spec alias(binary(), glance:type()) -> glance:type_alias().
alias(To, Type_) ->
{type_alias, To, public, [], Type_}.
-file("src/oas/generator.gleam", 84).
-spec noop1(binary()) -> glance:expression().
noop1(Message) ->
{fn,
[{fn_parameter, {discarded, <<""/utf8>>}, none}],
none,
[{expression, {panic, {some, {string, Message}}}}]}.
-file("src/oas/generator.gleam", 454).
-spec access(binary(), binary()) -> glance:expression().
access(Object_or_mod, Field) ->
{field_access, {variable, Object_or_mod}, Field}.
-file("src/oas/generator.gleam", 458).
-spec call0(binary(), binary()) -> glance:expression().
call0(M, F) ->
{call, access(M, F), []}.
-file("src/oas/generator.gleam", 462).
-spec call1(binary(), binary(), glance:expression()) -> glance:expression().
call1(M, F, A) ->
{call, access(M, F), [{unlabelled_field, A}]}.
-file("src/oas/generator.gleam", 466).
-spec call2(binary(), binary(), glance:expression(), glance:expression()) -> glance:expression().
call2(M, F, A, B) ->
{call, access(M, F), [{unlabelled_field, A}, {unlabelled_field, B}]}.
-file("src/oas/generator.gleam", 224).
-spec always_decode() -> glance:expression().
always_decode() ->
call2(
<<"decode"/utf8>>,
<<"new_primitive_decoder"/utf8>>,
{string, <<"Nil"/utf8>>},
{fn,
[{fn_parameter, {discarded, <<""/utf8>>}, none}],
none,
[{expression,
{call,
{variable, <<"Ok"/utf8>>},
[{unlabelled_field, {variable, <<"Nil"/utf8>>}}]}}]}
).
-file("src/oas/generator.gleam", 239).
-spec never_decode() -> glance:expression().
never_decode() ->
call2(
<<"decode"/utf8>>,
<<"new_primitive_decoder"/utf8>>,
{string, <<"Never"/utf8>>},
{fn,
[{fn_parameter, {discarded, <<""/utf8>>}, none}],
none,
[{expression,
{call,
{variable, <<"Error"/utf8>>},
[{unlabelled_field, {variable, <<"Nil"/utf8>>}}]}}]}
).
-file("src/oas/generator.gleam", 254).
-spec dynamic_decode() -> glance:expression().
dynamic_decode() ->
call2(
<<"decode"/utf8>>,
<<"new_primitive_decoder"/utf8>>,
{string, <<"Dynamic"/utf8>>},
{fn,
[{fn_parameter, {named, <<"raw"/utf8>>}, none}],
none,
[{expression,
{call,
{variable, <<"Ok"/utf8>>},
[{unlabelled_field, {variable, <<"raw"/utf8>>}}]}}]}
).
-file("src/oas/generator.gleam", 473).
-spec pipe(glance:expression(), glance:expression()) -> glance:expression().
pipe(A, B) ->
{binary_operator, pipe, A, B}.
-file("src/oas/generator.gleam", 510).
-spec gen_method(gleam@http:method()) -> glance:expression().
gen_method(Method) ->
case Method of
get ->
access(<<"http"/utf8>>, <<"Get"/utf8>>);
post ->
access(<<"http"/utf8>>, <<"Post"/utf8>>);
head ->
access(<<"http"/utf8>>, <<"Head"/utf8>>);
put ->
access(<<"http"/utf8>>, <<"Put"/utf8>>);
delete ->
access(<<"http"/utf8>>, <<"Delete"/utf8>>);
trace ->
access(<<"http"/utf8>>, <<"Trace"/utf8>>);
connect ->
access(<<"http"/utf8>>, <<"Connect"/utf8>>);
options ->
access(<<"http"/utf8>>, <<"Options"/utf8>>);
patch ->
access(<<"http"/utf8>>, <<"Patch"/utf8>>);
{other, Other} ->
call1(<<"http"/utf8>>, <<"Other"/utf8>>, {string, Other})
end.
-file("src/oas/generator.gleam", 525).
-spec let_(binary(), glance:expression()) -> glance:statement().
let_(Var, Value) ->
{assignment, 'let', {pattern_variable, Var}, none, Value}.
-file("src/oas/generator.gleam", 543).
-spec get_structure_json_media(gleam@dict:dict(binary(), oas:media_type())) -> {list({gleam@option:option(binary()),
oas:media_type()}),
list({binary(), oas:media_type()})}.
get_structure_json_media(Content) ->
gleam@dict:fold(
Content,
{[], []},
fun(Acc, Key, Value) ->
{Known, Unknown} = Acc,
case Key of
<<"application/json"/utf8>> ->
{[{none, Value} | Known], Unknown};
<<"application/"/utf8, Rest/binary>> ->
case gleam@string:split_once(Rest, <<"+json"/utf8>>) of
{ok, {Pre, <<""/utf8>>}} ->
{[{{some, Pre}, Value} | Known], Unknown};
_ ->
{Known, [{Key, Value} | Unknown]}
end;
_ ->
{Known, [{Key, Value} | Unknown]}
end
end
).
-file("src/oas/generator.gleam", 734).
-spec replace_gleam_keywords(binary()) -> binary().
replace_gleam_keywords(Key) ->
case Key of
<<"type"/utf8>> ->
<<"type_"/utf8>>;
<<"auto"/utf8>> ->
<<"auto_"/utf8>>;
<<"import"/utf8>> ->
<<"import_"/utf8>>;
<<"base"/utf8>> ->
<<"base_"/utf8>>;
<<"path"/utf8>> ->
<<"path_"/utf8>>;
<<"method"/utf8>> ->
<<"method_"/utf8>>;
<<"token"/utf8>> ->
<<"token_"/utf8>>;
_ ->
Key
end.
-file("src/oas/generator.gleam", 753).
-spec replace_disallowed_charachters(binary()) -> binary().
replace_disallowed_charachters(In) ->
_pipe = In,
_pipe@1 = gleam@string:replace(_pipe, <<"/"/utf8>>, <<"_"/utf8>>),
gleam@string:replace(_pipe@1, <<"+"/utf8>>, <<"_"/utf8>>).
-file("src/oas/generator.gleam", 761).
-spec prefix_numbers(binary()) -> binary().
prefix_numbers(In) ->
Needs_prefix = gleam@list:any(
[<<"1"/utf8>>,
<<"2"/utf8>>,
<<"3"/utf8>>,
<<"4"/utf8>>,
<<"5"/utf8>>,
<<"6"/utf8>>,
<<"7"/utf8>>,
<<"8"/utf8>>,
<<"9"/utf8>>,
<<"0"/utf8>>],
fun(_capture) -> gleam_stdlib:string_starts_with(In, _capture) end
),
case Needs_prefix of
true ->
<<"n"/utf8, In/binary>>;
false ->
In
end.
-file("src/oas/generator.gleam", 773).
-spec prefix_signs(binary()) -> binary().
prefix_signs(In) ->
In@1 = case gleam_stdlib:string_starts_with(In, <<"-"/utf8>>) of
true ->
<<"negative"/utf8, In/binary>>;
false ->
In
end,
case gleam_stdlib:string_starts_with(In@1, <<"+"/utf8>>) of
true ->
<<"positive"/utf8, In@1/binary>>;
false ->
In@1
end.
-file("src/oas/generator.gleam", 784).
-spec name_for_gleam_type(binary()) -> binary().
name_for_gleam_type(In) ->
_pipe = In,
_pipe@1 = prefix_signs(_pipe),
_pipe@2 = justin:pascal_case(_pipe@1),
_pipe@3 = prefix_numbers(_pipe@2),
replace_disallowed_charachters(_pipe@3).
-file("src/oas/generator.gleam", 421).
-spec to_type(oas@generator@lift:schema(integer()), module_()) -> glance:type().
to_type(Lifted, Module) ->
case Lifted of
{named, <<"#/components/schemas/"/utf8, Inner/binary>>} ->
Mod = case Module of
schema ->
none;
_ ->
{some, <<"schema"/utf8>>}
end,
{named_type, name_for_gleam_type(Inner), Mod, []};
{named, Ref} ->
erlang:error(#{gleam_error => panic,
message => (<<"not referencing schema component ref: "/utf8,
Ref/binary>>),
file => <<?FILEPATH/utf8>>,
module => <<"oas/generator"/utf8>>,
function => <<"to_type"/utf8>>,
line => 431});
{primitive, Primitive} ->
case Primitive of
boolean ->
{named_type, <<"Bool"/utf8>>, none, []};
integer ->
{named_type, <<"Int"/utf8>>, none, []};
number ->
{named_type, <<"Float"/utf8>>, none, []};
string ->
{named_type, <<"String"/utf8>>, none, []};
null ->
{named_type, <<"Null"/utf8>>, none, []};
always ->
{named_type,
<<"Dynamic"/utf8>>,
{some, <<"dynamic"/utf8>>},
[]};
never ->
{named_type, <<"Never"/utf8>>, none, []}
end;
{array, Items} ->
{named_type, <<"List"/utf8>>, none, [to_type(Items, Module)]};
{tuple, Items@1} ->
{tuple_type,
gleam@list:map(
Items@1,
fun(_capture) -> to_type(_capture, Module) end
)};
{compound, Index} ->
Type_ = <<"Internal"/utf8,
(erlang:integer_to_binary(Index))/binary>>,
{named_type, Type_, none, []};
unsupported ->
{named_type, <<"Dynamic"/utf8>>, {some, <<"dynamic"/utf8>>}, []}
end.
-file("src/oas/generator.gleam", 792).
-spec name_for_gleam_field_or_var(binary()) -> binary().
name_for_gleam_field_or_var(In) ->
_pipe = In,
_pipe@1 = prefix_signs(_pipe),
_pipe@2 = justin:snake_case(_pipe@1),
_pipe@3 = prefix_numbers(_pipe@2),
_pipe@4 = replace_disallowed_charachters(_pipe@3),
replace_gleam_keywords(_pipe@4).
-file("src/oas/generator.gleam", 25).
-spec concat_path(list(oas:segment()), binary()) -> glance:expression().
concat_path(Match, Root) ->
{Str, Rev} = gleam@list:fold(
Match,
{Root, []},
fun(Acc, Segment) ->
{Current, Prev} = Acc,
case Segment of
{fixed_segment, S} ->
{<<<<Current/binary, "/"/utf8>>/binary, S/binary>>, Prev};
{match_segment, Name, Schema} ->
case Schema of
{string, _, _, _, _, _, _, _, _} ->
Prev@1 = [{string, <<Current/binary, "/"/utf8>>} |
Prev],
Prev@2 = [{variable,
name_for_gleam_field_or_var(Name)} |
Prev@1],
{<<""/utf8>>, Prev@2};
{integer, _, _, _, _, _, _, _, _, _} ->
Prev@3 = [{string, <<Current/binary, "/"/utf8>>} |
Prev],
Prev@4 = [call1(
<<"int"/utf8>>,
<<"to_string"/utf8>>,
{variable,
name_for_gleam_field_or_var(Name)}
) |
Prev@3],
{<<""/utf8>>, Prev@4};
_ ->
Prev@5 = [{string, <<Current/binary, "/"/utf8>>} |
Prev],
Prev@6 = [{variable,
name_for_gleam_field_or_var(Name)} |
Prev@5],
{<<""/utf8>>, Prev@6}
end
end
end
),
Parts = case Str of
<<""/utf8>> ->
Rev;
_ ->
[{string, Str} | Rev]
end,
A@1 = case gleam@list:reduce(
Parts,
fun(Post, Pre) -> {binary_operator, concatenate, Pre, Post} end
) of
{ok, A} -> A;
_assert_fail ->
erlang:error(#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
file => <<?FILEPATH/utf8>>,
module => <<"oas/generator"/utf8>>,
function => <<"concat_path"/utf8>>,
line => 69,
value => _assert_fail,
start => 1701,
'end' => 1824,
pattern_start => 1712,
pattern_end => 1717})
end,
A@1.
-file("src/oas/generator.gleam", 80).
-spec encode_fn(binary()) -> binary().
encode_fn(Name) ->
name_for_gleam_field_or_var(<<Name/binary, "_encode"/utf8>>).
-file("src/oas/generator.gleam", 220).
-spec decoder(binary()) -> binary().
decoder(Name) ->
name_for_gleam_field_or_var(<<Name/binary, "_decoder"/utf8>>).
-file("src/oas/generator.gleam", 401).
-spec custom_type(
binary(),
list({binary(), {oas@generator@lift:schema(integer()), boolean()}}),
list(binary()),
module_()
) -> glance:custom_type().
custom_type(Name, Properties, Required, Module) ->
Fields = gleam@list:map(
Properties,
fun(Property) ->
{Key, {Schema, Nullable}} = Property,
Type_ = to_type(Schema, Module),
{labelled_variant_field,
case not gleam@list:contains(Required, Key) orelse Nullable of
false ->
Type_;
true ->
{named_type, <<"Option"/utf8>>, none, [Type_]}
end,
name_for_gleam_field_or_var(Key)}
end
),
Name@1 = name_for_gleam_type(Name),
{custom_type, Name@1, public, false, [], [{variant, Name@1, Fields}]}.
-file("src/oas/generator.gleam", 477).
-spec query_to_parts(
list({binary(), boolean(), oas:ref(oas:schema())}),
oas:components()
) -> {list(glance:function_parameter()), list(glance:expression())}.
query_to_parts(Parameters, Components) ->
_pipe = gleam@list:map(
Parameters,
fun(P) ->
{Key, Required, Schema} = P,
Schema@1 = oas:fetch_schema(Schema, erlang:element(2, Components)),
Key@1 = name_for_gleam_field_or_var(Key),
Arg = {function_parameter, {some, Key@1}, {named, Key@1}, none},
Var = {variable, Key@1},
Mapper = case Schema@1 of
{boolean, _, _, _, _} ->
{some, access(<<"bool"/utf8>>, <<"to_string"/utf8>>)};
{integer, _, _, _, _, _, _, _, _, _} ->
{some, access(<<"int"/utf8>>, <<"to_string"/utf8>>)};
{number, _, _, _, _, _, _, _, _, _} ->
{some, access(<<"float"/utf8>>, <<"to_string"/utf8>>)};
{string, _, _, _, _, _, _, _, _} ->
none;
_ ->
{some, noop1(<<"query parameter is not supported"/utf8>>)}
end,
Value = case Required of
true ->
call1(<<"option"/utf8>>, <<"Some"/utf8>>, case Mapper of
{some, M} ->
{call, M, [{unlabelled_field, Var}]};
none ->
Var
end);
false ->
case Mapper of
{some, Mapper@1} ->
call2(
<<"option"/utf8>>,
<<"map"/utf8>>,
Var,
Mapper@1
);
none ->
Var
end
end,
Tuple = {tuple, [{string, Key@1}, Value]},
{Arg, Tuple}
end
),
gleam@list:unzip(_pipe).
-file("src/oas/generator.gleam", 529).
-spec path_args(list(oas:segment())) -> list(glance:function_parameter()).
path_args(Match) ->
gleam@list:filter_map(Match, fun(Segment) -> case Segment of
{fixed_segment, _} ->
{error, nil};
{match_segment, Name, _} ->
{ok,
{function_parameter,
none,
{named, name_for_gleam_field_or_var(Name)},
none}}
end end).
-file("src/oas/generator.gleam", 558).
-spec gen_request_for_op(
{gleam@http:method(), oas:operation()},
binary(),
list(oas:ref(oas:parameter())),
oas:components()
) -> {glance:function_(), glance:function_()}.
gen_request_for_op(Op_entry, Pattern, Path_parameters, Components) ->
{Method, Op} = Op_entry,
{operation, _, _, _, Id, Op_parameters, _, _} = Op,
Id@1 = name_for_gleam_field_or_var(Id),
Parameters = lists:append(Op_parameters, Path_parameters),
Parameters@1 = gleam@list:map(
Parameters,
fun(_capture) ->
oas:fetch_parameter(_capture, erlang:element(4, Components))
end
),
{Q_args, Q_params} = query_to_parts(
oas:query_parameters(Parameters@1),
Components
),
Match@1 = case oas:gather_match(Pattern, Parameters@1, Components) of
{ok, Match} ->
Match;
{error, _} ->
erlang:error(#{gleam_error => panic,
message => <<"could not find all parameters in match"/utf8>>,
file => <<?FILEPATH/utf8>>,
module => <<"oas/generator"/utf8>>,
function => <<"gen_request_for_op"/utf8>>,
line => 578})
end,
Body@1 = case erlang:element(7, Op) of
{some, Body} ->
{request_body, _, Content, _} = oas:fetch_request_body(
Body,
erlang:element(5, Components)
),
{Known, Unknown} = get_structure_json_media(Content),
case {Known, Unknown} of
{[{_, {media_type, Schema}}], _} ->
case Schema of
{ref,
<<"#/components/schemas/"/utf8, Name/binary>>,
_,
_} ->
Arg = name_for_gleam_field_or_var(Name),
Encode = call1(
<<"utils"/utf8>>,
<<"json_to_bits"/utf8>>,
call1(
<<"schema"/utf8>>,
encode_fn(Name),
{variable, Arg}
)
),
{some, {Arg, Encode}};
_ ->
{some,
{<<"data"/utf8>>, {variable, <<"data"/utf8>>}}}
end;
{[], []} ->
none;
{[], [{Unknown@1, _}]} ->
gleam_stdlib:println(
<<"unknown content type: "/utf8, Unknown@1/binary>>
),
none;
{_, _} ->
gleam_stdlib:println(
<<"multiple content types not supported"/utf8>>
),
none
end;
none ->
none
end,
Parameters@2 = begin
_pipe = path_args(Match@1),
_pipe@1 = lists:append(_pipe, case Body@1 of
{some, {Arg@1, _}} ->
[{function_parameter, none, {named, Arg@1}, none}];
none ->
[]
end),
lists:append(_pipe@1, Q_args)
end,
Op_request = <<Id@1/binary, "_request"/utf8>>,
Op_response = <<Id@1/binary, "_response"/utf8>>,
Req_fn = {function,
Op_request,
public,
[{function_parameter, none, {named, <<"base"/utf8>>}, none} |
Parameters@2],
none,
[let_(<<"method"/utf8>>, gen_method(Method)),
let_(<<"path"/utf8>>, concat_path(Match@1, <<""/utf8>>)),
let_(<<"query"/utf8>>, {list, Q_params, none}) |
case Body@1 of
{some, {_, Encode@1}} ->
[let_(<<"body"/utf8>>, Encode@1),
{expression,
pipe(
{variable, <<"base"/utf8>>},
pipe(
call1(
<<"utils"/utf8>>,
<<"set_method"/utf8>>,
{variable, <<"method"/utf8>>}
),
pipe(
call1(
<<"utils"/utf8>>,
<<"append_path"/utf8>>,
{variable, <<"path"/utf8>>}
),
pipe(
call1(
<<"utils"/utf8>>,
<<"set_query"/utf8>>,
{variable, <<"query"/utf8>>}
),
call2(
<<"utils"/utf8>>,
<<"set_body"/utf8>>,
{string,
<<"application/json"/utf8>>},
{variable, <<"body"/utf8>>}
)
)
)
)
)}];
none ->
[{expression,
pipe(
{variable, <<"base"/utf8>>},
pipe(
call1(
<<"utils"/utf8>>,
<<"set_method"/utf8>>,
{variable, <<"method"/utf8>>}
),
pipe(
call1(
<<"utils"/utf8>>,
<<"append_path"/utf8>>,
{variable, <<"path"/utf8>>}
),
call1(
<<"utils"/utf8>>,
<<"set_query"/utf8>>,
{variable, <<"query"/utf8>>}
)
)
)
)}]
end],
{span, 0, 0}},
Fn_ = {function,
Id@1,
public,
[{function_parameter, none, {named, <<"token"/utf8>>}, none} |
Parameters@2],
none,
[let_(
<<"request"/utf8>>,
{call,
{variable, <<"base_request"/utf8>>},
[{unlabelled_field, {variable, <<"token"/utf8>>}}]}
),
let_(
<<"request"/utf8>>,
{call,
access(<<"operations"/utf8>>, Op_request),
[{unlabelled_field, {variable, <<"request"/utf8>>}} |
gleam@list:map(
Parameters@2,
fun(P) ->
Name@2 = case P of
{function_parameter, _, {named, Name@1}, _} -> Name@1;
_assert_fail ->
erlang:error(
#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
file => <<?FILEPATH/utf8>>,
module => <<"oas/generator"/utf8>>,
function => <<"gen_request_for_op"/utf8>>,
line => 703,
value => _assert_fail,
start => 20646,
'end' => 20731,
pattern_start => 20657,
pattern_end => 20711}
)
end,
{unlabelled_field, {variable, Name@2}}
end
)]}
),
{use,
[{pattern_variable, <<"response"/utf8>>}],
call1(
<<"t"/utf8>>,
<<"do"/utf8>>,
call1(
<<"t"/utf8>>,
<<"fetch"/utf8>>,
{variable, <<"request"/utf8>>}
)
)},
{use,
[{pattern_variable, <<"data"/utf8>>}],
call1(
<<"t"/utf8>>,
<<"try"/utf8>>,
{call,
{variable, <<"handle_errors"/utf8>>},
[{unlabelled_field,
call1(
<<"operations"/utf8>>,
Op_response,
{variable, <<"response"/utf8>>}
)}]}
)},
{expression,
call1(
<<"t"/utf8>>,
<<"Done"/utf8>>,
{variable, <<"data"/utf8>>}
)}],
{span, 0, 0}},
{Fn_, Req_fn}.
-file("src/oas/generator.gleam", 846).
-spec to_decoder(oas@generator@lift:schema(integer()), module_()) -> glance:expression().
to_decoder(Lifted, Module) ->
case Lifted of
{named, <<"#/components/schemas/"/utf8, Name/binary>>} ->
Func = name_for_gleam_field_or_var(<<Name/binary, "_decoder"/utf8>>),
case Module of
schema ->
{call, {variable, Func}, []};
_ ->
call0(<<"schema"/utf8>>, Func)
end;
{named, Ref} ->
erlang:error(#{gleam_error => panic,
message => (<<"not referencing schema component ref: "/utf8,
Ref/binary>>),
file => <<?FILEPATH/utf8>>,
module => <<"oas/generator"/utf8>>,
function => <<"to_decoder"/utf8>>,
line => 856});
{primitive, Primitive} ->
case Primitive of
boolean ->
access(<<"decode"/utf8>>, <<"bool"/utf8>>);
integer ->
access(<<"decode"/utf8>>, <<"int"/utf8>>);
number ->
access(<<"decode"/utf8>>, <<"float"/utf8>>);
string ->
access(<<"decode"/utf8>>, <<"string"/utf8>>);
null ->
always_decode();
always ->
dynamic_decode();
never ->
never_decode()
end;
{tuple, Items} ->
Uses = gleam@list:index_map(
Items,
fun(Item, Index) ->
{use,
[{pattern_variable,
<<"e"/utf8,
(erlang:integer_to_binary(Index))/binary>>}],
call1(
<<"decode"/utf8>>,
<<"then"/utf8>>,
to_decoder(Item, Module)
)}
end
),
Vars = gleam@list:index_map(
Items,
fun(_, Index@1) ->
{variable,
<<"e"/utf8, (erlang:integer_to_binary(Index@1))/binary>>}
end
),
{block,
lists:append(
Uses,
[{expression,
call1(
<<"decode"/utf8>>,
<<"success"/utf8>>,
{tuple, Vars}
)}]
)};
{array, Items@1} ->
call1(
<<"decode"/utf8>>,
<<"list"/utf8>>,
to_decoder(Items@1, Module)
);
{compound, Index@2} ->
Func@1 = <<<<"internal_"/utf8,
(erlang:integer_to_binary(Index@2))/binary>>/binary,
"_decoder"/utf8>>,
{call, {variable, Func@1}, []};
unsupported ->
dynamic_decode()
end.
-file("src/oas/generator.gleam", 283).
-spec gen_top_decoder_needs_name(
binary(),
oas@generator@lift:schema(oas@generator@lift:fields()),
module_()
) -> list(glance:statement()).
gen_top_decoder_needs_name(Name, Top, Module) ->
case Top of
{named, N} ->
[{expression, to_decoder({named, N}, Module)}];
{primitive, P} ->
[{expression, to_decoder({primitive, P}, Module)}];
{array, Items} ->
[{expression, to_decoder({array, Items}, Module)}];
{tuple, Items@1} ->
case to_decoder({tuple, Items@1}, Module) of
{block, Statements} ->
Statements;
Other ->
[{expression, Other}]
end;
{compound, {fields, Properties, Required}} ->
Type_ = name_for_gleam_type(Name),
{Fields, Cons} = begin
_pipe = gleam@list:map(
Properties,
fun(Property) ->
{Key, {Schema, Nullable}} = Property,
Is_optional = not gleam@list:contains(Required, Key)
orelse Nullable,
Field_decoder = to_decoder(Schema, Module),
{{use,
[{pattern_variable,
name_for_gleam_field_or_var(Key)}],
case Is_optional of
false ->
call2(
<<"decode"/utf8>>,
<<"field"/utf8>>,
{string, Key},
Field_decoder
);
true ->
{call,
access(
<<"decode"/utf8>>,
<<"optional_field"/utf8>>
),
[{unlabelled_field, {string, Key}},
{unlabelled_field,
{variable, <<"None"/utf8>>}},
{unlabelled_field,
call1(
<<"decode"/utf8>>,
<<"optional"/utf8>>,
Field_decoder
)}]}
end},
{labelled_field,
name_for_gleam_field_or_var(Key),
{variable, name_for_gleam_field_or_var(Key)}}}
end
),
gleam@list:unzip(_pipe)
end,
Final = {expression,
call1(
<<"decode"/utf8>>,
<<"success"/utf8>>,
case erlang:length(Cons) of
0 ->
{variable, Type_};
_ ->
{call, {variable, Type_}, Cons}
end
)},
lists:append(Fields, [Final]);
unsupported ->
[{expression, to_decoder(unsupported, Module)}]
end.
-file("src/oas/generator.gleam", 269).
-spec schema_to_decode_fn(
{binary(), oas@generator@lift:schema(oas@generator@lift:fields())}
) -> glance:function_().
schema_to_decode_fn(Entry) ->
{Name, Top} = Entry,
Body = gen_top_decoder_needs_name(Name, Top, schema),
{function, decoder(Name), public, [], none, Body, {span, 0, 0}}.
-file("src/oas/generator.gleam", 895).
-spec just_return_ok_nil(binary()) -> {glance:expression(),
gleam@option:option(any()),
boolean()}.
just_return_ok_nil(Wrapper) ->
Thing = begin
_pipe = {call,
{variable, Wrapper},
[{unlabelled_field, {variable, <<"Nil"/utf8>>}}]},
pipe(_pipe, {variable, <<"Ok"/utf8>>})
end,
{Thing, none, false}.
-file("src/oas/generator.gleam", 802).
-spec gen_content_handling(
binary(),
gleam@dict:dict(binary(), oas:media_type()),
binary()
) -> {glance:expression(), gleam@option:option(glance:custom_type()), boolean()}.
gen_content_handling(Operation_id, Content, Wrapper) ->
Module = operations,
{Known, Unknown} = get_structure_json_media(Content),
case {Known, Unknown} of
{[{_, {media_type, Schema}}], _} ->
{Decoder@1, Resp_type} = case oas@generator@lift:lift(Schema) of
{{named, N}, _, []} ->
{to_decoder({named, N}, Module), none};
{{primitive, P}, _, []} ->
{to_decoder({primitive, P}, Module), none};
{{array, A}, _, []} ->
{to_decoder({array, A}, Module), none};
{{compound, {fields, Parameters, Required}} = Top, _, []} ->
Name = <<Operation_id/binary, "_response"/utf8>>,
Type_ = custom_type(Name, Parameters, Required, operations),
Decoder = {block,
gen_top_decoder_needs_name(Name, Top, Module)},
{Decoder, {some, Type_}};
{_, _, _} ->
erlang:error(#{gleam_error => panic,
message => <<"dont support internal types at the top level"/utf8>>,
file => <<?FILEPATH/utf8>>,
module => <<"oas/generator"/utf8>>,
function => <<"gen_content_handling"/utf8>>,
line => 822})
end,
Action = begin
_pipe = call2(
<<"json"/utf8>>,
<<"parse_bits"/utf8>>,
{variable, <<"body"/utf8>>},
Decoder@1
),
pipe(
_pipe,
call1(
<<"result"/utf8>>,
<<"map"/utf8>>,
{variable, Wrapper}
)
)
end,
{Action, Resp_type, true};
{[], []} ->
just_return_ok_nil(Wrapper);
{[], [{Unknown@1, _}]} ->
gleam_stdlib:println(
<<"unknown content type: "/utf8, Unknown@1/binary>>
),
just_return_ok_nil(Wrapper);
{_, _} ->
gleam_stdlib:println(
<<"multiple content types not supported"/utf8>>
),
just_return_ok_nil(Wrapper)
end.
-file("src/oas/generator.gleam", 904).
-spec status_range(list({oas:status(), OUF}), integer(), integer()) -> list({integer(),
OUF}).
status_range(Responses, Above_equal, Bellow) ->
gleam@list:filter_map(
Responses,
fun(Response) ->
{Status, Response@1} = Response,
case Status of
{status, I} when (Above_equal =< I) andalso (I < Bellow) ->
{ok, {I, Response@1}};
_ ->
{error, nil}
end
end
).
-file("src/oas/generator.gleam", 914).
-spec gen_response({any(), oas:operation()}, oas:components()) -> {glance:function_(),
gleam@option:option(glance:custom_type())}.
gen_response(Operation, Components) ->
{_, Op} = Operation,
Op@1 = Op,
Responses = begin
_pipe = erlang:element(8, Op@1),
maps:to_list(_pipe)
end,
Default = gleam@list:find_map(
Responses,
fun(Response) ->
{Status, Response@1} = Response,
case Status of
default ->
{ok, Response@1};
_ ->
{error, nil}
end
end
),
{Default_branch, Resp_type, Used} = case Default of
{ok, Response@2} ->
{response, _, _, Content} = oas:fetch_response(
Response@2,
erlang:element(3, Components)
),
gen_content_handling(
erlang:element(5, Op@1),
Content,
<<"Error"/utf8>>
);
{error, nil} ->
case status_range(Responses, 400, 600) of
[{Status@1, First} | Rest] ->
case gleam@list:try_fold(
Rest,
[Status@1],
fun(Acc, This) ->
{Status@2, This@1} = This,
case {First, This@1} of
{{ref, A, _, _}, {ref, B, _, _}} when A =:= B ->
{ok, [Status@2 | Acc]};
{{inline, {response, _, _, A@1}},
{inline, {response, _, _, B@1}}} when A@1 =:= B@1 ->
{ok, [Status@2 | Acc]};
{_, _} ->
{error, nil}
end
end
) of
{ok, _} ->
{response, _, _, Content@1} = oas:fetch_response(
First,
erlang:element(3, Components)
),
gen_content_handling(
erlang:element(5, Op@1),
Content@1,
<<"Error"/utf8>>
);
{error, _} ->
Branch = begin
_pipe@1 = {variable, <<"response"/utf8>>},
_pipe@2 = pipe(
_pipe@1,
{variable, <<"Error"/utf8>>}
),
pipe(_pipe@2, {variable, <<"Ok"/utf8>>})
end,
{Branch, none, false}
end;
[] ->
Branch@1 = begin
_pipe@3 = {variable, <<"response"/utf8>>},
_pipe@4 = pipe(_pipe@3, {variable, <<"Error"/utf8>>}),
pipe(_pipe@4, {variable, <<"Ok"/utf8>>})
end,
{Branch@1, none, false}
end
end,
Default_clause = {clause,
[[{pattern_discard, <<""/utf8>>}]],
none,
Default_branch},
{Used@1, Response_type, Expected_clauses} = case begin
_pipe@5 = status_range(Responses, 200, 300),
gleam@list:sort(
_pipe@5,
fun(Ra, Rb) ->
gleam@int:compare(erlang:element(1, Ra), erlang:element(1, Rb))
end
)
end of
[] ->
{Used, Resp_type, []};
[{Status@3, First@1} | More] ->
case More of
[] ->
nil;
_ ->
gleam_stdlib:print(
<<"Doesn't support multiple ok statuses"/utf8>>
),
nil
end,
{response, _, _, Content@2} = oas:fetch_response(
First@1,
erlang:element(3, Components)
),
{Branch@2, Resp_type@1, U} = gen_content_handling(
erlang:element(5, Op@1),
Content@2,
<<"Ok"/utf8>>
),
Clause = {clause,
[[{pattern_int, erlang:integer_to_binary(Status@3)}]],
none,
Branch@2},
{Used orelse U, Resp_type@1, [Clause]}
end,
Response_handler = {function,
name_for_gleam_field_or_var(
<<(erlang:element(5, Op@1))/binary, "_response"/utf8>>
),
public,
[{function_parameter, none, {named, <<"response"/utf8>>}, none}],
none,
[{assignment,
'let',
{pattern_constructor,
{some, <<"response"/utf8>>},
<<".Response"/utf8>>,
[{shorthand_field, <<"status"/utf8>>} | case Used@1 of
true ->
[{shorthand_field, <<"body"/utf8>>}];
false ->
[]
end],
true},
none,
{variable, <<"response"/utf8>>}},
{expression,
{'case',
[{variable, <<"status"/utf8>>}],
lists:append(Expected_clauses, [Default_clause])}}],
{span, 0, 0}},
{Response_handler, Response_type}.
-file("src/oas/generator.gleam", 1042).
-spec gen_fns(binary(), oas:path_item(), oas:components(), list(binary())) -> list({{list(glance:function_()),
gleam@option:option(glance:custom_type())},
glance:function_()}).
gen_fns(Key, Path_item, Components, Exclude) ->
Operations = gleam@list:filter(
erlang:element(5, Path_item),
fun(Op) ->
not gleam@list:contains(
Exclude,
erlang:element(5, (erlang:element(2, Op)))
)
end
),
gleam@list:map(
Operations,
fun(Op@1) ->
{Fn_, Req_fn} = gen_request_for_op(
Op@1,
Key,
erlang:element(4, Path_item),
Components
),
{Response_handler, Response_type} = gen_response(Op@1, Components),
{{[Response_handler, Req_fn], Response_type}, Fn_}
end
).
-file("src/oas/generator.gleam", 1056).
-spec gen_ops({binary(), oas:path_item()}, oas:components(), list(binary())) -> list({{list(glance:function_()),
gleam@option:option(glance:custom_type())},
glance:function_()}).
gen_ops(Op, Components, Exclude) ->
{Key, Path} = Op,
gen_fns(Key, Path, Components, Exclude).
-file("src/oas/generator.gleam", 1062).
-spec defs(list(OXZ)) -> list(glance:definition(OXZ)).
defs(Xs) ->
gleam@list:map(Xs, fun(_capture) -> {definition, [], _capture} end).
-file("src/oas/generator.gleam", 1127).
-spec gen_operations_and_top_files(oas:document(), binary(), list(binary())) -> {binary(),
binary()}.
gen_operations_and_top_files(Spec, Provider, Exclude) ->
Paths = maps:to_list(erlang:element(6, Spec)),
Fs = gleam@list:flat_map(
Paths,
fun(_capture) -> gen_ops(_capture, erlang:element(7, Spec), Exclude) end
),
{Operation_functions, Top} = gleam@list:unzip(Fs),
{Operation_functions@1, Operation_types} = gleam@list:unzip(
Operation_functions
),
Operation_types@1 = gleam@list:filter_map(
Operation_types,
fun(_capture@1) -> gleam@option:to_result(_capture@1, nil) end
),
Operation_functions@2 = gleam@list:flatten(Operation_functions@1),
Modules = [<<Provider/binary, "/utils"/utf8>>,
<<Provider/binary, "/schema"/utf8>>,
<<"gleam/http"/utf8>>,
<<"gleam/http/response"/utf8>>,
<<"gleam/int"/utf8>>,
<<"gleam/float"/utf8>>,
<<"gleam/json"/utf8>>,
<<"gleam/dynamic/decode"/utf8>>,
<<"gleam/result"/utf8>>,
<<"gleam/bool"/utf8>>],
Operations = begin
_pipe = {module,
defs(
[{import,
<<"gleam/option"/utf8>>,
none,
[{unqualified_import, <<"Option"/utf8>>, none}],
[{unqualified_import, <<"None"/utf8>>, none}]} |
gleam@list:map(
Modules,
fun(_capture@2) ->
{import, _capture@2, none, [], []}
end
)]
),
defs(Operation_types@1),
[],
[],
gleam@list:map(
Operation_functions@2,
fun(_capture@3) -> {definition, [], _capture@3} end
)},
glance_printer:print(_pipe)
end,
Entry = begin
_pipe@1 = {module,
[],
[],
[],
[],
gleam@list:map(
Top,
fun(_capture@4) -> {definition, [], _capture@4} end
)},
glance_printer:print(_pipe@1)
end,
{Operations, Entry}.
-file("src/oas/generator.gleam", 1210).
-spec print_decode_errors(list(gleam@dynamic@decode:decode_error())) -> binary().
print_decode_errors(Errors) ->
_pipe = gleam@list:map(
Errors,
fun(Error) ->
{decode_error, Expected, Found, Path} = Error,
<<<<<<<<<<"expected "/utf8, Expected/binary>>/binary,
" found "/utf8>>/binary,
Found/binary>>/binary,
" at "/utf8>>/binary,
(gleam@string:join(Path, <<"/"/utf8>>))/binary>>
end
),
gleam@string:join(_pipe, <<"\n"/utf8>>).
-file("src/oas/generator.gleam", 1200).
-spec json_decode_error_to_string(gleam@json:decode_error()) -> binary().
json_decode_error_to_string(Error) ->
case Error of
unexpected_end_of_input ->
<<"UnexpectedEndOfInput"/utf8>>;
{unexpected_byte, Str} ->
<<"UnexpectedByte "/utf8, Str/binary>>;
{unexpected_sequence, Str@1} ->
<<"UnexpectedSequence "/utf8, Str@1/binary>>;
{unable_to_decode, Errors} ->
<<"UnableToDecode "/utf8, (print_decode_errors(Errors))/binary>>
end.
-file("src/oas/generator.gleam", 205).
-spec encode_tuple_body(
list(oas@generator@lift:schema(integer())),
glance:expression()
) -> glance:expression().
encode_tuple_body(Items, Arg) ->
call1(
<<"utils"/utf8>>,
<<"merge"/utf8>>,
{list,
gleam@list:index_map(
Items,
fun(Item, Index) ->
{call,
to_encoder(Item),
[{unlabelled_field, {tuple_index, Arg, Index}}]}
end
),
none}
).
-file("src/oas/generator.gleam", 90).
-spec to_encoder(oas@generator@lift:schema(integer())) -> glance:expression().
to_encoder(Lifted) ->
case Lifted of
{named, <<"#/components/schemas/"/utf8, Inner/binary>>} ->
{variable, encode_fn(Inner)};
{named, _} ->
erlang:error(#{gleam_error => panic,
message => <<"unexpected ref"/utf8>>,
file => <<?FILEPATH/utf8>>,
module => <<"oas/generator"/utf8>>,
function => <<"to_encoder"/utf8>>,
line => 94});
{primitive, boolean} ->
access(<<"json"/utf8>>, <<"bool"/utf8>>);
{primitive, integer} ->
access(<<"json"/utf8>>, <<"int"/utf8>>);
{primitive, number} ->
access(<<"json"/utf8>>, <<"float"/utf8>>);
{primitive, string} ->
access(<<"json"/utf8>>, <<"string"/utf8>>);
{primitive, null} ->
{fn,
[{fn_parameter,
{discarded, <<""/utf8>>},
{some, {named_type, <<"Nil"/utf8>>, none, []}}}],
none,
[{expression, call0(<<"json"/utf8>>, <<"null"/utf8>>)}]};
{primitive, always} ->
{fn,
[{fn_parameter, {named, <<"data"/utf8>>}, none}],
none,
[{expression, {variable, <<"data"/utf8>>}}]};
{primitive, never} ->
{fn,
[{fn_parameter, {discarded, <<"data"/utf8>>}, none}],
none,
[{expression,
{panic,
{some,
{string,
<<"never value cannot be encoded"/utf8>>}}}}]};
{array, Items} ->
call2(
<<"json"/utf8>>,
<<"array"/utf8>>,
{variable, <<"_"/utf8>>},
to_encoder(Items)
);
{tuple, Items@1} ->
{fn,
[{fn_parameter, {named, <<"data"/utf8>>}, none}],
none,
[{expression,
encode_tuple_body(Items@1, {variable, <<"data"/utf8>>})}]};
{compound, Index} ->
{variable,
encode_fn(
<<"internal_"/utf8,
(erlang:integer_to_binary(Index))/binary>>
)};
unsupported ->
{fn,
[{fn_parameter, {named, <<"data"/utf8>>}, none}],
none,
[{expression, {variable, <<"data"/utf8>>}}]}
end.
-file("src/oas/generator.gleam", 136).
-spec schema_to_encoder(
{binary(), oas@generator@lift:schema(oas@generator@lift:fields())}
) -> glance:function_().
schema_to_encoder(Entry) ->
{Name, Top} = Entry,
Type_ = name_for_gleam_type(Name),
Arg = {variable, <<"data"/utf8>>},
Exp = case Top of
{named, N} ->
_pipe = to_encoder({named, N}),
{call, _pipe, [{unlabelled_field, Arg}]};
{primitive, null} ->
call0(<<"json"/utf8>>, <<"null"/utf8>>);
{primitive, always} ->
Arg;
{primitive, never} ->
{panic, {some, {string, <<"never value cannot be encoded"/utf8>>}}};
{primitive, P} ->
_pipe@1 = to_encoder({primitive, P}),
{call, _pipe@1, [{unlabelled_field, Arg}]};
{array, Items} ->
call2(<<"json"/utf8>>, <<"array"/utf8>>, Arg, to_encoder(Items));
{tuple, Items@1} ->
encode_tuple_body(Items@1, Arg);
{compound, {fields, Properties, Required}} ->
call1(
<<"json"/utf8>>,
<<"object"/utf8>>,
{list,
gleam@list:map(
Properties,
fun(Property) ->
{Key, {Schema, Nullable}} = Property,
Arg@1 = access(
<<"data"/utf8>>,
name_for_gleam_field_or_var(Key)
),
Cast = to_encoder(Schema),
Value = case not gleam@list:contains(Required, Key)
orelse Nullable of
false ->
{call, Cast, [{unlabelled_field, Arg@1}]};
true ->
call2(
<<"json"/utf8>>,
<<"nullable"/utf8>>,
Arg@1,
Cast
)
end,
{tuple, [{string, Key}, Value]}
end
),
none}
);
unsupported ->
Arg
end,
Ignored = case Top of
{primitive, null} ->
true;
{primitive, never} ->
true;
{compound, {fields, Properties@1, _}} ->
gleam@list:is_empty(Properties@1);
_ ->
false
end,
Assignment = case Ignored of
true ->
{discarded, <<"data"/utf8>>};
false ->
{named, <<"data"/utf8>>}
end,
{function,
encode_fn(Name),
public,
[{function_parameter,
none,
Assignment,
{some, {named_type, Type_, none, []}}}],
none,
[{expression, Exp}],
{span, 0, 0}}.
-file("src/oas/generator.gleam", 345).
-spec gen_schema(gleam@dict:dict(binary(), oas:schema())) -> {list(glance:custom_type()),
list(glance:type_alias()),
list(glance:function_())}.
gen_schema(Schemas) ->
Module = schema,
{Internal, Named} = gleam@list:map_fold(
begin
_pipe = Schemas,
maps:to_list(_pipe)
end,
[],
fun(Acc, Entry) ->
{Name, Schema} = Entry,
{Top, _, Acc@1} = oas@generator@lift:do_lift({inline, Schema}, Acc),
{Acc@1, {Name, Top}}
end
),
Named@1 = lists:append(
Named,
begin
_pipe@1 = Internal,
_pipe@2 = lists:reverse(_pipe@1),
gleam@list:index_map(
_pipe@2,
fun(Fields, Index) ->
{<<"internal_"/utf8,
(erlang:integer_to_binary(Index))/binary>>,
{compound, Fields}}
end
)
end
),
gleam@list:fold(
Named@1,
{[], [], []},
fun(Acc@2, Entry@1) ->
{Name@1, Top@1} = Entry@1,
{Custom_types, Type_aliases, Fns} = Acc@2,
Fns@1 = lists:append(
Fns,
[schema_to_encoder({Name@1, Top@1}),
schema_to_decode_fn({Name@1, Top@1})]
),
Name@2 = name_for_gleam_type(Name@1),
{Custom_types@1, Type_aliases@1} = case Top@1 of
{named, Name@3} ->
Type_ = to_type({named, Name@3}, Module),
{Custom_types, [alias(Name@3, Type_) | Type_aliases]};
{primitive, Primitive} ->
Type_@1 = to_type({primitive, Primitive}, Module),
{Custom_types, [alias(Name@2, Type_@1) | Type_aliases]};
{array, Items} ->
Type_@2 = to_type({array, Items}, Module),
{Custom_types, [alias(Name@2, Type_@2) | Type_aliases]};
{tuple, Items@1} ->
Type_@3 = to_type({tuple, Items@1}, Module),
{Custom_types, [alias(Name@2, Type_@3) | Type_aliases]};
{compound, {fields, Properties, Required}} ->
Type_@4 = custom_type(Name@2, Properties, Required, Module),
{[Type_@4 | Custom_types], Type_aliases};
unsupported ->
Type_@5 = to_type(unsupported, Module),
{Custom_types, [alias(Name@2, Type_@5) | Type_aliases]}
end,
{Custom_types@1, Type_aliases@1, Fns@1}
end
).
-file("src/oas/generator.gleam", 1173).
-spec gen_schema_file(gleam@dict:dict(binary(), oas:schema()), binary()) -> binary().
gen_schema_file(Schemas, Provider) ->
{Custom_types, Type_aliases, Functions} = gen_schema(Schemas),
_pipe = {module,
[{definition,
[],
{import, <<"gleam/dynamic/decode"/utf8>>, none, [], []}},
{definition, [], {import, <<"gleam/dynamic"/utf8>>, none, [], []}},
{definition, [], {import, <<"gleam/json"/utf8>>, none, [], []}},
{definition,
[],
{import, <<Provider/binary, "/utils"/utf8>>, none, [], []}},
{definition,
[],
{import,
<<"gleam/option"/utf8>>,
none,
[{unqualified_import, <<"Option"/utf8>>, none}],
[{unqualified_import, <<"None"/utf8>>, none}]}}],
defs(Custom_types),
defs(Type_aliases),
[],
defs(Functions)},
glance_printer:print(_pipe).
-file("src/oas/generator.gleam", 1066).
-spec build(binary(), binary(), binary(), list(binary())) -> {ok, nil} |
{error, snag:snag()}.
build(Spec_src, Project_path, Provider, Exclude) ->
Module_path = <<<<Project_path/binary, "/src/"/utf8>>/binary,
Provider/binary>>,
gleam@result:'try'(
begin
_pipe = simplifile:read(Spec_src),
_pipe@1 = snag:map_error(_pipe, fun simplifile:describe_error/1),
snag:context(
_pipe@1,
<<"Could not read file "/utf8, Spec_src/binary>>
)
end,
fun(File) ->
gleam@result:'try'(
begin
_pipe@2 = gleam@json:parse(File, oas:decoder()),
snag:map_error(_pipe@2, fun json_decode_error_to_string/1)
end,
fun(Spec) ->
{Operations, Entry} = gen_operations_and_top_files(
Spec,
Provider,
Exclude
),
Operations_module_file = <<Module_path/binary,
"/operations.gleam"/utf8>>,
gleam@result:'try'(
begin
_pipe@4 = simplifile_erl:write_bits(
Operations_module_file,
begin
_pipe@3 = Operations,
gleam_stdlib:identity(_pipe@3)
end
),
_pipe@5 = snag:map_error(
_pipe@4,
fun simplifile:describe_error/1
),
snag:context(
_pipe@5,
<<"Could not write file "/utf8,
Operations_module_file/binary>>
)
end,
fun(_use0) ->
nil = _use0,
gleam@result:'try'(
begin
_pipe@6 = simplifile:read(
<<Module_path/binary, ".gleam"/utf8>>
),
_pipe@7 = snag:map_error(
_pipe@6,
fun simplifile:describe_error/1
),
snag:context(
_pipe@7,
<<<<"Could not read file "/utf8,
Module_path/binary>>/binary,
".gleam"/utf8>>
)
end,
fun(Mod) ->
Split = <<"// GENERATED ---"/utf8>>,
Pre@1 = case gleam@string:split_once(
Mod,
Split
) of
{ok, {Pre, _}} ->
Pre;
{error, nil} ->
Mod
end,
Content = <<Pre@1/binary,
Split/binary,
"----------\n\n"/utf8,
Entry/binary>>,
gleam@result:'try'(
begin
_pipe@8 = simplifile_erl:write_bits(
<<Module_path/binary,
".gleam"/utf8>>,
Content
),
_pipe@9 = snag:map_error(
_pipe@8,
fun simplifile:describe_error/1
),
snag:context(
_pipe@9,
<<<<"Could not write file "/utf8,
Module_path/binary>>/binary,
".gleam"/utf8>>
)
end,
fun(_use0@1) ->
nil = _use0@1,
Content@1 = begin
_pipe@10 = gen_schema_file(
erlang:element(
2,
erlang:element(7, Spec)
),
Provider
),
gleam_stdlib:identity(_pipe@10)
end,
Schema_module_file = <<Module_path/binary,
"/schema.gleam"/utf8>>,
gleam@result:'try'(
begin
_pipe@11 = simplifile_erl:write_bits(
Schema_module_file,
Content@1
),
_pipe@12 = snag:map_error(
_pipe@11,
fun simplifile:describe_error/1
),
snag:context(
_pipe@12,
<<"Could not write file "/utf8,
Schema_module_file/binary>>
)
end,
fun(_use0@2) ->
nil = _use0@2,
{ok, nil}
end
)
end
)
end
)
end
)
end
)
end
).