-module(gilly@internal@codegen). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/gilly/internal/codegen.gleam"). -export([generate_operations/2, generate/2, generate_schemas/2]). -export_type([config/0, schema_usage/0, state/0, body_info/0]). -if(?OTP_RELEASE >= 27). -define(MODULEDOC(Str), -moduledoc(Str)). -define(DOC(Str), -doc(Str)). -else. -define(MODULEDOC(Str), -compile([])). -define(DOC(Str), -compile([])). -endif. ?MODULEDOC(false). -type config() :: {config, gilly@common:optionality(), integer(), boolean(), list(binary())}. -type schema_usage() :: request_only | response_only | both | unreferenced. -type state() :: {state, gleam@dict:dict(binary(), gleam@set:set(binary())), gleam@dict:dict(binary(), list(binary())), gleam@dict:dict(binary(), schema_usage())}. -type body_info() :: no_body | {ref_body, glam@doc:document(), gilly@openapi@schema:schema()} | {inline_body, gilly@openapi@schema:base_schema(), gilly@openapi@schema:object_schema()}. -file("src/gilly/internal/codegen.gleam", 56). ?DOC(false). -spec default_state() -> state(). default_state() -> {state, maps:new(), maps:new(), maps:new()}. -file("src/gilly/internal/codegen.gleam", 60). ?DOC(false). -spec register_enum(state(), binary(), list(binary())) -> state(). register_enum(State, Type_name, Variants) -> {state, erlang:element(2, State), gleam@dict:insert(erlang:element(3, State), Type_name, Variants), erlang:element(4, State)}. -file("src/gilly/internal/codegen.gleam", 68). ?DOC(false). -spec import_qualified(state(), binary(), binary()) -> state(). import_qualified(State, Module, Imported) -> Imports = gleam@dict:upsert( erlang:element(2, State), Module, fun(Existing) -> case Existing of {some, Values} -> gleam@set:insert(Values, Imported); none -> gleam@set:from_list([Imported]) end end ), {state, Imports, erlang:element(3, State), erlang:element(4, State)}. -file("src/gilly/internal/codegen.gleam", 79). ?DOC(false). -spec import_module(state(), binary()) -> state(). import_module(State, Module) -> Imports = case gleam@dict:has_key(erlang:element(2, State), Module) of true -> erlang:element(2, State); false -> gleam@dict:insert(erlang:element(2, State), Module, gleam@set:new()) end, {state, Imports, erlang:element(3, State), erlang:element(4, State)}. -file("src/gilly/internal/codegen.gleam", 87). ?DOC(false). -spec imports_doc(state(), integer()) -> glam@doc:document(). imports_doc(State, Indent) -> Sorted_imports = begin _pipe = maps:to_list(erlang:element(2, State)), gleam@list:sort( _pipe, fun(A, B) -> gleam@string:compare(erlang:element(1, A), erlang:element(1, B)) end ) end, _pipe@6 = gleam@list:map( Sorted_imports, fun(Entry) -> {Module, Qualified} = Entry, Import_line = glam@doc:from_string( <<"import "/utf8, Module/binary>> ), case gleam@set:to_list(Qualified) of [] -> Import_line; Values -> Values_doc = begin _pipe@1 = gleam@list:sort( Values, fun gleam@string:compare/2 ), _pipe@2 = gleam@list:map( _pipe@1, fun glam@doc:from_string/1 ), _pipe@3 = glam@doc:join( _pipe@2, glam@doc:break(<<", "/utf8>>, <<","/utf8>>) ), glam@doc:group(_pipe@3) end, glam@doc:concat( [Import_line, glam@doc:from_string(<<".{"/utf8>>), begin _pipe@4 = glam@doc:concat( [{break, <<""/utf8>>, <<""/utf8>>}, Values_doc] ), _pipe@5 = glam@doc:group(_pipe@4), glam@doc:nest(_pipe@5, Indent) end, {break, <<""/utf8>>, <<""/utf8>>}, glam@doc:from_string(<<"}"/utf8>>)] ) end end ), glam@doc:join(_pipe@6, {line, 1}). -file("src/gilly/internal/codegen.gleam", 343). ?DOC(false). -spec extract_schemas(gilly@openapi@openapi:open_a_p_i()) -> list({binary(), gilly@openapi@schema:schema()}). extract_schemas(Spec) -> _pipe = erlang:element(6, Spec), _pipe@1 = gleam@option:map(_pipe, fun(C) -> erlang:element(2, C) end), gleam@option:unwrap(_pipe@1, []). -file("src/gilly/internal/codegen.gleam", 352). ?DOC(false). -spec ref_to_raw_name(binary()) -> gleam@option:option(binary()). ref_to_raw_name(Ref) -> case gleam@string:split(Ref, <<"/"/utf8>>) of [_, _, _, Name | _] -> {some, Name}; _ -> none end. -file("src/gilly/internal/codegen.gleam", 360). ?DOC(false). -spec merge_usage(schema_usage(), schema_usage()) -> schema_usage(). merge_usage(Existing, New) -> case {Existing, New} of {both, _} -> both; {_, both} -> both; {request_only, response_only} -> both; {response_only, request_only} -> both; {request_only, request_only} -> request_only; {response_only, response_only} -> response_only; {unreferenced, Other} -> Other; {Other, unreferenced} -> Other end. -file("src/gilly/internal/codegen.gleam", 371). ?DOC(false). -spec record_schema_ref( gleam@dict:dict(binary(), schema_usage()), gilly@openapi@schema:schema(), schema_usage() ) -> gleam@dict:dict(binary(), schema_usage()). record_schema_ref(Usages, Schema, Usage) -> case Schema of {ref, Ref} -> case ref_to_raw_name(Ref) of {some, Name} -> gleam@dict:upsert( Usages, Name, fun(Existing) -> case Existing of {some, Prev} -> merge_usage(Prev, Usage); none -> Usage end end ); none -> Usages end; _ -> Usages end. -file("src/gilly/internal/codegen.gleam", 457). ?DOC(false). -spec get_schema_usage(state(), binary()) -> schema_usage(). get_schema_usage(State, Raw_name) -> case gleam_stdlib:map_get(erlang:element(4, State), Raw_name) of {ok, Usage} -> Usage; {error, _} -> unreferenced end. -file("src/gilly/internal/codegen.gleam", 466). ?DOC(false). -spec api_error_doc(integer()) -> glam@doc:document(). api_error_doc(Indent) -> glam@doc:concat( [glam@doc:from_string(<<"pub type ApiError(err) {"/utf8>>), begin _pipe = {line, 1}, glam@doc:nest(_pipe, Indent) end, begin _pipe@1 = glam@doc:from_string( <<"JsonDecodeError(json.DecodeError)"/utf8>> ), glam@doc:nest(_pipe@1, Indent) end, begin _pipe@2 = {line, 1}, glam@doc:nest(_pipe@2, Indent) end, begin _pipe@3 = glam@doc:from_string(<<"ClientError(err)"/utf8>>), glam@doc:nest(_pipe@3, Indent) end, {line, 1}, glam@doc:from_string(<<"}"/utf8>>)] ). -file("src/gilly/internal/codegen.gleam", 574). ?DOC(false). -spec client_with_base_url_doc(integer()) -> glam@doc:document(). client_with_base_url_doc(Indent) -> glam@doc:concat( [glam@doc:from_string(<<"pub fn with_base_url("/utf8>>), begin _pipe = {line, 1}, glam@doc:nest(_pipe, Indent) end, begin _pipe@1 = glam@doc:from_string(<<"client: Client(err),"/utf8>>), glam@doc:nest(_pipe@1, Indent) end, begin _pipe@2 = {line, 1}, glam@doc:nest(_pipe@2, Indent) end, begin _pipe@3 = glam@doc:from_string(<<"base_url: String,"/utf8>>), glam@doc:nest(_pipe@3, Indent) end, {line, 1}, glam@doc:from_string(<<") -> Client(err) {"/utf8>>), begin _pipe@4 = {line, 1}, glam@doc:nest(_pipe@4, Indent) end, begin _pipe@5 = glam@doc:from_string( <<"Client(..client, base_url:)"/utf8>> ), glam@doc:nest(_pipe@5, Indent) end, {line, 1}, glam@doc:from_string(<<"}"/utf8>>)] ). -file("src/gilly/internal/codegen.gleam", 618). ?DOC(false). -spec default_base_url(gilly@openapi@openapi:open_a_p_i()) -> gleam@option:option(binary()). default_base_url(Spec) -> case erlang:element(4, Spec) of [First | _] -> {some, erlang:element(2, First)}; [] -> none end. -file("src/gilly/internal/codegen.gleam", 1651). ?DOC(false). -spec operation_fn_name(gilly@openapi@operation:operation(), binary(), binary()) -> binary(). operation_fn_name(Op, Path, Method) -> case erlang:element(2, Op) of {some, Id} -> justin:snake_case(Id); none -> Clean_path = begin _pipe = gleam@string:replace(Path, <<"{"/utf8>>, <<""/utf8>>), _pipe@1 = gleam@string:replace(_pipe, <<"}"/utf8>>, <<""/utf8>>), gleam@string:replace(_pipe@1, <<"/"/utf8>>, <<"_"/utf8>>) end, justin:snake_case( <<(string:lowercase(Method))/binary, Clean_path/binary>> ) end. -file("src/gilly/internal/codegen.gleam", 1706). ?DOC(false). -spec resolve_ref_schema( binary(), list({binary(), gilly@openapi@schema:schema()}) ) -> gleam@option:option(gilly@openapi@schema:schema()). resolve_ref_schema(Ref, All_schemas) -> case ref_to_raw_name(Ref) of {some, Name} -> _pipe = gleam@list:key_find(All_schemas, Name), gleam@option:from_result(_pipe); none -> none end. -file("src/gilly/internal/codegen.gleam", 1781). ?DOC(false). -spec result_or({ok, GEZ} | {error, GFA}, fun(() -> {ok, GEZ} | {error, GFA})) -> {ok, GEZ} | {error, GFA}. result_or(Result, Alternative) -> case Result of {ok, _} -> Result; {error, _} -> Alternative() end. -file("src/gilly/internal/codegen.gleam", 416). ?DOC(false). -spec collect_operation_usages( gleam@dict:dict(binary(), schema_usage()), gilly@openapi@operation:operation() ) -> gleam@dict:dict(binary(), schema_usage()). collect_operation_usages(Usages, Op) -> Usages@1 = case erlang:element(7, Op) of {some, Rb} -> case gleam@list:key_find( erlang:element(4, Rb), <<"application/json"/utf8>> ) of {ok, Media_type} -> case erlang:element(2, Media_type) of {some, Body_schema} -> record_schema_ref(Usages, Body_schema, request_only); none -> Usages end; {error, _} -> Usages end; none -> Usages end, Response = begin _pipe = gleam@list:key_find(erlang:element(8, Op), <<"200"/utf8>>), _pipe@1 = result_or( _pipe, fun() -> gleam@list:key_find(erlang:element(8, Op), <<"201"/utf8>>) end ), result_or( _pipe@1, fun() -> gleam@list:key_find(erlang:element(8, Op), <<"default"/utf8>>) end ) end, case Response of {ok, Resp} -> case gleam@list:key_find( erlang:element(3, Resp), <<"application/json"/utf8>> ) of {ok, Media_type@1} -> case erlang:element(2, Media_type@1) of {some, Resp_schema} -> record_schema_ref( Usages@1, Resp_schema, response_only ); none -> Usages@1 end; {error, _} -> Usages@1 end; {error, _} -> Usages@1 end. -file("src/gilly/internal/codegen.gleam", 393). ?DOC(false). -spec collect_schema_usages(gilly@openapi@openapi:open_a_p_i()) -> gleam@dict:dict(binary(), schema_usage()). collect_schema_usages(Spec) -> gleam@list:fold( erlang:element(5, Spec), maps:new(), fun(Usages, Path_entry) -> {_, Path_item} = Path_entry, Operations = begin _pipe = [erlang:element(2, Path_item), erlang:element(3, Path_item), erlang:element(4, Path_item), erlang:element(5, Path_item), erlang:element(6, Path_item)], gleam@list:filter_map(_pipe, fun(Op) -> case Op of {some, O} -> {ok, O}; none -> {error, nil} end end) end, gleam@list:fold( Operations, Usages, fun(Usages@1, Op@1) -> collect_operation_usages(Usages@1, Op@1) end ) end ). -file("src/gilly/internal/codegen.gleam", 1868). ?DOC(false). -spec find_next_param(binary(), list(gilly@openapi@operation:parameter())) -> gleam@option:option({binary(), gilly@openapi@operation:parameter(), binary()}). find_next_param(Path, Params) -> case gleam@string:split_once(Path, <<"{"/utf8>>) of {ok, {Before, Rest}} -> case gleam@string:split_once(Rest, <<"}"/utf8>>) of {ok, {Param_name, After}} -> case gleam@list:find( Params, fun(P) -> erlang:element(2, P) =:= Param_name end ) of {ok, Param} -> {some, {Before, Param, After}}; {error, _} -> none end; {error, _} -> none end; {error, _} -> none end. -file("src/gilly/internal/codegen.gleam", 2491). ?DOC(false). -spec wrap_optional(state(), glam@doc:document()) -> {state(), glam@doc:document()}. wrap_optional(State, Inner) -> State@1 = import_qualified( State, <<"gleam/option"/utf8>>, <<"type Option"/utf8>> ), {State@1, glam@doc:concat( [glam@doc:from_string(<<"Option("/utf8>>), Inner, glam@doc:from_string(<<")"/utf8>>)] )}. -file("src/gilly/internal/codegen.gleam", 2973). ?DOC(false). -spec is_nullable(gilly@openapi@schema:schema()) -> boolean(). is_nullable(S) -> case S of {ref, _} -> false; {string, Base, _} -> erlang:element(5, Base); {integer, Base, _} -> erlang:element(5, Base); {number, Base} -> erlang:element(5, Base); {boolean, Base} -> erlang:element(5, Base); {array, Base, _} -> erlang:element(5, Base); {object, Base, _} -> erlang:element(5, Base) end. -file("src/gilly/internal/codegen.gleam", 2954). ?DOC(false). -spec is_field_optional( gilly@openapi@schema:schema(), boolean(), gilly@common:optionality() ) -> boolean(). is_field_optional(Prop_schema, In_required, Optionality) -> case Prop_schema of {object, _, _} -> true; _ -> case Optionality of required_only -> not In_required; nullable_only -> is_nullable(Prop_schema); required_and_nullable -> not In_required orelse is_nullable(Prop_schema) end end. -file("src/gilly/internal/codegen.gleam", 3006). ?DOC(false). -spec description_to_comment(binary()) -> glam@doc:document(). description_to_comment(Desc) -> _pipe = gleam@string:split(Desc, <<"\n"/utf8>>), _pipe@1 = gleam@list:map( _pipe, fun(Line) -> glam@doc:from_string( <<"/// "/utf8, (gleam@string:trim(Line))/binary>> ) end ), glam@doc:join(_pipe@1, {line, 1}). -file("src/gilly/internal/codegen.gleam", 2987). ?DOC(false). -spec base_schema_comment(gilly@openapi@schema:base_schema()) -> gleam@option:option(glam@doc:document()). base_schema_comment(Base) -> case erlang:element(4, Base) of {some, Desc} -> {some, description_to_comment(Desc)}; none -> none end. -file("src/gilly/internal/codegen.gleam", 2994). ?DOC(false). -spec schema_description(gilly@openapi@schema:schema()) -> gleam@option:option(glam@doc:document()). schema_description(S) -> case S of {ref, _} -> none; {string, Base, _} -> base_schema_comment(Base); {integer, Base, _} -> base_schema_comment(Base); {number, Base} -> base_schema_comment(Base); {boolean, Base} -> base_schema_comment(Base); {array, Base, _} -> base_schema_comment(Base); {object, Base, _} -> base_schema_comment(Base) end. -file("src/gilly/internal/codegen.gleam", 3017). ?DOC(false). -spec is_map_object(gilly@openapi@schema:object_schema()) -> boolean(). is_map_object(Object_schema) -> case erlang:element(3, Object_schema) of [] -> false; Properties -> gleam@list:all( Properties, fun(Prop) -> {Key, _} = Prop, gleam_stdlib:string_starts_with(Key, <<"<"/utf8>>) andalso gleam_stdlib:string_ends_with( Key, <<">"/utf8>> ) end ) end. -file("src/gilly/internal/codegen.gleam", 3030). ?DOC(false). -spec map_value_schema(gilly@openapi@schema:object_schema()) -> gilly@openapi@schema:schema(). map_value_schema(Object_schema) -> Value_schema@1 = case erlang:element(3, Object_schema) of [{_, Value_schema} | _] -> Value_schema; _assert_fail -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, file => <>, module => <<"gilly/internal/codegen"/utf8>>, function => <<"map_value_schema"/utf8>>, line => 3031, value => _assert_fail, start => 86487, 'end' => 86549, pattern_start => 86498, pattern_end => 86522}) end, Value_schema@1. -file("src/gilly/internal/codegen.gleam", 3037). ?DOC(false). -spec to_type_name(binary()) -> binary(). to_type_name(Name) -> justin:pascal_case(Name). -file("src/gilly/internal/codegen.gleam", 2401). ?DOC(false). -spec string_type(state(), gilly@openapi@schema:string_schema(), binary()) -> {state(), glam@doc:document()}. string_type(State, String_schema, Enum_name_hint) -> case erlang:element(4, String_schema) of {some, Variants} -> Type_name = to_type_name(Enum_name_hint), State@1 = register_enum(State, Type_name, Variants), {State@1, glam@doc:from_string(Type_name)}; none -> case erlang:element(5, String_schema) of {some, <<"date-time"/utf8>>} -> {State, glam@doc:from_string(<<"String"/utf8>>)}; {some, <<"binary"/utf8>>} -> {State, glam@doc:from_string(<<"BitArray"/utf8>>)}; _ -> {State, glam@doc:from_string(<<"String"/utf8>>)} end end. -file("src/gilly/internal/codegen.gleam", 2733). ?DOC(false). -spec string_to_json_fn(state(), gilly@openapi@schema:string_schema(), binary()) -> {state(), glam@doc:document()}. string_to_json_fn(State, String_schema, Enum_name_hint) -> case erlang:element(4, String_schema) of {some, _} -> Type_name = to_type_name(Enum_name_hint), To_json_fn = <<(justin:snake_case(Type_name))/binary, "_to_json"/utf8>>, {State, glam@doc:from_string(To_json_fn)}; none -> {State, glam@doc:from_string(<<"json.string"/utf8>>)} end. -file("src/gilly/internal/codegen.gleam", 2847). ?DOC(false). -spec string_to_json( state(), gilly@openapi@schema:string_schema(), binary(), binary() ) -> {state(), glam@doc:document()}. string_to_json(State, String_schema, Accessor, Enum_name_hint) -> case erlang:element(4, String_schema) of {some, _} -> Type_name = to_type_name(Enum_name_hint), To_string_fn = <<(justin:snake_case(Type_name))/binary, "_to_string"/utf8>>, {State, glam@doc:from_string( <<<<<<<<"json.string("/utf8, To_string_fn/binary>>/binary, "("/utf8>>/binary, Accessor/binary>>/binary, "))"/utf8>> )}; none -> case erlang:element(5, String_schema) of {some, <<"binary"/utf8>>} -> {State, glam@doc:from_string( <<<<"json.string("/utf8, Accessor/binary>>/binary, ")"/utf8>> )}; _ -> {State, glam@doc:from_string( <<<<"json.string("/utf8, Accessor/binary>>/binary, ")"/utf8>> )} end end. -file("src/gilly/internal/codegen.gleam", 3041). ?DOC(false). -spec to_field_name(binary()) -> binary(). to_field_name(Name) -> Snake = justin:snake_case(Name), case Snake of <<"type"/utf8>> -> <<"type_"/utf8>>; <<"fn"/utf8>> -> <<"fn_"/utf8>>; <<"let"/utf8>> -> <<"let_"/utf8>>; <<"case"/utf8>> -> <<"case_"/utf8>>; <<"use"/utf8>> -> <<"use_"/utf8>>; <<"pub"/utf8>> -> <<"pub_"/utf8>>; <<"import"/utf8>> -> <<"import_"/utf8>>; <<"as"/utf8>> -> <<"as_"/utf8>>; _ -> Snake end. -file("src/gilly/internal/codegen.gleam", 479). ?DOC(false). -spec client_type_doc(integer(), gleam@option:option(binary()), list(binary())) -> glam@doc:document(). client_type_doc(Indent, Description, Default_params) -> Comment = case Description of {some, Desc} -> glam@doc:concat([description_to_comment(Desc), {line, 1}]); none -> {concat, []} end, Extra_fields = gleam@list:map( Default_params, fun(Name) -> glam@doc:concat( [begin _pipe = {line, 1}, glam@doc:nest(_pipe, Indent * 2) end, begin _pipe@1 = glam@doc:from_string( <<(to_field_name(Name))/binary, ": String,"/utf8>> ), glam@doc:nest(_pipe@1, Indent * 2) end] ) end ), glam@doc:concat( lists:append( [[Comment, glam@doc:from_string( <<"pub opaque type Client(err) {"/utf8>> ), begin _pipe@2 = {line, 1}, glam@doc:nest(_pipe@2, Indent) end, begin _pipe@3 = glam@doc:from_string(<<"Client("/utf8>>), glam@doc:nest(_pipe@3, Indent) end, begin _pipe@4 = {line, 1}, glam@doc:nest(_pipe@4, Indent * 2) end, begin _pipe@5 = glam@doc:from_string( <<"http_client: fn(request.Request(String)) -> Result(response.Response(String), err),"/utf8>> ), glam@doc:nest(_pipe@5, Indent * 2) end, begin _pipe@6 = {line, 1}, glam@doc:nest(_pipe@6, Indent * 2) end, begin _pipe@7 = glam@doc:from_string( <<"base_url: String,"/utf8>> ), glam@doc:nest(_pipe@7, Indent * 2) end], Extra_fields, [begin _pipe@8 = {line, 1}, glam@doc:nest(_pipe@8, Indent) end, begin _pipe@9 = glam@doc:from_string(<<")"/utf8>>), glam@doc:nest(_pipe@9, Indent) end, {line, 1}, glam@doc:from_string(<<"}"/utf8>>)]] ) ). -file("src/gilly/internal/codegen.gleam", 525). ?DOC(false). -spec client_new_doc(integer(), gleam@option:option(binary()), list(binary())) -> glam@doc:document(). client_new_doc(Indent, Default_base_url, Default_params) -> Base_url_default = case Default_base_url of {some, Url} -> <<<<"\""/utf8, Url/binary>>/binary, "\""/utf8>>; none -> <<"\"\""/utf8>> end, Extra_args = gleam@list:map( Default_params, fun(Name) -> Field_name = to_field_name(Name), glam@doc:concat( [begin _pipe = {line, 1}, glam@doc:nest(_pipe, Indent) end, begin _pipe@1 = glam@doc:from_string( <<<<<>/binary, Field_name/binary>>/binary, ": String,"/utf8>> ), glam@doc:nest(_pipe@1, Indent) end] ) end ), Extra_inits = gleam@list:map( Default_params, fun(Name@1) -> <<(to_field_name(Name@1))/binary, ":"/utf8>> end ), All_inits = begin _pipe@2 = [<<"http_client:"/utf8>>, <<"base_url: "/utf8, Base_url_default/binary>>], lists:append(_pipe@2, Extra_inits) end, glam@doc:concat( lists:append( [[glam@doc:from_string(<<"pub fn new("/utf8>>), begin _pipe@3 = {line, 1}, glam@doc:nest(_pipe@3, Indent) end, begin _pipe@4 = glam@doc:from_string( <<"http_client: fn(request.Request(String)) -> Result(response.Response(String), err),"/utf8>> ), glam@doc:nest(_pipe@4, Indent) end], Extra_args, [{line, 1}, glam@doc:from_string(<<") -> Client(err) {"/utf8>>), begin _pipe@5 = {line, 1}, glam@doc:nest(_pipe@5, Indent) end, begin _pipe@6 = glam@doc:from_string( <<<<"Client("/utf8, (gleam@string:join(All_inits, <<", "/utf8>>))/binary>>/binary, ")"/utf8>> ), glam@doc:nest(_pipe@6, Indent) end, {line, 1}, glam@doc:from_string(<<"}"/utf8>>)]] ) ). -file("src/gilly/internal/codegen.gleam", 593). ?DOC(false). -spec client_default_param_setters(integer(), list(binary())) -> list(glam@doc:document()). client_default_param_setters(Indent, Default_params) -> gleam@list:map( Default_params, fun(Name) -> Field_name = to_field_name(Name), glam@doc:concat( [glam@doc:from_string( <<<<"pub fn with_"/utf8, Field_name/binary>>/binary, "("/utf8>> ), begin _pipe = {line, 1}, glam@doc:nest(_pipe, Indent) end, begin _pipe@1 = glam@doc:from_string( <<"client: Client(err),"/utf8>> ), glam@doc:nest(_pipe@1, Indent) end, begin _pipe@2 = {line, 1}, glam@doc:nest(_pipe@2, Indent) end, begin _pipe@3 = glam@doc:from_string( <<<<<>/binary, Field_name/binary>>/binary, ": String,"/utf8>> ), glam@doc:nest(_pipe@3, Indent) end, {line, 1}, glam@doc:from_string(<<") -> Client(err) {"/utf8>>), begin _pipe@4 = {line, 1}, glam@doc:nest(_pipe@4, Indent) end, begin _pipe@5 = glam@doc:from_string( <<<<"Client(..client, "/utf8, Field_name/binary>>/binary, ":)"/utf8>> ), glam@doc:nest(_pipe@5, Indent) end, {line, 1}, glam@doc:from_string(<<"}"/utf8>>)] ) end ). -file("src/gilly/internal/codegen.gleam", 1826). ?DOC(false). -spec split_path_on_params( binary(), list(gilly@openapi@operation:parameter()), binary(), gleam@set:set(binary()), list(glam@doc:document()) ) -> list(glam@doc:document()). split_path_on_params(Remaining, Params, Params_prefix, Promoted, Acc) -> case find_next_param(Remaining, Params) of {some, {Before, Param, After}} -> Param_name = case gleam@set:contains( Promoted, erlang:element(2, Param) ) of true -> to_field_name(erlang:element(2, Param)); false -> <> end, Has_int_type = case erlang:element(6, Param) of {some, {integer, _, _}} -> true; _ -> false end, Before_parts = case Before of <<""/utf8>> -> Acc; _ -> lists:append( Acc, [glam@doc:from_string( <<<<"\""/utf8, Before/binary>>/binary, "\""/utf8>> )] ) end, Param_expr = case Has_int_type of true -> glam@doc:from_string( <<<<"int.to_string("/utf8, Param_name/binary>>/binary, ")"/utf8>> ); false -> glam@doc:from_string(Param_name) end, split_path_on_params( After, Params, Params_prefix, Promoted, lists:append(Before_parts, [Param_expr]) ); none -> case Remaining of <<""/utf8>> -> Acc; _ -> lists:append( Acc, [glam@doc:from_string( <<<<"\""/utf8, Remaining/binary>>/binary, "\""/utf8>> )] ) end end. -file("src/gilly/internal/codegen.gleam", 1815). ?DOC(false). -spec build_path_parts( binary(), list(gilly@openapi@operation:parameter()), binary(), gleam@set:set(binary()) ) -> glam@doc:document(). build_path_parts(Path, Params, Params_prefix, Promoted) -> Parts = split_path_on_params(Path, Params, Params_prefix, Promoted, []), glam@doc:join(Parts, glam@doc:from_string(<<" <> "/utf8>>)). -file("src/gilly/internal/codegen.gleam", 1791). ?DOC(false). -spec build_url_expression( binary(), list(gilly@openapi@operation:parameter()), binary(), gleam@set:set(binary()) ) -> glam@doc:document(). build_url_expression(Path, Path_params, Params_prefix, Promoted) -> case Path_params of [] -> glam@doc:from_string( <<<<"let assert Ok(req) = request.to(client.base_url <> \""/utf8, Path/binary>>/binary, "\")"/utf8>> ); _ -> Url_parts = build_path_parts( Path, Path_params, Params_prefix, Promoted ), glam@doc:concat( [glam@doc:from_string( <<"let assert Ok(req) = request.to(client.base_url <> "/utf8>> ), Url_parts, glam@doc:from_string(<<")"/utf8>>)] ) end. -file("src/gilly/internal/codegen.gleam", 3057). ?DOC(false). -spec ref_to_type_name(binary()) -> binary(). ref_to_type_name(Ref) -> case gleam@string:split(Ref, <<"/"/utf8>>) of [_, _, _, Name | _] -> to_type_name(Name); _ -> to_type_name(Ref) end. -file("src/gilly/internal/codegen.gleam", 1684). ?DOC(false). -spec query_param_to_string_expr( gilly@openapi@operation:parameter(), list({binary(), gilly@openapi@schema:schema()}) ) -> binary(). query_param_to_string_expr(Param, All_schemas) -> case erlang:element(6, Param) of {some, {integer, _, _}} -> <<"int.to_string(v)"/utf8>>; {some, {number, _}} -> <<"float.to_string(v)"/utf8>>; {some, {boolean, _}} -> <<"bool.to_string(v)"/utf8>>; {some, {ref, Ref}} -> case resolve_ref_schema(Ref, All_schemas) of {some, {string, _, {string_schema, _, _, {some, _}, _}}} -> Type_name = ref_to_type_name(Ref), <<(justin:snake_case(Type_name))/binary, "_to_string(v)"/utf8>>; _ -> <<"v"/utf8>> end; _ -> <<"v"/utf8>> end. -file("src/gilly/internal/codegen.gleam", 3067). ?DOC(false). -spec enum_variant_name(binary(), binary()) -> binary(). enum_variant_name(Type_name, Variant) -> <>. -file("src/gilly/internal/codegen.gleam", 3071). ?DOC(false). -spec enum_decoder_name(binary()) -> binary(). enum_decoder_name(Type_name) -> <<(justin:snake_case(Type_name))/binary, "_decoder"/utf8>>. -file("src/gilly/internal/codegen.gleam", 2545). ?DOC(false). -spec string_decoder(state(), gilly@openapi@schema:string_schema(), binary()) -> {state(), glam@doc:document()}. string_decoder(State, String_schema, Enum_name_hint) -> case erlang:element(4, String_schema) of {some, Variants} -> Type_name = to_type_name(Enum_name_hint), _ = Variants, Decoder_name = enum_decoder_name(Type_name), {State, glam@doc:from_string(<>)}; none -> case erlang:element(5, String_schema) of {some, <<"binary"/utf8>>} -> {State, glam@doc:from_string(<<"decode.bit_array"/utf8>>)}; _ -> {State, glam@doc:from_string(<<"decode.string"/utf8>>)} end end. -file("src/gilly/internal/codegen.gleam", 3439). ?DOC(false). -spec separator_comment(binary()) -> glam@doc:document(). separator_comment(Value) -> _pipe = gleam@string:pad_end( <<<<"// --- "/utf8, Value/binary>>/binary, " "/utf8>>, 80, <<"-"/utf8>> ), glam@doc:from_string(_pipe). -file("src/gilly/internal/codegen.gleam", 3464). ?DOC(false). -spec enum_type_doc(binary(), list(binary()), integer()) -> glam@doc:document(). enum_type_doc(Type_name, Variants, Indent) -> Variant_docs = gleam@list:map( Variants, fun(V) -> glam@doc:from_string(enum_variant_name(Type_name, V)) end ), glam@doc:concat( [glam@doc:from_string( <<<<"pub type "/utf8, Type_name/binary>>/binary, " {"/utf8>> ), begin _pipe = {line, 1}, glam@doc:nest(_pipe, Indent) end, begin _pipe@1 = glam@doc:join(Variant_docs, {line, 1}), glam@doc:nest(_pipe@1, Indent) end, {line, 1}, glam@doc:from_string(<<"}"/utf8>>)] ). -file("src/gilly/internal/codegen.gleam", 3484). ?DOC(false). -spec enum_to_string_doc(binary(), list(binary()), integer()) -> glam@doc:document(). enum_to_string_doc(Type_name, Variants, Indent) -> Fn_name = <<(justin:snake_case(Type_name))/binary, "_to_string"/utf8>>, Var_name = <<"value"/utf8>>, Case_lines = gleam@list:map( Variants, fun(V) -> glam@doc:concat( [glam@doc:from_string(enum_variant_name(Type_name, V)), glam@doc:from_string(<<" -> "/utf8>>), glam@doc:from_string( <<<<"\""/utf8, V/binary>>/binary, "\""/utf8>> )] ) end ), Case_block = glam@doc:concat( [glam@doc:from_string( <<<<"case "/utf8, Var_name/binary>>/binary, " {"/utf8>> ), begin _pipe = {line, 1}, glam@doc:nest(_pipe, Indent) end, begin _pipe@1 = glam@doc:join(Case_lines, {line, 1}), glam@doc:nest(_pipe@1, Indent) end, {line, 1}, glam@doc:from_string(<<"}"/utf8>>)] ), glam@doc:concat( [glam@doc:from_string( <<<<<<<<<<<<"pub fn "/utf8, Fn_name/binary>>/binary, "("/utf8>>/binary, Var_name/binary>>/binary, ": "/utf8>>/binary, Type_name/binary>>/binary, ") -> String {"/utf8>> ), begin _pipe@2 = {line, 1}, glam@doc:nest(_pipe@2, Indent) end, begin _pipe@3 = Case_block, glam@doc:nest(_pipe@3, Indent) end, {line, 1}, glam@doc:from_string(<<"}"/utf8>>)] ). -file("src/gilly/internal/codegen.gleam", 3528). ?DOC(false). -spec enum_to_json_doc(binary(), list(binary()), integer()) -> glam@doc:document(). enum_to_json_doc(Type_name, _, Indent) -> Fn_name = <<(justin:snake_case(Type_name))/binary, "_to_json"/utf8>>, To_string_fn = <<(justin:snake_case(Type_name))/binary, "_to_string"/utf8>>, Var_name = <<"value"/utf8>>, glam@doc:concat( [glam@doc:from_string( <<<<<<<<<<<<"pub fn "/utf8, Fn_name/binary>>/binary, "("/utf8>>/binary, Var_name/binary>>/binary, ": "/utf8>>/binary, Type_name/binary>>/binary, ") -> json.Json {"/utf8>> ), begin _pipe = {line, 1}, glam@doc:nest(_pipe, Indent) end, begin _pipe@1 = glam@doc:from_string( <<<<<<<<"json.string("/utf8, To_string_fn/binary>>/binary, "("/utf8>>/binary, Var_name/binary>>/binary, "))"/utf8>> ), glam@doc:nest(_pipe@1, Indent) end, {line, 1}, glam@doc:from_string(<<"}"/utf8>>)] ). -file("src/gilly/internal/codegen.gleam", 3555). ?DOC(false). -spec enum_decoder_doc(binary(), list(binary()), integer()) -> glam@doc:document(). enum_decoder_doc(Type_name, Variants, Indent) -> Decoder_name = enum_decoder_name(Type_name), Var_name = <<"value"/utf8>>, Success_cases = gleam@list:map( Variants, fun(V) -> glam@doc:concat( [glam@doc:from_string( <<<<"\""/utf8, V/binary>>/binary, "\" -> "/utf8>> ), glam@doc:from_string( <<<<"decode.success("/utf8, (enum_variant_name(Type_name, V))/binary>>/binary, ")"/utf8>> )] ) end ), First_variant = case Variants of [First | _] -> enum_variant_name(Type_name, First); [] -> <<"Nil"/utf8>> end, Failure_case = glam@doc:concat( [glam@doc:from_string(<<"_ -> "/utf8>>), glam@doc:from_string( <<<<<<<<"decode.failure("/utf8, First_variant/binary>>/binary, ", \""/utf8>>/binary, Type_name/binary>>/binary, "\")"/utf8>> )] ), Case_body = lists:append(Success_cases, [Failure_case]), Case_block = glam@doc:concat( [glam@doc:from_string( <<<<"case "/utf8, Var_name/binary>>/binary, " {"/utf8>> ), begin _pipe = {line, 1}, glam@doc:nest(_pipe, Indent) end, begin _pipe@1 = glam@doc:join(Case_body, {line, 1}), glam@doc:nest(_pipe@1, Indent) end, {line, 1}, glam@doc:from_string(<<"}"/utf8>>)] ), Fn_body = glam@doc:concat( [glam@doc:from_string( <<<<"use "/utf8, Var_name/binary>>/binary, " <- decode.then(decode.string)"/utf8>> ), {line, 1}, Case_block] ), Return_type = glam@doc:from_string( <<<<"decode.Decoder("/utf8, Type_name/binary>>/binary, ")"/utf8>> ), glam@doc:concat( [glam@doc:from_string( <<<<"pub fn "/utf8, Decoder_name/binary>>/binary, "() -> "/utf8>> ), Return_type, glam@doc:from_string(<<" {"/utf8>>), begin _pipe@2 = {line, 1}, glam@doc:nest(_pipe@2, Indent) end, begin _pipe@3 = Fn_body, glam@doc:nest(_pipe@3, Indent) end, {line, 1}, glam@doc:from_string(<<"}"/utf8>>)] ). -file("src/gilly/internal/codegen.gleam", 3444). ?DOC(false). -spec enums_doc(state(), integer()) -> glam@doc:document(). enums_doc(State, Indent) -> Sorted_enums = begin _pipe = maps:to_list(erlang:element(3, State)), gleam@list:sort( _pipe, fun(A, B) -> gleam@string:compare(erlang:element(1, A), erlang:element(1, B)) end ) end, _pipe@1 = gleam@list:map( Sorted_enums, fun(Entry) -> {Type_name, Variants} = Entry, glam@doc:concat( [enum_type_doc(Type_name, Variants, Indent), glam@doc:lines(2), enum_to_string_doc(Type_name, Variants, Indent), glam@doc:lines(2), enum_to_json_doc(Type_name, Variants, Indent), glam@doc:lines(2), enum_decoder_doc(Type_name, Variants, Indent)] ) end ), glam@doc:join(_pipe@1, glam@doc:lines(2)). -file("src/gilly/internal/codegen.gleam", 2875). ?DOC(false). -spec array_to_json( state(), gilly@openapi@schema:array_schema(), binary(), list({binary(), gilly@openapi@schema:schema()}), binary() ) -> {state(), glam@doc:document()}. array_to_json(State, Array_schema, Accessor, All_schemas, Enum_name_hint) -> {State@1, Item_encoder} = schema_to_json_expression_inner( State, erlang:element(4, Array_schema), <<"item"/utf8>>, All_schemas, Enum_name_hint, false ), {State@1, glam@doc:concat( [glam@doc:from_string( <<<<"json.array("/utf8, Accessor/binary>>/binary, ", fn(item) { "/utf8>> ), Item_encoder, glam@doc:from_string(<<" })"/utf8>>)] )}. -file("src/gilly/internal/codegen.gleam", 2791). ?DOC(false). -spec schema_to_json_expression_inner( state(), gilly@openapi@schema:schema(), binary(), list({binary(), gilly@openapi@schema:schema()}), binary(), boolean() ) -> {state(), glam@doc:document()}. schema_to_json_expression_inner( State, Schema, Accessor, All_schemas, Enum_name_hint, Request_only ) -> case Schema of {string, _, String_schema} -> string_to_json(State, String_schema, Accessor, Enum_name_hint); {integer, _, _} -> {State, glam@doc:from_string( <<<<"json.int("/utf8, Accessor/binary>>/binary, ")"/utf8>> )}; {number, _} -> {State, glam@doc:from_string( <<<<"json.float("/utf8, Accessor/binary>>/binary, ")"/utf8>> )}; {boolean, _} -> {State, glam@doc:from_string( <<<<"json.bool("/utf8, Accessor/binary>>/binary, ")"/utf8>> )}; {array, _, Array_schema} -> array_to_json( State, Array_schema, Accessor, All_schemas, Enum_name_hint ); {ref, Ref} -> ref_to_json(State, Ref, Accessor, All_schemas); {object, _, Object_schema} -> case is_map_object(Object_schema) of true -> Value_schema = map_value_schema(Object_schema), {State@1, Value_encoder} = schema_to_json_encoder_fn( State, Value_schema, All_schemas, Enum_name_hint, Request_only ), {State@1, glam@doc:concat( [glam@doc:from_string( <<<<"json.dict("/utf8, Accessor/binary>>/binary, ", fn(k) { k }, "/utf8>> ), Value_encoder, glam@doc:from_string(<<")"/utf8>>)] )}; false -> case Request_only of true -> {State, glam@doc:from_string(Accessor)}; false -> {State, glam@doc:from_string(<<"json.null()"/utf8>>)} end end end. -file("src/gilly/internal/codegen.gleam", 1886). ?DOC(false). -spec build_request_lines( state(), binary(), list(gilly@openapi@operation:parameter()), gleam@option:option({binary(), glam@doc:document(), gilly@openapi@schema:schema()}), list({binary(), gilly@openapi@schema:schema()}), binary(), gleam@set:set(binary()) ) -> list(glam@doc:document()). build_request_lines( State, Method, Query_params, Body_param, All_schemas, Params_prefix, Promoted ) -> Method_line = glam@doc:from_string( <<<<"let req = request.set_method(req, http."/utf8, Method/binary>>/binary, ")"/utf8>> ), Header_line = glam@doc:from_string( <<"let req = request.prepend_header(req, \"content-type\", \"application/json\")"/utf8>> ), Body_line = case Body_param of {some, {Arg_name, _, Body_schema}} -> {_, Encode_expr} = schema_to_json_expression_inner( State, Body_schema, Arg_name, All_schemas, Arg_name, false ), Encode_str = glam@doc:to_string(Encode_expr, 80), [glam@doc:from_string( <<<<"let req = request.set_body(req, json.to_string("/utf8, Encode_str/binary>>/binary, "))"/utf8>> )]; none -> [] end, Query_lines = case Query_params of [] -> []; _ -> Is_array_param = fun(P) -> case erlang:element(6, P) of {some, {array, _, _}} -> true; _ -> false end end, Is_effectively_required = fun(P@1) -> erlang:element(5, P@1) orelse gleam@set:contains( Promoted, erlang:element(2, P@1) ) end, Param_var_name = fun(P@2) -> case gleam@set:contains(Promoted, erlang:element(2, P@2)) of true -> to_field_name(erlang:element(2, P@2)); false -> <> end end, Required_scalar_entries = begin _pipe = gleam@list:filter( Query_params, fun(P@3) -> Is_effectively_required(P@3) andalso not Is_array_param( P@3 ) end ), gleam@list:map( _pipe, fun(Param) -> Pname = Param_var_name(Param), Value_expr = case query_param_to_string_expr( Param, All_schemas ) of <<"v"/utf8>> -> Pname; Conv -> gleam@string:replace(Conv, <<"v"/utf8>>, Pname) end, glam@doc:from_string( <<<<<<<<"#(\""/utf8, (erlang:element(2, Param))/binary>>/binary, "\", "/utf8>>/binary, Value_expr/binary>>/binary, ")"/utf8>> ) end ) end, Required_array_lines = begin _pipe@1 = gleam@list:filter( Query_params, fun(P@4) -> Is_effectively_required(P@4) andalso Is_array_param(P@4) end ), gleam@list:map( _pipe@1, fun(Param@1) -> Pname@1 = Param_var_name(Param@1), Value_expr@1 = query_param_to_string_expr( Param@1, All_schemas ), glam@doc:from_string( <<<<<<<<<<<<"let query = list.append(query, list.map("/utf8, Pname@1/binary>>/binary, ", fn(v) { #(\""/utf8>>/binary, (erlang:element(2, Param@1))/binary>>/binary, "\", "/utf8>>/binary, Value_expr@1/binary>>/binary, ") }))"/utf8>> ) end ) end, Optional_scalar_entries = begin _pipe@2 = gleam@list:filter( Query_params, fun(P@5) -> not Is_effectively_required(P@5) andalso not Is_array_param( P@5 ) end ), gleam@list:map( _pipe@2, fun(Param@2) -> Pname@2 = Param_var_name(Param@2), Value_expr@2 = query_param_to_string_expr( Param@2, All_schemas ), glam@doc:from_string( <<<<<<<<<<<<"option.map("/utf8, Pname@2/binary>>/binary, ", fn(v) { #(\""/utf8>>/binary, (erlang:element(2, Param@2))/binary>>/binary, "\", "/utf8>>/binary, Value_expr@2/binary>>/binary, ") })"/utf8>> ) end ) end, Optional_array_lines = begin _pipe@3 = gleam@list:filter( Query_params, fun(P@6) -> not Is_effectively_required(P@6) andalso Is_array_param( P@6 ) end ), gleam@list:map( _pipe@3, fun(Param@3) -> Pname@3 = Param_var_name(Param@3), Value_expr@3 = query_param_to_string_expr( Param@3, All_schemas ), glam@doc:from_string( <<<<<<<<<<<<"let query = list.append(query, "/utf8, Pname@3/binary>>/binary, " |> option.unwrap([]) |> list.map(fn(v) { #(\""/utf8>>/binary, (erlang:element(2, Param@3))/binary>>/binary, "\", "/utf8>>/binary, Value_expr@3/binary>>/binary, ") }))"/utf8>> ) end ) end, Required_list = case Required_scalar_entries of [] -> glam@doc:from_string(<<"[]"/utf8>>); _ -> glam@doc:concat( [glam@doc:from_string(<<"["/utf8>>), glam@doc:join( Required_scalar_entries, glam@doc:from_string(<<", "/utf8>>) ), glam@doc:from_string(<<"]"/utf8>>)] ) end, Optional_scalar_part = case Optional_scalar_entries of [] -> []; _ -> [glam@doc:from_string( <<"let query = list.append(query, option.values(["/utf8>> ) | lists:append( gleam@list:map( Optional_scalar_entries, fun(Entry) -> glam@doc:concat( [glam@doc:from_string(<<" "/utf8>>), Entry, glam@doc:from_string(<<","/utf8>>)] ) end ), [glam@doc:from_string(<<"]))"/utf8>>)] )] end, lists:append( [[glam@doc:concat( [glam@doc:from_string(<<"let query = "/utf8>>), Required_list] )], Required_array_lines, Optional_scalar_part, Optional_array_lines, [glam@doc:from_string( <<"let req = request.set_query(req, query)"/utf8>> )]] ) end, _pipe@4 = [Method_line, Header_line], _pipe@5 = lists:append(_pipe@4, Body_line), lists:append(_pipe@5, Query_lines). -file("src/gilly/internal/codegen.gleam", 2748). ?DOC(false). -spec ref_to_json_fn( state(), binary(), list({binary(), gilly@openapi@schema:schema()}) ) -> {state(), glam@doc:document()}. ref_to_json_fn(State, Ref, All_schemas) -> Raw_name = case gleam@string:split(Ref, <<"/"/utf8>>) of [_, _, _, Name | _] -> Name; _ -> Ref end, Type_name = to_type_name(Raw_name), case gleam@list:key_find(All_schemas, Raw_name) of {ok, {object, _, Object_schema}} -> case is_map_object(Object_schema) of true -> Value_schema = map_value_schema(Object_schema), {State@1, Value_encoder} = schema_to_json_encoder_fn( State, Value_schema, All_schemas, Type_name, false ), {State@1, glam@doc:concat( [glam@doc:from_string( <<"json.dict(_, fn(k) { k }, "/utf8>> ), Value_encoder, glam@doc:from_string(<<")"/utf8>>)] )}; false -> To_json_fn = <<(justin:snake_case(Type_name))/binary, "_to_json"/utf8>>, {State, glam@doc:from_string(To_json_fn)} end; {ok, Schema} -> schema_to_json_encoder_fn( State, Schema, All_schemas, Type_name, false ); {error, _} -> {State, glam@doc:from_string(<<"fn(_) { json.null() }"/utf8>>)} end. -file("src/gilly/internal/codegen.gleam", 2671). ?DOC(false). -spec schema_to_json_encoder_fn( state(), gilly@openapi@schema:schema(), list({binary(), gilly@openapi@schema:schema()}), binary(), boolean() ) -> {state(), glam@doc:document()}. schema_to_json_encoder_fn( State, Schema, All_schemas, Enum_name_hint, Request_only ) -> case Schema of {string, _, String_schema} -> string_to_json_fn(State, String_schema, Enum_name_hint); {integer, _, _} -> {State, glam@doc:from_string(<<"json.int"/utf8>>)}; {number, _} -> {State, glam@doc:from_string(<<"json.float"/utf8>>)}; {boolean, _} -> {State, glam@doc:from_string(<<"json.bool"/utf8>>)}; {array, _, Array_schema} -> {State@1, Item_fn} = schema_to_json_encoder_fn( State, erlang:element(4, Array_schema), All_schemas, Enum_name_hint, Request_only ), {State@1, glam@doc:concat( [glam@doc:from_string(<<"json.array(_, "/utf8>>), Item_fn, glam@doc:from_string(<<")"/utf8>>)] )}; {ref, Ref} -> ref_to_json_fn(State, Ref, All_schemas); {object, _, Object_schema} -> case is_map_object(Object_schema) of true -> Value_schema = map_value_schema(Object_schema), {State@2, Value_encoder} = schema_to_json_encoder_fn( State, Value_schema, All_schemas, Enum_name_hint, Request_only ), {State@2, glam@doc:concat( [glam@doc:from_string( <<"json.dict(_, fn(k) { k }, "/utf8>> ), Value_encoder, glam@doc:from_string(<<")"/utf8>>)] )}; false -> case Request_only of true -> {State, glam@doc:from_string(<<"fn(v) { v }"/utf8>>)}; false -> {State, glam@doc:from_string( <<"fn(_) { json.null() }"/utf8>> )} end end end. -file("src/gilly/internal/codegen.gleam", 2629). ?DOC(false). -spec schema_to_json_expression( state(), gilly@openapi@schema:schema(), binary(), list({binary(), gilly@openapi@schema:schema()}), binary(), boolean(), boolean() ) -> {state(), glam@doc:document()}. schema_to_json_expression( State, Schema, Accessor, All_schemas, Enum_name_hint, Optional, Request_only ) -> case Optional of true -> {State@1, Encoder_fn} = schema_to_json_encoder_fn( State, Schema, All_schemas, Enum_name_hint, Request_only ), {State@1, glam@doc:concat( [glam@doc:from_string( <<<<"json.nullable("/utf8, Accessor/binary>>/binary, ", "/utf8>> ), Encoder_fn, glam@doc:from_string(<<")"/utf8>>)] )}; false -> schema_to_json_expression_inner( State, Schema, Accessor, All_schemas, Enum_name_hint, Request_only ) end. -file("src/gilly/internal/codegen.gleam", 2901). ?DOC(false). -spec ref_to_json( state(), binary(), binary(), list({binary(), gilly@openapi@schema:schema()}) ) -> {state(), glam@doc:document()}. ref_to_json(State, Ref, Accessor, All_schemas) -> Raw_name = case gleam@string:split(Ref, <<"/"/utf8>>) of [_, _, _, Name | _] -> Name; _ -> Ref end, Type_name = to_type_name(Raw_name), case gleam@list:key_find(All_schemas, Raw_name) of {ok, {object, _, Object_schema}} -> case is_map_object(Object_schema) of true -> Value_schema = map_value_schema(Object_schema), {State@1, Value_encoder} = schema_to_json_encoder_fn( State, Value_schema, All_schemas, Type_name, false ), {State@1, glam@doc:concat( [glam@doc:from_string( <<<<"json.dict("/utf8, Accessor/binary>>/binary, ", fn(k) { k }, "/utf8>> ), Value_encoder, glam@doc:from_string(<<")"/utf8>>)] )}; false -> To_json_fn = <<(justin:snake_case(Type_name))/binary, "_to_json"/utf8>>, {State, glam@doc:from_string( <<<<<>/binary, Accessor/binary>>/binary, ")"/utf8>> )} end; {ok, Schema} -> schema_to_json_expression_inner( State, Schema, Accessor, All_schemas, Type_name, false ); {error, _} -> {State, glam@doc:from_string(<<"json.null()"/utf8>>)} end. -file("src/gilly/internal/codegen.gleam", 3171). ?DOC(false). -spec record_to_json_doc( state(), binary(), gilly@openapi@schema:object_schema(), list({binary(), gilly@openapi@schema:schema()}), config(), boolean(), gleam@set:set(binary()) ) -> {state(), glam@doc:document()}. record_to_json_doc( State, Type_name, Object_schema, All_schemas, Config, Request_only, Promoted_body_fields ) -> State@1 = import_module(State, <<"gleam/json"/utf8>>), Fn_name = <<(justin:snake_case(Type_name))/binary, "_to_json"/utf8>>, Indent = erlang:element(3, Config), {State@4, Field_pairs} = gleam@list:fold( erlang:element(3, Object_schema), {State@1, []}, fun(Acc, Prop) -> {State@2, Pairs} = Acc, {Prop_name, Prop_schema} = Prop, Field_name = to_field_name(Prop_name), In_required = gleam@list:contains( erlang:element(2, Object_schema), Prop_name ), Optional = is_field_optional( Prop_schema, In_required, erlang:element(2, Config) ) orelse gleam@set:contains(Promoted_body_fields, Prop_name), Enum_hint = <>, Accessor = <<"value."/utf8, Field_name/binary>>, {State@3, Json_expr} = schema_to_json_expression( State@2, Prop_schema, Accessor, All_schemas, Enum_hint, Optional, Request_only ), Pair = glam@doc:concat( [glam@doc:from_string( <<<<"#(\""/utf8, Prop_name/binary>>/binary, "\", "/utf8>> ), Json_expr, glam@doc:from_string(<<")"/utf8>>)] ), {State@3, [Pair | Pairs]} end ), Field_pairs@1 = lists:reverse(Field_pairs), Body = case Field_pairs@1 of [] -> glam@doc:from_string(<<"json.object([])"/utf8>>); _ -> glam@doc:concat( [glam@doc:from_string(<<"json.object(["/utf8>>), begin _pipe = {line, 1}, glam@doc:nest(_pipe, Indent) end, begin _pipe@1 = glam@doc:join( Field_pairs@1, glam@doc:concat( [glam@doc:from_string(<<","/utf8>>), {line, 1}] ) ), glam@doc:nest(_pipe@1, Indent) end, glam@doc:concat( [glam@doc:from_string(<<","/utf8>>), {line, 1}] ), glam@doc:from_string(<<"])"/utf8>>)] ) end, Result = glam@doc:concat( [glam@doc:from_string( <<<<<<<<"pub fn "/utf8, Fn_name/binary>>/binary, "(value: "/utf8>>/binary, Type_name/binary>>/binary, ") -> json.Json {"/utf8>> ), begin _pipe@2 = {line, 1}, glam@doc:nest(_pipe@2, Indent) end, begin _pipe@3 = Body, glam@doc:nest(_pipe@3, Indent) end, {line, 1}, glam@doc:from_string(<<"}"/utf8>>)] ), {State@4, Result}. -file("src/gilly/internal/codegen.gleam", 2565). ?DOC(false). -spec array_decoder( state(), gilly@openapi@schema:array_schema(), list({binary(), gilly@openapi@schema:schema()}), binary() ) -> {state(), glam@doc:document()}. array_decoder(State, Array_schema, All_schemas, Enum_name_hint) -> {State@1, Items_decoder} = schema_to_inner_decoder( State, erlang:element(4, Array_schema), All_schemas, Enum_name_hint ), {State@1, glam@doc:concat( [glam@doc:from_string(<<"decode.list("/utf8>>), Items_decoder, glam@doc:from_string(<<")"/utf8>>)] )}. -file("src/gilly/internal/codegen.gleam", 2505). ?DOC(false). -spec schema_to_inner_decoder( state(), gilly@openapi@schema:schema(), list({binary(), gilly@openapi@schema:schema()}), binary() ) -> {state(), glam@doc:document()}. schema_to_inner_decoder(State, Schema, All_schemas, Enum_name_hint) -> case Schema of {ref, Ref} -> ref_to_decoder(State, Ref, All_schemas); {string, _, String_schema} -> string_decoder(State, String_schema, Enum_name_hint); {integer, _, _} -> {State, glam@doc:from_string(<<"decode.int"/utf8>>)}; {number, _} -> {State, glam@doc:from_string(<<"decode.float"/utf8>>)}; {boolean, _} -> {State, glam@doc:from_string(<<"decode.bool"/utf8>>)}; {array, _, Array_schema} -> array_decoder(State, Array_schema, All_schemas, Enum_name_hint); {object, _, Object_schema} -> case is_map_object(Object_schema) of true -> Value_schema = map_value_schema(Object_schema), {State@1, Value_decoder} = schema_to_inner_decoder( State, Value_schema, All_schemas, Enum_name_hint ), {State@1, glam@doc:concat( [glam@doc:from_string( <<"decode.dict(decode.string, "/utf8>> ), Value_decoder, glam@doc:from_string(<<")"/utf8>>)] )}; false -> {State, glam@doc:from_string(<<"decode.dynamic"/utf8>>)} end end. -file("src/gilly/internal/codegen.gleam", 2064). ?DOC(false). -spec build_decode_line( state(), gleam@option:option({glam@doc:document(), gilly@openapi@schema:schema()}), list({binary(), gilly@openapi@schema:schema()}) ) -> {state(), glam@doc:document()}. build_decode_line(State, Response_type, All_schemas) -> case Response_type of {some, {_, Resp_schema}} -> {State@1, Decoder_doc} = schema_to_inner_decoder( State, Resp_schema, All_schemas, <<"response"/utf8>> ), Decoder_str = glam@doc:to_string(Decoder_doc, 80), {State@1, glam@doc:concat( [glam@doc:from_string( <<"use resp <- result.try(client.http_client(req) |> result.map_error(ClientError))"/utf8>> ), {line, 1}, glam@doc:from_string( <<<<"json.parse(resp.body, "/utf8, Decoder_str/binary>>/binary, ")"/utf8>> ), {line, 1}, glam@doc:from_string( <<"|> result.map_error(JsonDecodeError)"/utf8>> )] )}; none -> {State, glam@doc:concat( [glam@doc:from_string( <<"use resp <- result.try(client.http_client(req) |> result.map_error(ClientError))"/utf8>> ), {line, 1}, glam@doc:from_string(<<"let _ = resp"/utf8>>), {line, 1}, glam@doc:from_string(<<"Ok(Nil)"/utf8>>)] )} end. -file("src/gilly/internal/codegen.gleam", 2588). ?DOC(false). -spec ref_to_decoder( state(), binary(), list({binary(), gilly@openapi@schema:schema()}) ) -> {state(), glam@doc:document()}. ref_to_decoder(State, Ref, All_schemas) -> Raw_name = case gleam@string:split(Ref, <<"/"/utf8>>) of [_, _, _, Name | _] -> Name; _ -> Ref end, Type_name = to_type_name(Raw_name), case gleam@list:key_find(All_schemas, Raw_name) of {ok, {object, _, Object_schema}} -> case is_map_object(Object_schema) of true -> Value_schema = map_value_schema(Object_schema), {State@1, Value_decoder} = schema_to_inner_decoder( State, Value_schema, All_schemas, Type_name ), {State@1, glam@doc:concat( [glam@doc:from_string( <<"decode.dict(decode.string, "/utf8>> ), Value_decoder, glam@doc:from_string(<<")"/utf8>>)] )}; false -> Decoder_name = <<(justin:snake_case(Type_name))/binary, "_decoder()"/utf8>>, {State, glam@doc:from_string(Decoder_name)} end; {ok, Schema} -> schema_to_inner_decoder(State, Schema, All_schemas, Type_name); {error, _} -> {State, glam@doc:from_string(<<"decode.dynamic"/utf8>>)} end. -file("src/gilly/internal/codegen.gleam", 3077). ?DOC(false). -spec record_decoder_doc( state(), binary(), gilly@openapi@schema:object_schema(), list({binary(), gilly@openapi@schema:schema()}), config() ) -> {state(), glam@doc:document()}. record_decoder_doc(State, Type_name, Object_schema, All_schemas, Config) -> State@1 = import_module(State, <<"gleam/dynamic/decode"/utf8>>), Decoder_name = <<(justin:snake_case(Type_name))/binary, "_decoder"/utf8>>, Indent = erlang:element(3, Config), {State@6, Field_lines} = gleam@list:fold( erlang:element(3, Object_schema), {State@1, []}, fun(Acc, Prop) -> {State@2, Lines} = Acc, {Prop_name, Prop_schema} = Prop, Field_name = to_field_name(Prop_name), In_required = gleam@list:contains( erlang:element(2, Object_schema), Prop_name ), Optional = is_field_optional( Prop_schema, In_required, erlang:element(2, Config) ), Enum_hint = <>, {State@3, Inner_decoder} = schema_to_inner_decoder( State@2, Prop_schema, All_schemas, Enum_hint ), {State@5, Line} = case Optional of false -> {State@3, glam@doc:concat( [glam@doc:from_string( <<<<<<<<"use "/utf8, Field_name/binary>>/binary, " <- decode.field(\""/utf8>>/binary, Prop_name/binary>>/binary, "\", "/utf8>> ), Inner_decoder, glam@doc:from_string(<<")"/utf8>>)] )}; true -> State@4 = import_qualified( State@3, <<"gleam/option"/utf8>>, <<"None"/utf8>> ), {State@4, glam@doc:concat( [glam@doc:from_string( <<<<<<<<"use "/utf8, Field_name/binary>>/binary, " <- decode.optional_field(\""/utf8>>/binary, Prop_name/binary>>/binary, "\", None, decode.optional("/utf8>> ), Inner_decoder, glam@doc:from_string(<<"))"/utf8>>)] )} end, {State@5, [Line | Lines]} end ), Field_lines@1 = lists:reverse(Field_lines), Labels = gleam@list:map( erlang:element(3, Object_schema), fun(Prop@1) -> <<(to_field_name(erlang:element(1, Prop@1)))/binary, ":"/utf8>> end ), Success_line = case Labels of [] -> glam@doc:from_string( <<<<"decode.success("/utf8, Type_name/binary>>/binary, ")"/utf8>> ); _ -> glam@doc:from_string( <<<<<<<<"decode.success("/utf8, Type_name/binary>>/binary, "("/utf8>>/binary, (gleam@string:join(Labels, <<", "/utf8>>))/binary>>/binary, "))"/utf8>> ) end, Body_lines = lists:append(Field_lines@1, [Success_line]), Return_type = glam@doc:from_string( <<<<"decode.Decoder("/utf8, Type_name/binary>>/binary, ")"/utf8>> ), Result = glam@doc:concat( [glam@doc:from_string( <<<<"pub fn "/utf8, Decoder_name/binary>>/binary, "() -> "/utf8>> ), Return_type, glam@doc:from_string(<<" {"/utf8>>), begin _pipe = {line, 1}, glam@doc:nest(_pipe, Indent) end, begin _pipe@1 = glam@doc:join(Body_lines, {line, 1}), glam@doc:nest(_pipe@1, Indent) end, {line, 1}, glam@doc:from_string(<<"}"/utf8>>)] ), {State@6, Result}. -file("src/gilly/internal/codegen.gleam", 2421). ?DOC(false). -spec array_type( state(), gilly@openapi@schema:array_schema(), list({binary(), gilly@openapi@schema:schema()}), binary(), boolean() ) -> {state(), glam@doc:document()}. array_type(State, Array_schema, All_schemas, Enum_name_hint, Request_only) -> {State@1, Items_type} = schema_to_gleam_type( State, erlang:element(4, Array_schema), true, All_schemas, Enum_name_hint, Request_only ), {State@1, glam@doc:concat( [glam@doc:from_string(<<"List("/utf8>>), Items_type, glam@doc:from_string(<<")"/utf8>>)] )}. -file("src/gilly/internal/codegen.gleam", 2374). ?DOC(false). -spec schema_to_gleam_type( state(), gilly@openapi@schema:schema(), boolean(), list({binary(), gilly@openapi@schema:schema()}), binary(), boolean() ) -> {state(), glam@doc:document()}. schema_to_gleam_type( State, Schema, Required, All_schemas, Enum_name_hint, Request_only ) -> {State@1, Inner} = case Schema of {ref, Ref} -> {State, glam@doc:from_string(ref_to_type_name(Ref))}; {string, _, String_schema} -> string_type(State, String_schema, Enum_name_hint); {integer, _, _} -> {State, glam@doc:from_string(<<"Int"/utf8>>)}; {number, _} -> {State, glam@doc:from_string(<<"Float"/utf8>>)}; {boolean, _} -> {State, glam@doc:from_string(<<"Bool"/utf8>>)}; {array, _, Array_schema} -> array_type( State, Array_schema, All_schemas, Enum_name_hint, Request_only ); {object, _, Object_schema} -> inline_object_type(State, Object_schema, All_schemas, Request_only) end, case Required of true -> {State@1, Inner}; false -> wrap_optional(State@1, Inner) end. -file("src/gilly/internal/codegen.gleam", 1665). ?DOC(false). -spec param_to_type( state(), gilly@openapi@operation:parameter(), list({binary(), gilly@openapi@schema:schema()}) ) -> {state(), glam@doc:document()}. param_to_type(State, Param, All_schemas) -> case erlang:element(6, Param) of {some, {string, _, _}} -> {State, glam@doc:from_string(<<"String"/utf8>>)}; {some, Schema} -> schema_to_gleam_type( State, Schema, true, All_schemas, erlang:element(2, Param), false ); none -> {State, glam@doc:from_string(<<"String"/utf8>>)} end. -file("src/gilly/internal/codegen.gleam", 1076). ?DOC(false). -spec operation_request_docs( state(), binary(), list(gilly@openapi@operation:parameter()), list(gilly@openapi@operation:parameter()), gleam@option:option({binary(), glam@doc:document()}), list({binary(), gilly@openapi@schema:schema()}), config() ) -> {state(), list(glam@doc:document())}. operation_request_docs( State, Type_name, Path_params, Query_params, Body_ref, All_schemas, Config ) -> Indent = erlang:element(3, Config), All_params = lists:append(Path_params, Query_params), {State@3, Fields@1} = gleam@list:fold( All_params, {State, []}, fun(Acc, Param) -> {State@1, Fields} = Acc, Field_name = to_field_name(erlang:element(2, Param)), {State@2, Type_doc} = param_to_type(State@1, Param, All_schemas), Field_doc = case erlang:element(5, Param) of true -> glam@doc:concat( [glam@doc:from_string(<>), Type_doc] ); false -> glam@doc:concat( [glam@doc:from_string( <> ), Type_doc, glam@doc:from_string(<<")"/utf8>>)] ) end, {State@2, lists:append(Fields, [Field_doc])} end ), Fields@2 = case Body_ref of {some, {Name, Btype_doc}} -> Field_doc@1 = glam@doc:concat( [glam@doc:from_string( <<(to_field_name(Name))/binary, ": "/utf8>> ), Btype_doc] ), lists:append(Fields@1, [Field_doc@1]); none -> Fields@1 end, Has_optional = gleam@list:any( All_params, fun(P) -> not erlang:element(5, P) end ), State@4 = case Has_optional of true -> import_qualified( State@3, <<"gleam/option"/utf8>>, <<"type Option"/utf8>> ); false -> State@3 end, Type_doc@1 = case Fields@2 of [] -> glam@doc:concat( [glam@doc:from_string( <<<<"pub opaque type "/utf8, Type_name/binary>>/binary, " {"/utf8>> ), begin _pipe = {line, 1}, glam@doc:nest(_pipe, Indent) end, begin _pipe@1 = glam@doc:from_string(Type_name), glam@doc:nest(_pipe@1, Indent) end, {line, 1}, glam@doc:from_string(<<"}"/utf8>>)] ); _ -> glam@doc:concat( [glam@doc:from_string( <<<<"pub opaque type "/utf8, Type_name/binary>>/binary, " {"/utf8>> ), begin _pipe@2 = {line, 1}, glam@doc:nest(_pipe@2, Indent) end, begin _pipe@5 = glam@doc:concat( [glam@doc:from_string( <> ), begin _pipe@3 = {line, 1}, glam@doc:nest(_pipe@3, Indent) end, begin _pipe@4 = glam@doc:join( Fields@2, glam@doc:concat( [glam@doc:from_string(<<","/utf8>>), {line, 1}] ) ), glam@doc:nest(_pipe@4, Indent) end, glam@doc:concat( [glam@doc:from_string(<<","/utf8>>), {line, 1}] ), glam@doc:from_string(<<")"/utf8>>)] ), glam@doc:nest(_pipe@5, Indent) end, {line, 1}, glam@doc:from_string(<<"}"/utf8>>)] ) end, Required_params = gleam@list:filter( All_params, fun(P@1) -> erlang:element(5, P@1) end ), Optional_params = gleam@list:filter( All_params, fun(P@2) -> not erlang:element(5, P@2) end ), State@5 = case gleam@list:is_empty(Optional_params) of true -> State@4; false -> import_qualified(State@4, <<"gleam/option"/utf8>>, <<"None"/utf8>>) end, {State@8, Required_args} = gleam@list:fold( Required_params, {State@5, []}, fun(Acc@1, Param@1) -> {State@6, Args} = Acc@1, Field_name@1 = to_field_name(erlang:element(2, Param@1)), {State@7, Type_doc@2} = param_to_type(State@6, Param@1, All_schemas), Arg = glam@doc:concat( [glam@doc:from_string( <<<<<>/binary, Field_name@1/binary>>/binary, ": "/utf8>> ), Type_doc@2] ), {State@7, lists:append(Args, [Arg])} end ), Required_args@1 = case Body_ref of {some, {Name@1, Btype_doc@1}} -> Arg@1 = glam@doc:concat( [glam@doc:from_string( <<<<<<(to_field_name(Name@1))/binary, " "/utf8>>/binary, (to_field_name(Name@1))/binary>>/binary, ": "/utf8>> ), Btype_doc@1] ), lists:append(Required_args, [Arg@1]); none -> Required_args end, Field_inits = gleam@list:map( All_params, fun(Param@2) -> Field_name@2 = to_field_name(erlang:element(2, Param@2)), case erlang:element(5, Param@2) of true -> <>; false -> <> end end ), Field_inits@1 = case Body_ref of {some, {Name@2, _}} -> lists:append( Field_inits, [<<(to_field_name(Name@2))/binary, ":"/utf8>>] ); none -> Field_inits end, Constructor_body = glam@doc:from_string( <<<<<>/binary, (gleam@string:join(Field_inits@1, <<", "/utf8>>))/binary>>/binary, ")"/utf8>> ), Fn_name = <<"new_"/utf8, (justin:snake_case(Type_name))/binary>>, Constructor_doc = case Required_args@1 of [] -> glam@doc:concat( [glam@doc:from_string( <<<<<<<<"pub fn "/utf8, Fn_name/binary>>/binary, "() -> "/utf8>>/binary, Type_name/binary>>/binary, " {"/utf8>> ), begin _pipe@6 = {line, 1}, glam@doc:nest(_pipe@6, Indent) end, begin _pipe@7 = Constructor_body, glam@doc:nest(_pipe@7, Indent) end, {line, 1}, glam@doc:from_string(<<"}"/utf8>>)] ); _ -> glam@doc:concat( [glam@doc:from_string( <<<<"pub fn "/utf8, Fn_name/binary>>/binary, "("/utf8>> ), begin _pipe@8 = {line, 1}, glam@doc:nest(_pipe@8, Indent) end, begin _pipe@9 = glam@doc:join( Required_args@1, glam@doc:concat( [glam@doc:from_string(<<","/utf8>>), {line, 1}] ) ), glam@doc:nest(_pipe@9, Indent) end, glam@doc:concat( [glam@doc:from_string(<<","/utf8>>), {line, 1}] ), glam@doc:from_string( <<<<") -> "/utf8, Type_name/binary>>/binary, " {"/utf8>> ), begin _pipe@10 = {line, 1}, glam@doc:nest(_pipe@10, Indent) end, begin _pipe@11 = Constructor_body, glam@doc:nest(_pipe@11, Indent) end, {line, 1}, glam@doc:from_string(<<"}"/utf8>>)] ) end, Var_name = justin:snake_case(Type_name), {State@12, Setters@1} = gleam@list:fold( Optional_params, {State@8, []}, fun(Acc@2, Param@3) -> {State@9, Setters} = Acc@2, Field_name@3 = to_field_name(erlang:element(2, Param@3)), Setter_fn_name = <<<<(justin:snake_case(Type_name))/binary, "_with_"/utf8>>/binary, Field_name@3/binary>>, {State@10, Inner_type} = param_to_type( State@9, Param@3, All_schemas ), State@11 = import_qualified( State@10, <<"gleam/option"/utf8>>, <<"Some"/utf8>> ), Comment_part = case erlang:element(4, Param@3) of {some, Desc} -> [description_to_comment(Desc), {line, 1}]; none -> [] end, Setter_doc = glam@doc:concat( lists:append( Comment_part, [glam@doc:from_string( <<<<"pub fn "/utf8, Setter_fn_name/binary>>/binary, "("/utf8>> ), begin _pipe@12 = {line, 1}, glam@doc:nest(_pipe@12, Indent) end, begin _pipe@13 = glam@doc:from_string( <<<<<>/binary, Type_name/binary>>/binary, ","/utf8>> ), glam@doc:nest(_pipe@13, Indent) end, begin _pipe@14 = {line, 1}, glam@doc:nest(_pipe@14, Indent) end, begin _pipe@15 = glam@doc:concat( [glam@doc:from_string( <<<<<>/binary, Field_name@3/binary>>/binary, ": "/utf8>> ), Inner_type, glam@doc:from_string(<<","/utf8>>)] ), glam@doc:nest(_pipe@15, Indent) end, {line, 1}, glam@doc:from_string( <<<<") -> "/utf8, Type_name/binary>>/binary, " {"/utf8>> ), begin _pipe@16 = {line, 1}, glam@doc:nest(_pipe@16, Indent) end, begin _pipe@17 = glam@doc:from_string( <<<<<<<<<<<<<>/binary, Var_name/binary>>/binary, ", "/utf8>>/binary, Field_name@3/binary>>/binary, ": Some("/utf8>>/binary, Field_name@3/binary>>/binary, "))"/utf8>> ), glam@doc:nest(_pipe@17, Indent) end, {line, 1}, glam@doc:from_string(<<"}"/utf8>>)] ) ), {State@11, lists:append(Setters, [Setter_doc])} end ), All_docs = begin _pipe@18 = [Type_doc@1, Constructor_doc], lists:append(_pipe@18, Setters@1) end, {State@12, All_docs}. -file("src/gilly/internal/codegen.gleam", 1718). ?DOC(false). -spec request_body_param( state(), gilly@openapi@operation:request_body(), list({binary(), gilly@openapi@schema:schema()}) ) -> {state(), gleam@option:option({binary(), glam@doc:document(), gilly@openapi@schema:schema()})}. request_body_param(State, Rb, All_schemas) -> case gleam@list:key_find(erlang:element(4, Rb), <<"application/json"/utf8>>) of {ok, Media_type} -> case erlang:element(2, Media_type) of {some, Body_schema} -> {State@1, Type_doc} = schema_to_gleam_type( State, Body_schema, true, All_schemas, <<"body"/utf8>>, false ), {State@1, {some, {<<"body"/utf8>>, Type_doc, Body_schema}}}; none -> {State, none} end; {error, _} -> {State, none} end. -file("src/gilly/internal/codegen.gleam", 1745). ?DOC(false). -spec response_type_from_op( state(), gilly@openapi@operation:operation(), list({binary(), gilly@openapi@schema:schema()}) ) -> {state(), gleam@option:option({glam@doc:document(), gilly@openapi@schema:schema()})}. response_type_from_op(State, Op, All_schemas) -> Response = begin _pipe = gleam@list:key_find(erlang:element(8, Op), <<"200"/utf8>>), _pipe@1 = result_or( _pipe, fun() -> gleam@list:key_find(erlang:element(8, Op), <<"201"/utf8>>) end ), result_or( _pipe@1, fun() -> gleam@list:key_find(erlang:element(8, Op), <<"default"/utf8>>) end ) end, case Response of {ok, Resp} -> case gleam@list:key_find( erlang:element(3, Resp), <<"application/json"/utf8>> ) of {ok, Media_type} -> case erlang:element(2, Media_type) of {some, Resp_schema} -> {State@1, Type_doc} = schema_to_gleam_type( State, Resp_schema, true, All_schemas, <<"response"/utf8>>, false ), {State@1, {some, {Type_doc, Resp_schema}}}; none -> {State, none} end; {error, _} -> {State, none} end; {error, _} -> {State, none} end. -file("src/gilly/internal/codegen.gleam", 2322). ?DOC(false). -spec simple_type_doc( state(), binary(), gilly@openapi@schema:schema(), list({binary(), gilly@openapi@schema:schema()}), config() ) -> {state(), glam@doc:document()}. simple_type_doc(State, Type_name, Schema, All_schemas, Config) -> {State@1, Gleam_type} = schema_to_gleam_type( State, Schema, true, All_schemas, Type_name, false ), Result = glam@doc:concat( [glam@doc:from_string( <<<<"pub type "/utf8, Type_name/binary>>/binary, " ="/utf8>> ), begin _pipe = {line, 1}, glam@doc:nest(_pipe, erlang:element(3, Config)) end, begin _pipe@1 = Gleam_type, glam@doc:nest(_pipe@1, erlang:element(3, Config)) end] ), {State@1, Result}. -file("src/gilly/internal/codegen.gleam", 2340). ?DOC(false). -spec map_type_doc( state(), binary(), gilly@openapi@schema:object_schema(), list({binary(), gilly@openapi@schema:schema()}), config() ) -> {state(), glam@doc:document()}. map_type_doc(State, Type_name, Object_schema, All_schemas, Config) -> Value_schema = map_value_schema(Object_schema), {State@1, Value_type} = schema_to_gleam_type( State, Value_schema, true, All_schemas, Type_name, false ), State@2 = import_qualified( State@1, <<"gleam/dict"/utf8>>, <<"type Dict"/utf8>> ), Result = glam@doc:concat( [glam@doc:from_string( <<<<"pub type "/utf8, Type_name/binary>>/binary, " ="/utf8>> ), begin _pipe = {line, 1}, glam@doc:nest(_pipe, erlang:element(3, Config)) end, begin _pipe@1 = glam@doc:concat( [glam@doc:from_string(<<"Dict(String, "/utf8>>), Value_type, glam@doc:from_string(<<")"/utf8>>)] ), glam@doc:nest(_pipe@1, erlang:element(3, Config)) end] ), {State@2, Result}. -file("src/gilly/internal/codegen.gleam", 2447). ?DOC(false). -spec inline_object_type( state(), gilly@openapi@schema:object_schema(), list({binary(), gilly@openapi@schema:schema()}), boolean() ) -> {state(), glam@doc:document()}. inline_object_type(State, Object_schema, All_schemas, Request_only) -> case is_map_object(Object_schema) of true -> Value_schema = map_value_schema(Object_schema), {State@1, Value_type} = schema_to_gleam_type( State, Value_schema, true, All_schemas, <<""/utf8>>, Request_only ), State@2 = import_qualified( State@1, <<"gleam/dict"/utf8>>, <<"type Dict"/utf8>> ), {State@2, glam@doc:concat( [glam@doc:from_string(<<"Dict(String, "/utf8>>), Value_type, glam@doc:from_string(<<")"/utf8>>)] )}; false -> case Request_only of true -> State@3 = import_module(State, <<"gleam/json"/utf8>>), {State@3, glam@doc:from_string(<<"json.Json"/utf8>>)}; false -> State@4 = import_qualified( State, <<"gleam/dynamic"/utf8>>, <<"type Dynamic"/utf8>> ), {State@4, glam@doc:from_string(<<"Dynamic"/utf8>>)} end end. -file("src/gilly/internal/codegen.gleam", 3248). ?DOC(false). -spec record_new_doc( state(), binary(), gilly@openapi@schema:object_schema(), list({binary(), gilly@openapi@schema:schema()}), config(), boolean() ) -> {state(), glam@doc:document()}. record_new_doc( State, Type_name, Object_schema, All_schemas, Config, Request_only ) -> Fn_name = <<"new_"/utf8, (justin:snake_case(Type_name))/binary>>, Indent = erlang:element(3, Config), Field_info = gleam@list:map( erlang:element(3, Object_schema), fun(Prop) -> {Prop_name, Prop_schema} = Prop, Field_name = to_field_name(Prop_name), In_required = gleam@list:contains( erlang:element(2, Object_schema), Prop_name ), Optional = is_field_optional( Prop_schema, In_required, erlang:element(2, Config) ), {Prop_name, Field_name, Prop_schema, Optional} end ), Has_optional = gleam@list:any( Field_info, fun(F) -> erlang:element(4, F) end ), State@1 = case Has_optional of true -> import_qualified(State, <<"gleam/option"/utf8>>, <<"None"/utf8>>); false -> State end, {State@4, Required_args} = gleam@list:fold( Field_info, {State@1, []}, fun(Acc, F@1) -> {State@2, Args} = Acc, {Prop_name@1, Field_name@1, Prop_schema@1, Optional@1} = F@1, case Optional@1 of true -> {State@2, Args}; false -> Enum_hint = <>, {State@3, Field_type} = schema_to_gleam_type( State@2, Prop_schema@1, true, All_schemas, Enum_hint, Request_only ), Arg = glam@doc:concat( [glam@doc:from_string( <<<<<>/binary, Field_name@1/binary>>/binary, ": "/utf8>> ), Field_type] ), {State@3, lists:append(Args, [Arg])} end end ), Field_inits = gleam@list:map( Field_info, fun(F@2) -> {_, Field_name@2, _, Optional@2} = F@2, case Optional@2 of true -> <>; false -> <> end end ), Constructor_body = case Field_inits of [] -> glam@doc:from_string(Type_name); _ -> glam@doc:from_string( <<<<<>/binary, (gleam@string:join(Field_inits, <<", "/utf8>>))/binary>>/binary, ")"/utf8>> ) end, Result = case Required_args of [] -> glam@doc:concat( [glam@doc:from_string( <<<<<<<<"pub fn "/utf8, Fn_name/binary>>/binary, "() -> "/utf8>>/binary, Type_name/binary>>/binary, " {"/utf8>> ), begin _pipe = {line, 1}, glam@doc:nest(_pipe, Indent) end, begin _pipe@1 = Constructor_body, glam@doc:nest(_pipe@1, Indent) end, {line, 1}, glam@doc:from_string(<<"}"/utf8>>)] ); _ -> glam@doc:concat( [glam@doc:from_string( <<<<"pub fn "/utf8, Fn_name/binary>>/binary, "("/utf8>> ), begin _pipe@2 = {line, 1}, glam@doc:nest(_pipe@2, Indent) end, begin _pipe@3 = glam@doc:join( Required_args, glam@doc:concat( [glam@doc:from_string(<<","/utf8>>), {line, 1}] ) ), glam@doc:nest(_pipe@3, Indent) end, glam@doc:concat( [glam@doc:from_string(<<","/utf8>>), {line, 1}] ), glam@doc:from_string( <<<<") -> "/utf8, Type_name/binary>>/binary, " {"/utf8>> ), begin _pipe@4 = {line, 1}, glam@doc:nest(_pipe@4, Indent) end, begin _pipe@5 = Constructor_body, glam@doc:nest(_pipe@5, Indent) end, {line, 1}, glam@doc:from_string(<<"}"/utf8>>)] ) end, {State@4, Result}. -file("src/gilly/internal/codegen.gleam", 3354). ?DOC(false). -spec record_with_field_docs( state(), binary(), gilly@openapi@schema:object_schema(), list({binary(), gilly@openapi@schema:schema()}), config(), boolean(), gleam@set:set(binary()) ) -> {state(), list(glam@doc:document())}. record_with_field_docs( State, Type_name, Object_schema, All_schemas, Config, Request_only, Promoted_body_fields ) -> Indent = erlang:element(3, Config), Var_name = justin:snake_case(Type_name), gleam@list:fold( erlang:element(3, Object_schema), {State, []}, fun(Acc, Prop) -> {State@1, Docs} = Acc, {Prop_name, Prop_schema} = Prop, Field_name = to_field_name(Prop_name), In_required = gleam@list:contains( erlang:element(2, Object_schema), Prop_name ), Optional = is_field_optional( Prop_schema, In_required, erlang:element(2, Config) ) orelse gleam@set:contains(Promoted_body_fields, Prop_name), case Optional of false -> {State@1, Docs}; true -> Fn_name = <<<<(justin:snake_case(Type_name))/binary, "_with_"/utf8>>/binary, Field_name/binary>>, Enum_hint = <>, {State@2, Inner_type} = schema_to_gleam_type( State@1, Prop_schema, true, All_schemas, Enum_hint, Request_only ), State@3 = import_qualified( State@2, <<"gleam/option"/utf8>>, <<"Some"/utf8>> ), Comment_part = case schema_description(Prop_schema) of {some, Comment} -> [Comment, {line, 1}]; none -> [] end, Setter_doc = glam@doc:concat( lists:append( Comment_part, [glam@doc:from_string( <<<<"pub fn "/utf8, Fn_name/binary>>/binary, "("/utf8>> ), begin _pipe = {line, 1}, glam@doc:nest(_pipe, Indent) end, begin _pipe@1 = glam@doc:from_string( <<<<<>/binary, Type_name/binary>>/binary, ","/utf8>> ), glam@doc:nest(_pipe@1, Indent) end, begin _pipe@2 = {line, 1}, glam@doc:nest(_pipe@2, Indent) end, begin _pipe@3 = glam@doc:concat( [glam@doc:from_string( <<<<<>/binary, Field_name/binary>>/binary, ": "/utf8>> ), Inner_type, glam@doc:from_string(<<","/utf8>>)] ), glam@doc:nest(_pipe@3, Indent) end, {line, 1}, glam@doc:from_string( <<<<") -> "/utf8, Type_name/binary>>/binary, " {"/utf8>> ), begin _pipe@4 = {line, 1}, glam@doc:nest(_pipe@4, Indent) end, begin _pipe@5 = glam@doc:from_string( <<<<<<<<<<<<<>/binary, Var_name/binary>>/binary, ", "/utf8>>/binary, Field_name/binary>>/binary, ": Some("/utf8>>/binary, Field_name/binary>>/binary, "))"/utf8>> ), glam@doc:nest(_pipe@5, Indent) end, {line, 1}, glam@doc:from_string(<<"}"/utf8>>)] ) ), {State@3, lists:append(Docs, [Setter_doc])} end end ). -file("src/gilly/internal/codegen.gleam", 1299). ?DOC(false). -spec operation_inline_body_request_docs( state(), binary(), list(gilly@openapi@operation:parameter()), list(gilly@openapi@operation:parameter()), gilly@openapi@schema:base_schema(), gilly@openapi@schema:object_schema(), list({binary(), gilly@openapi@schema:schema()}), config(), gleam@set:set(binary()) ) -> {state(), list(glam@doc:document()), list({binary(), gilly@openapi@schema:schema()})}. operation_inline_body_request_docs( State, Type_name, Path_params, Query_params, Body_base, Body_schema, All_schemas, Config, Promoted_body_fields ) -> Indent = erlang:element(3, Config), Request_only = true, All_params = lists:append(Path_params, Query_params), State@1 = {state, erlang:element(2, State), erlang:element(3, State), gleam@dict:insert(erlang:element(4, State), Type_name, request_only)}, Enums_before = erlang:element(3, State@1), {State@4, Param_fields} = gleam@list:fold( All_params, {State@1, []}, fun(Acc, Param) -> {State@2, Fields} = Acc, Field_name = to_field_name(erlang:element(2, Param)), {State@3, Type_doc} = param_to_type(State@2, Param, All_schemas), Field_doc = case erlang:element(5, Param) of true -> glam@doc:concat( [glam@doc:from_string(<>), Type_doc] ); false -> glam@doc:concat( [glam@doc:from_string( <> ), Type_doc, glam@doc:from_string(<<")"/utf8>>)] ) end, {State@3, lists:append(Fields, [Field_doc])} end ), {State@7, Body_fields} = gleam@list:fold( erlang:element(3, Body_schema), {State@4, []}, fun(Acc@1, Prop) -> {State@5, Fields@1} = Acc@1, {Prop_name, Prop_schema} = Prop, Field_name@1 = to_field_name(Prop_name), In_required = gleam@list:contains( erlang:element(2, Body_schema), Prop_name ), Optional = is_field_optional( Prop_schema, In_required, erlang:element(2, Config) ) orelse gleam@set:contains(Promoted_body_fields, Prop_name), Enum_hint = <>, {State@6, Field_type} = schema_to_gleam_type( State@5, Prop_schema, not Optional, All_schemas, Enum_hint, Request_only ), Field_line = glam@doc:concat( [glam@doc:from_string(<>), Field_type] ), Field_doc@1 = case schema_description(Prop_schema) of {some, Comment} -> glam@doc:concat([Comment, {line, 1}, Field_line]); none -> Field_line end, {State@6, [Field_doc@1 | Fields@1]} end ), Body_fields@1 = lists:reverse(Body_fields), All_fields = lists:append(Param_fields, Body_fields@1), Has_optional_params = gleam@list:any( All_params, fun(P) -> not erlang:element(5, P) end ), State@8 = case Has_optional_params of true -> import_qualified( State@7, <<"gleam/option"/utf8>>, <<"type Option"/utf8>> ); false -> State@7 end, Comment@1 = base_schema_comment(Body_base), Type_body = case All_fields of [] -> glam@doc:concat( [glam@doc:from_string( <<<<"pub opaque type "/utf8, Type_name/binary>>/binary, " {"/utf8>> ), begin _pipe = {line, 1}, glam@doc:nest(_pipe, Indent) end, begin _pipe@1 = glam@doc:from_string(Type_name), glam@doc:nest(_pipe@1, Indent) end, {line, 1}, glam@doc:from_string(<<"}"/utf8>>)] ); _ -> glam@doc:concat( [glam@doc:from_string( <<<<"pub opaque type "/utf8, Type_name/binary>>/binary, " {"/utf8>> ), begin _pipe@2 = {line, 1}, glam@doc:nest(_pipe@2, Indent) end, begin _pipe@5 = glam@doc:concat( [glam@doc:from_string( <> ), begin _pipe@3 = {line, 1}, glam@doc:nest(_pipe@3, Indent) end, begin _pipe@4 = glam@doc:join( All_fields, glam@doc:concat( [glam@doc:from_string(<<","/utf8>>), {line, 1}] ) ), glam@doc:nest(_pipe@4, Indent) end, glam@doc:concat( [glam@doc:from_string(<<","/utf8>>), {line, 1}] ), glam@doc:from_string(<<")"/utf8>>)] ), glam@doc:nest(_pipe@5, Indent) end, {line, 1}, glam@doc:from_string(<<"}"/utf8>>)] ) end, Type_doc@1 = case Comment@1 of {some, C} -> glam@doc:concat([C, {line, 1}, Type_body]); none -> Type_body end, {State@9, To_json_doc} = record_to_json_doc( State@8, Type_name, Body_schema, All_schemas, Config, Request_only, Promoted_body_fields ), Body_field_info = gleam@list:map( erlang:element(3, Body_schema), fun(Prop@1) -> {Prop_name@1, Prop_schema@1} = Prop@1, Field_name@2 = to_field_name(Prop_name@1), In_required@1 = gleam@list:contains( erlang:element(2, Body_schema), Prop_name@1 ), Optional@1 = is_field_optional( Prop_schema@1, In_required@1, erlang:element(2, Config) ) orelse gleam@set:contains(Promoted_body_fields, Prop_name@1), {Prop_name@1, Field_name@2, Prop_schema@1, Optional@1} end ), Has_optional_body = gleam@list:any( Body_field_info, fun(F) -> erlang:element(4, F) end ), State@10 = case Has_optional_params orelse Has_optional_body of true -> import_qualified(State@9, <<"gleam/option"/utf8>>, <<"None"/utf8>>); false -> State@9 end, {State@13, Param_required_args} = gleam@list:fold( gleam@list:filter(All_params, fun(P@1) -> erlang:element(5, P@1) end), {State@10, []}, fun(Acc@2, Param@1) -> {State@11, Args} = Acc@2, Field_name@3 = to_field_name(erlang:element(2, Param@1)), {State@12, Type_doc@2} = param_to_type( State@11, Param@1, All_schemas ), Arg = glam@doc:concat( [glam@doc:from_string( <<<<<>/binary, Field_name@3/binary>>/binary, ": "/utf8>> ), Type_doc@2] ), {State@12, lists:append(Args, [Arg])} end ), {State@16, Body_required_args} = gleam@list:fold( Body_field_info, {State@13, []}, fun(Acc@3, F@1) -> {State@14, Args@1} = Acc@3, {Prop_name@2, Field_name@4, Prop_schema@2, Optional@2} = F@1, case Optional@2 of true -> {State@14, Args@1}; false -> Enum_hint@1 = <>, {State@15, Field_type@1} = schema_to_gleam_type( State@14, Prop_schema@2, true, All_schemas, Enum_hint@1, Request_only ), Arg@1 = glam@doc:concat( [glam@doc:from_string( <<<<<>/binary, Field_name@4/binary>>/binary, ": "/utf8>> ), Field_type@1] ), {State@15, lists:append(Args@1, [Arg@1])} end end ), Required_args = lists:append(Param_required_args, Body_required_args), Param_inits = gleam@list:map( All_params, fun(P@2) -> Field_name@5 = to_field_name(erlang:element(2, P@2)), case erlang:element(5, P@2) of true -> <>; false -> <> end end ), Body_inits = gleam@list:map( Body_field_info, fun(F@2) -> {_, Field_name@6, _, Optional@3} = F@2, case Optional@3 of true -> <>; false -> <> end end ), Field_inits = lists:append(Param_inits, Body_inits), Constructor_body = glam@doc:from_string( <<<<<>/binary, (gleam@string:join(Field_inits, <<", "/utf8>>))/binary>>/binary, ")"/utf8>> ), Constructor_fn_name = <<"new_"/utf8, (justin:snake_case(Type_name))/binary>>, Constructor_doc = case Required_args of [] -> glam@doc:concat( [glam@doc:from_string( <<<<<<<<"pub fn "/utf8, Constructor_fn_name/binary>>/binary, "() -> "/utf8>>/binary, Type_name/binary>>/binary, " {"/utf8>> ), begin _pipe@6 = {line, 1}, glam@doc:nest(_pipe@6, Indent) end, begin _pipe@7 = Constructor_body, glam@doc:nest(_pipe@7, Indent) end, {line, 1}, glam@doc:from_string(<<"}"/utf8>>)] ); _ -> glam@doc:concat( [glam@doc:from_string( <<<<"pub fn "/utf8, Constructor_fn_name/binary>>/binary, "("/utf8>> ), begin _pipe@8 = {line, 1}, glam@doc:nest(_pipe@8, Indent) end, begin _pipe@9 = glam@doc:join( Required_args, glam@doc:concat( [glam@doc:from_string(<<","/utf8>>), {line, 1}] ) ), glam@doc:nest(_pipe@9, Indent) end, glam@doc:concat( [glam@doc:from_string(<<","/utf8>>), {line, 1}] ), glam@doc:from_string( <<<<") -> "/utf8, Type_name/binary>>/binary, " {"/utf8>> ), begin _pipe@10 = {line, 1}, glam@doc:nest(_pipe@10, Indent) end, begin _pipe@11 = Constructor_body, glam@doc:nest(_pipe@11, Indent) end, {line, 1}, glam@doc:from_string(<<"}"/utf8>>)] ) end, Var_name = justin:snake_case(Type_name), Optional_params = gleam@list:filter( All_params, fun(P@3) -> not erlang:element(5, P@3) end ), {State@20, Param_setters} = gleam@list:fold( Optional_params, {State@16, []}, fun(Acc@4, Param@2) -> {State@17, Setters} = Acc@4, Field_name@7 = to_field_name(erlang:element(2, Param@2)), Setter_fn_name = <<<<(justin:snake_case(Type_name))/binary, "_with_"/utf8>>/binary, Field_name@7/binary>>, {State@18, Inner_type} = param_to_type( State@17, Param@2, All_schemas ), State@19 = import_qualified( State@18, <<"gleam/option"/utf8>>, <<"Some"/utf8>> ), Comment_part = case erlang:element(4, Param@2) of {some, Desc} -> [description_to_comment(Desc), {line, 1}]; none -> [] end, Setter_doc = glam@doc:concat( lists:append( Comment_part, [glam@doc:from_string( <<<<"pub fn "/utf8, Setter_fn_name/binary>>/binary, "("/utf8>> ), begin _pipe@12 = {line, 1}, glam@doc:nest(_pipe@12, Indent) end, begin _pipe@13 = glam@doc:from_string( <<<<<>/binary, Type_name/binary>>/binary, ","/utf8>> ), glam@doc:nest(_pipe@13, Indent) end, begin _pipe@14 = {line, 1}, glam@doc:nest(_pipe@14, Indent) end, begin _pipe@15 = glam@doc:concat( [glam@doc:from_string( <<<<<>/binary, Field_name@7/binary>>/binary, ": "/utf8>> ), Inner_type, glam@doc:from_string(<<","/utf8>>)] ), glam@doc:nest(_pipe@15, Indent) end, {line, 1}, glam@doc:from_string( <<<<") -> "/utf8, Type_name/binary>>/binary, " {"/utf8>> ), begin _pipe@16 = {line, 1}, glam@doc:nest(_pipe@16, Indent) end, begin _pipe@17 = glam@doc:from_string( <<<<<<<<<<<<<>/binary, Var_name/binary>>/binary, ", "/utf8>>/binary, Field_name@7/binary>>/binary, ": Some("/utf8>>/binary, Field_name@7/binary>>/binary, "))"/utf8>> ), glam@doc:nest(_pipe@17, Indent) end, {line, 1}, glam@doc:from_string(<<"}"/utf8>>)] ) ), {State@19, lists:append(Setters, [Setter_doc])} end ), {State@21, Body_setters} = record_with_field_docs( State@20, Type_name, Body_schema, All_schemas, Config, Request_only, Promoted_body_fields ), All_setters = lists:append(Param_setters, Body_setters), New_enums = begin _pipe@18 = maps:to_list(erlang:element(3, State@21)), gleam@list:filter( _pipe@18, fun(Entry) -> not gleam@dict:has_key(Enums_before, erlang:element(1, Entry)) end ) end, Enum_docs = case New_enums of [] -> []; _ -> Temp_state = {state, erlang:element(2, State@21), maps:from_list(New_enums), erlang:element(4, State@21)}, [enums_doc(Temp_state, erlang:element(3, Config))] end, All_schemas@1 = [{Type_name, {object, Body_base, Body_schema}} | All_schemas], All_docs = lists:append( [Enum_docs, [Type_doc@1, To_json_doc, Constructor_doc], All_setters] ), {State@21, All_docs, All_schemas@1}. -file("src/gilly/internal/codegen.gleam", 661). ?DOC(false). -spec operation_doc( state(), binary(), binary(), gilly@openapi@operation:operation(), list({binary(), gilly@openapi@schema:schema()}), config() ) -> {state(), glam@doc:document()}. operation_doc(State, Path, Method, Op, All_schemas, Config) -> Indent = erlang:element(3, Config), Fn_name = operation_fn_name(Op, Path, Method), Request_type_name = <<(to_type_name(Fn_name))/binary, "Request"/utf8>>, Path_params = gleam@list:filter( erlang:element(6, Op), fun(P) -> erlang:element(3, P) =:= path end ), Query_params = begin _pipe = gleam@list:filter( erlang:element(6, Op), fun(P@1) -> erlang:element(3, P@1) =:= 'query' end ), gleam@list:map(_pipe, fun(P@2) -> case erlang:element(4, Config) of true -> {parameter, erlang:element(2, P@2), erlang:element(3, P@2), erlang:element(4, P@2), false, erlang:element(6, P@2)}; false -> P@2 end end) end, Promoted_set = gleam@set:from_list(erlang:element(5, Config)), Promoted_path_params = gleam@list:filter( Path_params, fun(P@3) -> gleam@set:contains(Promoted_set, erlang:element(2, P@3)) end ), Promoted_query_params = gleam@list:filter( Query_params, fun(P@4) -> gleam@set:contains(Promoted_set, erlang:element(2, P@4)) end ), Path_params_for_request = gleam@list:map( Path_params, fun(P@5) -> case gleam@set:contains(Promoted_set, erlang:element(2, P@5)) of true -> {parameter, erlang:element(2, P@5), erlang:element(3, P@5), erlang:element(4, P@5), false, erlang:element(6, P@5)}; false -> P@5 end end ), Query_params_for_request = gleam@list:map( Query_params, fun(P@6) -> case gleam@set:contains(Promoted_set, erlang:element(2, P@6)) andalso erlang:element(5, P@6) of true -> {parameter, erlang:element(2, P@6), erlang:element(3, P@6), erlang:element(4, P@6), false, erlang:element(6, P@6)}; false -> P@6 end end ), Has_params = not gleam@list:is_empty(Path_params) orelse not gleam@list:is_empty( Query_params ), {State@2, Body_info} = case erlang:element(7, Op) of {some, Rb} -> {State@1, Param} = request_body_param(State, Rb, All_schemas), case Param of {some, {_, _, {object, Base, Obj_schema}}} -> {State@1, {inline_body, Base, Obj_schema}}; {some, {_, Type_doc, Schema}} -> {State@1, {ref_body, Type_doc, Schema}}; none -> {State@1, no_body} end; none -> {State, no_body} end, Promoted_body_field_names = case Body_info of {inline_body, _, Obj_schema@1} -> gleam@list:filter( erlang:element(5, Config), fun(Name) -> gleam@list:any( erlang:element(3, Obj_schema@1), fun(Prop) -> erlang:element(1, Prop) =:= Name end ) end ); _ -> [] end, All_promoted_names = lists:append( gleam@list:map( lists:append(Promoted_path_params, Promoted_query_params), fun(P@7) -> erlang:element(2, P@7) end ), Promoted_body_field_names ), {State@3, Response_type} = response_type_from_op(State@2, Op, All_schemas), {State@8, Request_docs, All_args, Body_param, Params_prefix, All_schemas@3} = case {Body_info, Has_params} of {no_body, false} -> {State@3, [], [glam@doc:from_string(<<"client client: Client(err)"/utf8>>)], none, <<""/utf8>>, All_schemas}; {no_body, true} -> {State@4, Docs} = operation_request_docs( State@3, Request_type_name, Path_params_for_request, Query_params_for_request, none, All_schemas, Config ), {State@4, Docs, [glam@doc:from_string( <<"request params: "/utf8, Request_type_name/binary>> ), glam@doc:from_string(<<"client client: Client(err)"/utf8>>)], none, <<"params."/utf8>>, All_schemas}; {{ref_body, Type_doc@1, Body_schema}, false} -> {State@3, [], [glam@doc:concat( [glam@doc:from_string(<<"body: "/utf8>>), Type_doc@1] ), glam@doc:from_string(<<"client client: Client(err)"/utf8>>)], {some, {<<"body"/utf8>>, Type_doc@1, Body_schema}}, <<""/utf8>>, All_schemas}; {{ref_body, Type_doc@2, Body_schema@1}, true} -> {State@5, Docs@1} = operation_request_docs( State@3, Request_type_name, Path_params_for_request, Query_params_for_request, {some, {<<"body"/utf8>>, Type_doc@2}}, All_schemas, Config ), Ref_schema = Body_schema@1, {State@5, Docs@1, [glam@doc:from_string( <<"request params: "/utf8, Request_type_name/binary>> ), glam@doc:from_string(<<"client client: Client(err)"/utf8>>)], {some, {<<"params.body"/utf8>>, Type_doc@2, Ref_schema}}, <<"params."/utf8>>, All_schemas}; {{inline_body, Base@1, Obj_schema@2}, false} -> {State@6, Docs@2, All_schemas@1} = operation_inline_body_request_docs( State@3, Request_type_name, [], [], Base@1, Obj_schema@2, All_schemas, Config, Promoted_set ), Ref_schema@1 = {ref, <<"#/components/schemas/"/utf8, Request_type_name/binary>>}, {State@6, Docs@2, [glam@doc:from_string( <<"request params: "/utf8, Request_type_name/binary>> ), glam@doc:from_string(<<"client client: Client(err)"/utf8>>)], {some, {<<"params"/utf8>>, glam@doc:from_string(Request_type_name), Ref_schema@1}}, <<"params."/utf8>>, All_schemas@1}; {{inline_body, Base@2, Obj_schema@3}, true} -> {State@7, Docs@3, All_schemas@2} = operation_inline_body_request_docs( State@3, Request_type_name, Path_params_for_request, Query_params_for_request, Base@2, Obj_schema@3, All_schemas, Config, Promoted_set ), Ref_schema@2 = {ref, <<"#/components/schemas/"/utf8, Request_type_name/binary>>}, {State@7, Docs@3, [glam@doc:from_string( <<"request params: "/utf8, Request_type_name/binary>> ), glam@doc:from_string(<<"client client: Client(err)"/utf8>>)], {some, {<<"params"/utf8>>, glam@doc:from_string(Request_type_name), Ref_schema@2}}, <<"params."/utf8>>, All_schemas@2} end, Merge_lines = case All_promoted_names of [] -> []; _ -> gleam@list:map( All_promoted_names, fun(Name@1) -> Field_name = to_field_name(Name@1), glam@doc:from_string( <<<<<<<<<<<<<<"let "/utf8, Field_name/binary>>/binary, " = option.unwrap("/utf8>>/binary, Params_prefix/binary>>/binary, Field_name/binary>>/binary, ", client."/utf8>>/binary, Field_name/binary>>/binary, ")"/utf8>> ) end ) end, Body_update_lines = case Promoted_body_field_names of [] -> []; _ -> Field_updates = gleam@list:map( Promoted_body_field_names, fun(Name@2) -> Field_name@1 = to_field_name(Name@2), <<<<<>/binary, Field_name@1/binary>>/binary, ")"/utf8>> end ), [glam@doc:from_string( <<<<<<<<"let params = "/utf8, Request_type_name/binary>>/binary, "(..params, "/utf8>>/binary, (gleam@string:join(Field_updates, <<", "/utf8>>))/binary>>/binary, ")"/utf8>> )] end, State@9 = case All_promoted_names of [] -> State@8; _ -> _pipe@1 = State@8, import_module(_pipe@1, <<"gleam/option"/utf8>>) end, State@10 = case Promoted_body_field_names of [] -> State@9; _ -> _pipe@2 = State@9, import_qualified(_pipe@2, <<"gleam/option"/utf8>>, <<"Some"/utf8>>) end, Url_expr = build_url_expression( Path, Path_params, Params_prefix, Promoted_set ), State@11 = import_module(State@10, <<"gleam/dynamic/decode"/utf8>>), State@12 = import_module(State@11, <<"gleam/json"/utf8>>), Has_int_path_param = gleam@list:any( Path_params, fun(P@8) -> case erlang:element(6, P@8) of {some, {integer, _, _}} -> true; _ -> false end end ), Has_int_query_param = gleam@list:any( Query_params, fun(P@9) -> case erlang:element(6, P@9) of {some, {integer, _, _}} -> true; _ -> false end end ), State@13 = case Has_int_path_param orelse Has_int_query_param of true -> import_module(State@12, <<"gleam/int"/utf8>>); false -> State@12 end, Has_optional_query = gleam@list:any( Query_params, fun(P@10) -> not erlang:element(5, P@10) end ), State@14 = case Has_optional_query of true -> _pipe@3 = State@13, _pipe@4 = import_module(_pipe@3, <<"gleam/option"/utf8>>), import_module(_pipe@4, <<"gleam/list"/utf8>>); false -> State@13 end, Req_lines = build_request_lines( State@14, Method, Query_params, Body_param, All_schemas@3, Params_prefix, Promoted_set ), {State@15, Decode_line} = build_decode_line( State@14, Response_type, All_schemas@3 ), Body_lines = lists:append( [Merge_lines, Body_update_lines, [Url_expr], Req_lines, [Decode_line]] ), Return_type = case Response_type of {some, {Type_doc@3, _}} -> glam@doc:concat( [glam@doc:from_string(<<"Result("/utf8>>), Type_doc@3, glam@doc:from_string(<<", ApiError(err))"/utf8>>)] ); none -> glam@doc:from_string(<<"Result(Nil, ApiError(err))"/utf8>>) end, Comment = case erlang:element(3, Op) of {some, Summary} -> glam@doc:concat( [glam@doc:from_string(<<"/// "/utf8, Summary/binary>>), {line, 1}] ); none -> case erlang:element(4, Op) of {some, Desc} -> glam@doc:concat([description_to_comment(Desc), {line, 1}]); none -> {concat, []} end end, Fn_doc = glam@doc:concat( [Comment, glam@doc:from_string( <<<<"pub fn "/utf8, Fn_name/binary>>/binary, "("/utf8>> ), begin _pipe@5 = {line, 1}, glam@doc:nest(_pipe@5, Indent) end, begin _pipe@6 = glam@doc:join( All_args, glam@doc:concat( [glam@doc:from_string(<<","/utf8>>), {line, 1}] ) ), glam@doc:nest(_pipe@6, Indent) end, glam@doc:concat([glam@doc:from_string(<<","/utf8>>), {line, 1}]), glam@doc:from_string(<<") -> "/utf8>>), Return_type, glam@doc:from_string(<<" {"/utf8>>), begin _pipe@7 = {line, 1}, glam@doc:nest(_pipe@7, Indent) end, begin _pipe@8 = glam@doc:join(Body_lines, {line, 1}), glam@doc:nest(_pipe@8, Indent) end, {line, 1}, glam@doc:from_string(<<"}"/utf8>>)] ), Full_doc = case Request_docs of [] -> Fn_doc; _ -> glam@doc:concat( [glam@doc:join(Request_docs, glam@doc:lines(2)), glam@doc:lines(2), Fn_doc] ) end, {State@15, Full_doc}. -file("src/gilly/internal/codegen.gleam", 625). ?DOC(false). -spec path_item_to_docs( state(), binary(), gilly@openapi@openapi:path_item(), list({binary(), gilly@openapi@schema:schema()}), config() ) -> {state(), list(glam@doc:document())}. path_item_to_docs(State, Path, Path_item, All_schemas, Config) -> Methods = [{<<"Get"/utf8>>, erlang:element(2, Path_item)}, {<<"Post"/utf8>>, erlang:element(3, Path_item)}, {<<"Put"/utf8>>, erlang:element(4, Path_item)}, {<<"Delete"/utf8>>, erlang:element(5, Path_item)}, {<<"Patch"/utf8>>, erlang:element(6, Path_item)}], gleam@list:fold( Methods, {State, []}, fun(Acc, Method_entry) -> {State@1, Docs} = Acc, {Method, Op} = Method_entry, case Op of {some, Operation} -> {State@2, Op_doc} = operation_doc( State@1, Path, Method, Operation, All_schemas, Config ), {State@2, lists:append(Docs, [Op_doc])}; none -> {State@1, Docs} end end ). -file("src/gilly/internal/codegen.gleam", 323). ?DOC(false). -spec generate_operation_docs( state(), gilly@openapi@openapi:open_a_p_i(), list({binary(), gilly@openapi@schema:schema()}), config() ) -> {state(), list(glam@doc:document())}. generate_operation_docs(State, Spec, Schemas, Config) -> State@1 = import_module(State, <<"gleam/http/request"/utf8>>), State@2 = import_module(State@1, <<"gleam/http/response"/utf8>>), State@3 = import_module(State@2, <<"gleam/http"/utf8>>), State@4 = import_module(State@3, <<"gleam/result"/utf8>>), gleam@list:fold( erlang:element(5, Spec), {State@4, []}, fun(Acc, Path_entry) -> {State@5, Docs} = Acc, {Path, Path_item} = Path_entry, {State@6, Path_docs} = path_item_to_docs( State@5, Path, Path_item, Schemas, Config ), {State@6, lists:append(Docs, Path_docs)} end ). -file("src/gilly/internal/codegen.gleam", 263). ?DOC(false). -spec generate_operations(gilly@openapi@openapi:open_a_p_i(), config()) -> binary(). generate_operations(Spec, Config) -> Schemas = extract_schemas(Spec), State = default_state(), {State@1, Op_docs} = generate_operation_docs(State, Spec, Schemas, Config), Code = case Op_docs of [] -> {concat, []}; _ -> Base_url = default_base_url(Spec), Default_params = erlang:element(5, Config), Client_param_setters = client_default_param_setters( erlang:element(3, Config), Default_params ), glam@doc:concat( lists:append( [[imports_doc(State@1, erlang:element(3, Config)), glam@doc:lines(2), api_error_doc(erlang:element(3, Config)), glam@doc:lines(2), client_type_doc( erlang:element(3, Config), erlang:element(4, erlang:element(3, Spec)), Default_params ), glam@doc:lines(2), client_new_doc( erlang:element(3, Config), Base_url, Default_params ), glam@doc:lines(2), client_with_base_url_doc(erlang:element(3, Config))], gleam@list:map( Client_param_setters, fun(D) -> glam@doc:concat([glam@doc:lines(2), D]) end ), [glam@doc:lines(2), glam@doc:join(Op_docs, glam@doc:lines(2)), {line, 1}]] ) ) end, glam@doc:to_string(Code, 80). -file("src/gilly/internal/codegen.gleam", 2142). ?DOC(false). -spec object_type_doc( state(), binary(), gilly@openapi@schema:base_schema(), gilly@openapi@schema:object_schema(), list({binary(), gilly@openapi@schema:schema()}), config(), schema_usage() ) -> {state(), glam@doc:document()}. object_type_doc( State, Type_name, Base, Object_schema, All_schemas, Config, Usage ) -> Comment = base_schema_comment(Base), Is_opaque = case Usage of request_only -> true; response_only -> false; both -> false; unreferenced -> false end, Request_only = Usage =:= request_only, Needs_decoder = case Usage of request_only -> false; response_only -> true; both -> true; unreferenced -> true end, Needs_encoder = case Usage of response_only -> false; request_only -> true; both -> true; unreferenced -> true end, Needs_constructor = case Usage of response_only -> false; request_only -> true; both -> true; unreferenced -> true end, Needs_setters = case Usage of response_only -> false; request_only -> true; both -> true; unreferenced -> true end, {State@3, Fields@1} = gleam@list:fold( erlang:element(3, Object_schema), {State, []}, fun(Acc, Prop) -> {State@1, Fields} = Acc, {Prop_name, Prop_schema} = Prop, Field_name = to_field_name(Prop_name), In_required = gleam@list:contains( erlang:element(2, Object_schema), Prop_name ), Optional = is_field_optional( Prop_schema, In_required, erlang:element(2, Config) ), Enum_hint = <>, {State@2, Field_type} = schema_to_gleam_type( State@1, Prop_schema, not Optional, All_schemas, Enum_hint, Request_only ), Field_line = glam@doc:concat( [glam@doc:from_string(<>), Field_type] ), Field_doc = case schema_description(Prop_schema) of {some, Comment@1} -> glam@doc:concat([Comment@1, {line, 1}, Field_line]); none -> Field_line end, {State@2, [Field_doc | Fields]} end ), Fields@2 = lists:reverse(Fields@1), Indent = erlang:element(3, Config), Type_keyword = case Is_opaque of true -> <<"pub opaque type "/utf8>>; false -> <<"pub type "/utf8>> end, Body = case Fields@2 of [] -> glam@doc:concat( [glam@doc:from_string( <<<>/binary, " {"/utf8>> ), begin _pipe = {line, 1}, glam@doc:nest(_pipe, Indent) end, begin _pipe@1 = glam@doc:from_string(Type_name), glam@doc:nest(_pipe@1, Indent) end, {line, 1}, glam@doc:from_string(<<"}"/utf8>>)] ); _ -> glam@doc:concat( [glam@doc:from_string( <<<>/binary, " {"/utf8>> ), begin _pipe@2 = {line, 1}, glam@doc:nest(_pipe@2, Indent) end, begin _pipe@5 = glam@doc:concat( [glam@doc:from_string( <> ), begin _pipe@3 = {line, 1}, glam@doc:nest(_pipe@3, Indent) end, begin _pipe@4 = glam@doc:join( Fields@2, glam@doc:concat( [glam@doc:from_string(<<","/utf8>>), {line, 1}] ) ), glam@doc:nest(_pipe@4, Indent) end, glam@doc:concat( [glam@doc:from_string(<<","/utf8>>), {line, 1}] ), glam@doc:from_string(<<")"/utf8>>)] ), glam@doc:nest(_pipe@5, Indent) end, {line, 1}, glam@doc:from_string(<<"}"/utf8>>)] ) end, Result = case Comment of {some, C} -> glam@doc:concat([C, {line, 1}, Body]); none -> Body end, {State@5, Result@1} = case Needs_decoder of true -> {State@4, Decoder} = record_decoder_doc( State@3, Type_name, Object_schema, All_schemas, Config ), {State@4, glam@doc:concat([Result, glam@doc:lines(2), Decoder])}; false -> {State@3, Result} end, {State@7, Result@2} = case Needs_encoder of true -> {State@6, Encoder} = record_to_json_doc( State@5, Type_name, Object_schema, All_schemas, Config, Request_only, gleam@set:new() ), {State@6, glam@doc:concat([Result@1, glam@doc:lines(2), Encoder])}; false -> {State@5, Result@1} end, {State@9, Result@3} = case Needs_constructor of true -> {State@8, Constructor} = record_new_doc( State@7, Type_name, Object_schema, All_schemas, Config, Request_only ), {State@8, glam@doc:concat([Result@2, glam@doc:lines(2), Constructor])}; false -> {State@7, Result@2} end, {State@11, Result@4} = case Needs_setters of true -> {State@10, Setters} = record_with_field_docs( State@9, Type_name, Object_schema, All_schemas, Config, Request_only, gleam@set:new() ), Setter_docs = case Setters of [] -> {concat, []}; _ -> glam@doc:concat( [glam@doc:lines(2), glam@doc:join(Setters, glam@doc:lines(2))] ) end, {State@10, glam@doc:concat([Result@3, Setter_docs])}; false -> {State@9, Result@3} end, {State@11, Result@4}. -file("src/gilly/internal/codegen.gleam", 2104). ?DOC(false). -spec schema_to_type_doc( state(), binary(), gilly@openapi@schema:schema(), list({binary(), gilly@openapi@schema:schema()}), config() ) -> {state(), glam@doc:document()}. schema_to_type_doc(State, Name, Schema, All_schemas, Config) -> Type_name = to_type_name(Name), Usage = get_schema_usage(State, Name), case Schema of {object, Base, Object_schema} -> case is_map_object(Object_schema) of true -> map_type_doc( State, Type_name, Object_schema, All_schemas, Config ); false -> object_type_doc( State, Type_name, Base, Object_schema, All_schemas, Config, Usage ) end; {string, _, {string_schema, _, _, {some, Variants}, _}} -> State@1 = register_enum(State, Type_name, Variants), {State@1, {concat, []}}; _ -> simple_type_doc(State, Type_name, Schema, All_schemas, Config) end. -file("src/gilly/internal/codegen.gleam", 307). ?DOC(false). -spec generate_schema_docs( state(), list({binary(), gilly@openapi@schema:schema()}), config() ) -> {state(), list(glam@doc:document())}. generate_schema_docs(State, Schemas, Config) -> {State@3, Type_docs} = gleam@list:fold( Schemas, {State, []}, fun(Acc, Entry) -> {State@1, Docs} = Acc, {Name, Schema} = Entry, {State@2, Type_doc} = schema_to_type_doc( State@1, Name, Schema, Schemas, Config ), {State@2, [Type_doc | Docs]} end ), {State@3, lists:reverse(Type_docs)}. -file("src/gilly/internal/codegen.gleam", 123). ?DOC(false). -spec generate(gilly@openapi@openapi:open_a_p_i(), config()) -> binary(). generate(Spec, Config) -> Schemas = extract_schemas(Spec), State = default_state(), Schema_usages = collect_schema_usages(Spec), State@1 = {state, erlang:element(2, State), erlang:element(3, State), Schema_usages}, {State@2, Type_docs} = generate_schema_docs(State@1, Schemas, Config), Types_code = begin _pipe = glam@doc:join(Type_docs, glam@doc:lines(2)), glam@doc:append(_pipe, {line, 1}) end, State@3 = case gleam@dict:is_empty(erlang:element(3, State@2)) of true -> State@2; false -> _pipe@1 = State@2, _pipe@2 = import_module(_pipe@1, <<"gleam/dynamic/decode"/utf8>>), import_module(_pipe@2, <<"gleam/json"/utf8>>) end, Enums_code = case gleam@dict:is_empty(erlang:element(3, State@3)) of true -> {concat, []}; false -> glam@doc:concat( [glam@doc:lines(2), separator_comment(<<"Enums"/utf8>>), glam@doc:lines(2), enums_doc(State@3, erlang:element(3, Config))] ) end, {State@4, Op_docs} = generate_operation_docs(State@3, Spec, Schemas, Config), Ops_code = case Op_docs of [] -> {concat, []}; _ -> Base_url = default_base_url(Spec), Default_params = erlang:element(5, Config), Client_param_setters = client_default_param_setters( erlang:element(3, Config), Default_params ), glam@doc:concat( lists:append( [[glam@doc:lines(2), separator_comment(<<"Operations"/utf8>>), glam@doc:lines(2), api_error_doc(erlang:element(3, Config)), glam@doc:lines(2), client_type_doc( erlang:element(3, Config), erlang:element(4, erlang:element(3, Spec)), Default_params ), glam@doc:lines(2), client_new_doc( erlang:element(3, Config), Base_url, Default_params ), glam@doc:lines(2), client_with_base_url_doc(erlang:element(3, Config))], gleam@list:map( Client_param_setters, fun(D) -> glam@doc:concat([glam@doc:lines(2), D]) end ), [glam@doc:lines(2), glam@doc:join(Op_docs, glam@doc:lines(2)), {line, 1}]] ) ) end, Code = case gleam@dict:is_empty(erlang:element(2, State@4)) of true -> glam@doc:concat([Types_code, Enums_code, Ops_code]); false -> glam@doc:concat( [imports_doc(State@4, erlang:element(3, Config)), glam@doc:lines(2), Types_code, Enums_code, Ops_code] ) end, glam@doc:to_string(Code, 80). -file("src/gilly/internal/codegen.gleam", 215). ?DOC(false). -spec generate_schemas(gilly@openapi@openapi:open_a_p_i(), config()) -> binary(). generate_schemas(Spec, Config) -> Schemas = extract_schemas(Spec), State = default_state(), {State@1, Type_docs} = generate_schema_docs(State, Schemas, Config), Types_code = begin _pipe = glam@doc:join(Type_docs, glam@doc:lines(2)), glam@doc:append(_pipe, {line, 1}) end, State@2 = case gleam@dict:is_empty(erlang:element(3, State@1)) of true -> State@1; false -> _pipe@1 = State@1, _pipe@2 = import_module(_pipe@1, <<"gleam/dynamic/decode"/utf8>>), import_module(_pipe@2, <<"gleam/json"/utf8>>) end, Enums_code = case gleam@dict:is_empty(erlang:element(3, State@2)) of true -> {concat, []}; false -> glam@doc:concat( [glam@doc:lines(2), separator_comment(<<"Enums"/utf8>>), glam@doc:lines(2), enums_doc(State@2, erlang:element(3, Config))] ) end, Code = case gleam@dict:is_empty(erlang:element(2, State@2)) of true -> glam@doc:concat([Types_code, Enums_code]); false -> glam@doc:concat( [imports_doc(State@2, erlang:element(3, Config)), glam@doc:lines(2), Types_code, Enums_code] ) end, glam@doc:to_string(Code, 80).