-module(oaspec@internal@codegen@schema_dispatch). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/oaspec/internal/codegen/schema_dispatch.gleam"). -export([to_string_expr/2, schema_ref_to_string_expr/3, decoder_expr/1, json_encoder_expr/2, json_encoder_fn/1, to_string_fn/2, schema_base_type/1, schema_type/1, schema_ref_qualified_type/1, resolve_param_type/2]). -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). -file("src/oaspec/internal/codegen/schema_dispatch.gleam", 62). ?DOC(false). -spec to_string_expr(oaspec@internal@openapi@schema:schema_object(), binary()) -> binary(). to_string_expr(Schema, Value) -> case Schema of {integer_schema, _, _, _, _, _, _, _} -> <<<<"int.to_string("/utf8, Value/binary>>/binary, ")"/utf8>>; {number_schema, _, _, _, _, _, _, _} -> <<<<"float.to_string("/utf8, Value/binary>>/binary, ")"/utf8>>; {boolean_schema, _} -> <<<<"bool.to_string("/utf8, Value/binary>>/binary, ")"/utf8>>; {string_schema, _, _, _, _, _, _} -> Value; _ -> Value end. -file("src/oaspec/internal/codegen/schema_dispatch.gleam", 73). ?DOC(false). -spec schema_ref_to_string_expr( oaspec@internal@openapi@schema:schema_ref(), binary(), oaspec@internal@openapi@spec:open_api_spec(oaspec@internal@openapi@spec:resolved()) ) -> binary(). schema_ref_to_string_expr(Ref, Value, Spec) -> case Ref of {inline, Schema} -> to_string_expr(Schema, Value); {reference, _, Name} -> case oaspec@internal@openapi@resolver:resolve_schema_ref(Ref, Spec) of {ok, {string_schema, _, _, Enum_values, _, _, _}} when Enum_values =/= [] -> <<<<<<<<"encode.encode_"/utf8, (oaspec@internal@util@naming:to_snake_case( Name ))/binary>>/binary, "_to_string("/utf8>>/binary, Value/binary>>/binary, ")"/utf8>>; {ok, Resolved} -> to_string_expr(Resolved, Value); {error, _} -> Value end end. -file("src/oaspec/internal/codegen/schema_dispatch.gleam", 185). ?DOC(false). -spec schema_kind(oaspec@internal@openapi@schema:schema_object()) -> binary(). schema_kind(Schema) -> case Schema of {string_schema, _, _, _, _, _, _} -> <<"string"/utf8>>; {integer_schema, _, _, _, _, _, _, _} -> <<"integer"/utf8>>; {number_schema, _, _, _, _, _, _, _} -> <<"number"/utf8>>; {boolean_schema, _} -> <<"boolean"/utf8>>; {array_schema, _, _, _, _, _} -> <<"array"/utf8>>; {object_schema, _, _, _, _, _, _} -> <<"object"/utf8>>; {all_of_schema, _, _} -> <<"allOf"/utf8>>; {one_of_schema, _, _, _} -> <<"oneOf"/utf8>>; {any_of_schema, _, _, _} -> <<"anyOf"/utf8>> end. -file("src/oaspec/internal/codegen/schema_dispatch.gleam", 104). ?DOC(false). -spec decoder_expr(oaspec@internal@openapi@schema:schema_ref()) -> binary(). decoder_expr(Ref) -> case Ref of {inline, {string_schema, _, _, _, _, _, _}} -> <<"decode.string"/utf8>>; {inline, {integer_schema, _, _, _, _, _, _, _}} -> <<"decode.int"/utf8>>; {inline, {number_schema, _, _, _, _, _, _, _}} -> <<"decode.float"/utf8>>; {inline, {boolean_schema, _}} -> <<"decode.bool"/utf8>>; {reference, _, Name} -> <<(oaspec@internal@util@naming:to_snake_case(Name))/binary, "_decoder()"/utf8>>; {inline, Schema} -> erlang:error(#{gleam_error => panic, message => (<<<<<<"oaspec: inline "/utf8, (schema_kind(Schema))/binary>>/binary, " schema is not supported in decoder_expr. "/utf8>>/binary, "Move the schema to components/schemas and use a $ref instead."/utf8>>), file => <>, module => <<"oaspec/internal/codegen/schema_dispatch"/utf8>>, function => <<"decoder_expr"/utf8>>, line => 112}) end. -file("src/oaspec/internal/codegen/schema_dispatch.gleam", 122). ?DOC(false). -spec json_encoder_expr(oaspec@internal@openapi@schema:schema_ref(), binary()) -> binary(). json_encoder_expr(Ref, Value) -> case Ref of {inline, {string_schema, _, _, _, _, _, _}} -> <<<<"json.string("/utf8, Value/binary>>/binary, ")"/utf8>>; {inline, {integer_schema, _, _, _, _, _, _, _}} -> <<<<"json.int("/utf8, Value/binary>>/binary, ")"/utf8>>; {inline, {number_schema, _, _, _, _, _, _, _}} -> <<<<"json.float("/utf8, Value/binary>>/binary, ")"/utf8>>; {inline, {boolean_schema, _}} -> <<<<"json.bool("/utf8, Value/binary>>/binary, ")"/utf8>>; {reference, _, Name} -> <<<<<<<<"encode_"/utf8, (oaspec@internal@util@naming:to_snake_case(Name))/binary>>/binary, "_json("/utf8>>/binary, Value/binary>>/binary, ")"/utf8>>; {inline, Schema} -> erlang:error(#{gleam_error => panic, message => (<<<<<<"oaspec: inline "/utf8, (schema_kind(Schema))/binary>>/binary, " schema is not supported in json_encoder_expr. "/utf8>>/binary, "Move the schema to components/schemas and use a $ref instead."/utf8>>), file => <>, module => <<"oaspec/internal/codegen/schema_dispatch"/utf8>>, function => <<"json_encoder_expr"/utf8>>, line => 131}) end. -file("src/oaspec/internal/codegen/schema_dispatch.gleam", 141). ?DOC(false). -spec json_encoder_fn(oaspec@internal@openapi@schema:schema_ref()) -> binary(). json_encoder_fn(Ref) -> case Ref of {inline, {string_schema, _, _, _, _, _, _}} -> <<"json.string"/utf8>>; {inline, {integer_schema, _, _, _, _, _, _, _}} -> <<"json.int"/utf8>>; {inline, {number_schema, _, _, _, _, _, _, _}} -> <<"json.float"/utf8>>; {inline, {boolean_schema, _}} -> <<"json.bool"/utf8>>; {reference, _, Name} -> <<<<"encode_"/utf8, (oaspec@internal@util@naming:to_snake_case(Name))/binary>>/binary, "_json"/utf8>>; {inline, Schema} -> erlang:error(#{gleam_error => panic, message => (<<<<<<"oaspec: inline "/utf8, (schema_kind(Schema))/binary>>/binary, " schema is not supported in json_encoder_fn. "/utf8>>/binary, "Move the schema to components/schemas and use a $ref instead."/utf8>>), file => <>, module => <<"oaspec/internal/codegen/schema_dispatch"/utf8>>, function => <<"json_encoder_fn"/utf8>>, line => 149}) end. -file("src/oaspec/internal/codegen/schema_dispatch.gleam", 159). ?DOC(false). -spec to_string_fn( oaspec@internal@openapi@schema:schema_ref(), oaspec@internal@openapi@spec:open_api_spec(oaspec@internal@openapi@spec:resolved()) ) -> binary(). to_string_fn(Ref, Spec) -> case Ref of {inline, {string_schema, _, _, _, _, _, _}} -> <<"fn(x) { x }"/utf8>>; {inline, {integer_schema, _, _, _, _, _, _, _}} -> <<"int.to_string"/utf8>>; {inline, {number_schema, _, _, _, _, _, _, _}} -> <<"float.to_string"/utf8>>; {inline, {boolean_schema, _}} -> <<"bool.to_string"/utf8>>; {reference, _, Name} -> case oaspec@internal@openapi@resolver:resolve_schema_ref(Ref, Spec) of {ok, {string_schema, _, _, Enum_values, _, _, _}} when Enum_values =/= [] -> <<<<"encode.encode_"/utf8, (oaspec@internal@util@naming:to_snake_case(Name))/binary>>/binary, "_to_string"/utf8>>; {ok, Resolved} -> to_string_fn({inline, Resolved}, Spec); {error, _} -> <<"fn(x) { x }"/utf8>> end; {inline, Schema} -> erlang:error(#{gleam_error => panic, message => (<<<<<<"oaspec: inline "/utf8, (schema_kind(Schema))/binary>>/binary, " schema is not supported in to_string_fn. "/utf8>>/binary, "Move the schema to components/schemas and use a $ref instead."/utf8>>), file => <>, module => <<"oaspec/internal/codegen/schema_dispatch"/utf8>>, function => <<"to_string_fn"/utf8>>, line => 175}) end. -file("src/oaspec/internal/codegen/schema_dispatch.gleam", 45). ?DOC(false). -spec schema_ref_type(oaspec@internal@openapi@schema:schema_ref()) -> binary(). schema_ref_type(Ref) -> case Ref of {inline, Schema} -> schema_base_type(Schema); {reference, _, Name} -> oaspec@internal@util@naming:schema_to_type_name(Name) end. -file("src/oaspec/internal/codegen/schema_dispatch.gleam", 21). ?DOC(false). -spec schema_base_type(oaspec@internal@openapi@schema:schema_object()) -> binary(). schema_base_type(Schema) -> case Schema of {string_schema, _, _, _, _, _, _} -> <<"String"/utf8>>; {integer_schema, _, _, _, _, _, _, _} -> <<"Int"/utf8>>; {number_schema, _, _, _, _, _, _, _} -> <<"Float"/utf8>>; {boolean_schema, _} -> <<"Bool"/utf8>>; {array_schema, _, Items, _, _, _} -> <<<<"List("/utf8, (schema_ref_type(Items))/binary>>/binary, ")"/utf8>>; {object_schema, _, _, _, _, _, _} -> <<"String"/utf8>>; {all_of_schema, _, _} -> <<"String"/utf8>>; {one_of_schema, _, _, _} -> <<"String"/utf8>>; {any_of_schema, _, _, _} -> <<"String"/utf8>> end. -file("src/oaspec/internal/codegen/schema_dispatch.gleam", 36). ?DOC(false). -spec schema_type(oaspec@internal@openapi@schema:schema_object()) -> binary(). schema_type(Schema) -> Base = schema_base_type(Schema), case oaspec@internal@openapi@schema:is_nullable(Schema) of true -> <<<<"Option("/utf8, Base/binary>>/binary, ")"/utf8>>; false -> Base end. -file("src/oaspec/internal/codegen/schema_dispatch.gleam", 53). ?DOC(false). -spec schema_ref_qualified_type(oaspec@internal@openapi@schema:schema_ref()) -> binary(). schema_ref_qualified_type(Ref) -> case Ref of {inline, Schema} -> schema_base_type(Schema); {reference, _, Name} -> <<"types."/utf8, (oaspec@internal@util@naming:schema_to_type_name(Name))/binary>> end. -file("src/oaspec/internal/codegen/schema_dispatch.gleam", 200). ?DOC(false). -spec resolve_param_type( gleam@option:option(oaspec@internal@openapi@schema:schema_ref()), oaspec@internal@openapi@spec:open_api_spec(oaspec@internal@openapi@spec:resolved()) ) -> binary(). resolve_param_type(Schema_ref, Spec) -> case Schema_ref of {some, {inline, Schema}} -> schema_base_type(Schema); {some, {reference, _, Name} = Ref} -> case oaspec@internal@openapi@resolver:resolve_schema_ref(Ref, Spec) of {ok, {array_schema, _, Items, _, _, _}} -> <<<<"List("/utf8, (schema_ref_type(Items))/binary>>/binary, ")"/utf8>>; _ -> <<"types."/utf8, (oaspec@internal@util@naming:schema_to_type_name(Name))/binary>> end; none -> <<"String"/utf8>> end.