-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", 61). ?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", 72). ?DOC(false). -spec schema_ref_to_string_expr( oaspec@internal@openapi@schema:schema_ref(), binary(), oaspec@internal@codegen@context:context() ) -> binary(). schema_ref_to_string_expr(Ref, Value, Ctx) -> case Ref of {inline, Schema} -> to_string_expr(Schema, Value); {reference, _, Name} -> case oaspec@internal@codegen@context:resolve_schema_ref(Ref, Ctx) 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", 203). ?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", 103). ?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 reached decoder_expr after hoist. "/utf8>>/binary, "This is a hoist contract bug — inline composites must be "/utf8>>/binary, "moved to components/schemas before codegen. Please open an "/utf8>>/binary, "issue at https://github.com/nao1215/oaspec/issues with the "/utf8>>/binary, "spec that triggered this."/utf8>>), file => <>, module => <<"oaspec/internal/codegen/schema_dispatch"/utf8>>, function => <<"decoder_expr"/utf8>>, line => 121}) end. -file("src/oaspec/internal/codegen/schema_dispatch.gleam", 134). ?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 reached json_encoder_expr after hoist. "/utf8>>/binary, "This is a hoist contract bug; please file an issue with the spec."/utf8>>), file => <>, module => <<"oaspec/internal/codegen/schema_dispatch"/utf8>>, function => <<"json_encoder_expr"/utf8>>, line => 145}) end. -file("src/oaspec/internal/codegen/schema_dispatch.gleam", 155). ?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 reached json_encoder_fn after hoist. "/utf8>>/binary, "This is a hoist contract bug; please file an issue with the spec."/utf8>>), file => <>, module => <<"oaspec/internal/codegen/schema_dispatch"/utf8>>, function => <<"json_encoder_fn"/utf8>>, line => 165}) end. -file("src/oaspec/internal/codegen/schema_dispatch.gleam", 175). ?DOC(false). -spec to_string_fn( oaspec@internal@openapi@schema:schema_ref(), oaspec@internal@codegen@context:context() ) -> binary(). to_string_fn(Ref, Ctx) -> 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@codegen@context:resolve_schema_ref(Ref, Ctx) 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}, Ctx); {error, _} -> <<"fn(x) { x }"/utf8>> end; {inline, Schema} -> erlang:error(#{gleam_error => panic, message => (<<<<<<"oaspec: inline "/utf8, (schema_kind(Schema))/binary>>/binary, " schema reached to_string_fn after hoist. "/utf8>>/binary, "This is a hoist contract bug; please file an issue with the spec."/utf8>>), file => <>, module => <<"oaspec/internal/codegen/schema_dispatch"/utf8>>, function => <<"to_string_fn"/utf8>>, line => 193}) end. -file("src/oaspec/internal/codegen/schema_dispatch.gleam", 44). ?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", 20). ?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", 35). ?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", 52). ?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", 218). ?DOC(false). -spec resolve_param_type( gleam@option:option(oaspec@internal@openapi@schema:schema_ref()), oaspec@internal@codegen@context:context() ) -> binary(). resolve_param_type(Schema_ref, Ctx) -> case Schema_ref of {some, {inline, Schema}} -> schema_base_type(Schema); {some, {reference, _, Name} = Ref} -> case oaspec@internal@codegen@context:resolve_schema_ref(Ref, Ctx) 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.