-module(oaspec@internal@openapi@diagnostic_format). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/oaspec/internal/openapi/diagnostic_format.gleam"). -export([pointer_to_human/1]). -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/openapi/diagnostic_format.gleam", 56). ?DOC(false). -spec unescape_segment(binary()) -> binary(). unescape_segment(S) -> _pipe = S, _pipe@1 = gleam@string:replace(_pipe, <<"~1"/utf8>>, <<"/"/utf8>>), gleam@string:replace(_pipe@1, <<"~0"/utf8>>, <<"~"/utf8>>). -file("src/oaspec/internal/openapi/diagnostic_format.gleam", 39). ?DOC(false). -spec split_pointer(binary()) -> list(binary()). split_pointer(Pointer) -> _pipe = Pointer, _pipe@1 = gleam@string:replace(_pipe, <<"#/"/utf8>>, <<""/utf8>>), _pipe@2 = gleam@string:replace(_pipe@1, <<"/"/utf8>>, <<"."/utf8>>), _pipe@3 = gleam@string:split(_pipe@2, <<"."/utf8>>), _pipe@4 = gleam@list:filter(_pipe@3, fun(S) -> S /= <<""/utf8>> end), gleam@list:map(_pipe@4, fun unescape_segment/1). -file("src/oaspec/internal/openapi/diagnostic_format.gleam", 94). ?DOC(false). -spec with_tail(binary(), list(binary())) -> binary(). with_tail(Base, Rest) -> case Rest of [] -> Base; _ -> <<<<<>/binary, (gleam@string:join(Rest, <<"."/utf8>>))/binary>>/binary, ")"/utf8>> end. -file("src/oaspec/internal/openapi/diagnostic_format.gleam", 101). ?DOC(false). -spec default_format(list(binary()), binary()) -> binary(). default_format(Segments, Original) -> case Segments of [] -> Original; _ -> gleam@string:join(Segments, <<"."/utf8>>) end. -file("src/oaspec/internal/openapi/diagnostic_format.gleam", 62). ?DOC(false). -spec format_segments(list(binary()), binary()) -> binary(). format_segments(Segments, Original) -> case Segments of [<<"paths"/utf8>>, Path, Method, <<"parameters"/utf8>>, Idx | Rest] -> with_tail( <<<<<<<<(string:uppercase(Method))/binary, " "/utf8>>/binary, Path/binary>>/binary, ", parameter #"/utf8>>/binary, Idx/binary>>, Rest ); [<<"paths"/utf8>>, Path@1, Method@1, <<"requestBody"/utf8>> | Rest@1] -> with_tail( <<<<<<(string:uppercase(Method@1))/binary, " "/utf8>>/binary, Path@1/binary>>/binary, ", requestBody"/utf8>>, Rest@1 ); [<<"paths"/utf8>>, Path@2, Method@2, <<"responses"/utf8>>, Status | Rest@2] -> with_tail( <<<<<<<<(string:uppercase(Method@2))/binary, " "/utf8>>/binary, Path@2/binary>>/binary, ", response "/utf8>>/binary, Status/binary>>, Rest@2 ); [<<"paths"/utf8>>, Path@3, Method@3 | Rest@3] -> with_tail( <<<<(string:uppercase(Method@3))/binary, " "/utf8>>/binary, Path@3/binary>>, Rest@3 ); [<<"components"/utf8>>, <<"schemas"/utf8>>, Name | Rest@4] -> with_tail(<<"schemas."/utf8, Name/binary>>, Rest@4); [<<"components"/utf8>>, <<"parameters"/utf8>>, Name@1 | Rest@5] -> with_tail(<<"parameters."/utf8, Name@1/binary>>, Rest@5); [<<"components"/utf8>>, <<"responses"/utf8>>, Name@2 | Rest@6] -> with_tail(<<"responses."/utf8, Name@2/binary>>, Rest@6); [<<"components"/utf8>>, <<"requestBodies"/utf8>>, Name@3 | Rest@7] -> with_tail(<<"requestBodies."/utf8, Name@3/binary>>, Rest@7); [<<"components"/utf8>>, Kind, Name@4 | Rest@8] -> with_tail( <<<>/binary, Name@4/binary>>, Rest@8 ); _ -> default_format(Segments, Original) end. -file("src/oaspec/internal/openapi/diagnostic_format.gleam", 32). ?DOC(false). -spec pointer_to_human(binary()) -> binary(). pointer_to_human(Pointer) -> case Pointer of <<""/utf8>> -> <<"root"/utf8>>; _ -> format_segments(split_pointer(Pointer), Pointer) end.