Packages
oaspec
0.42.0
0.68.0
0.67.0
0.66.0
0.65.0
0.64.0
0.63.0
0.62.0
0.61.0
0.60.0
0.59.0
0.58.1
0.58.0
0.57.0
0.56.0
0.55.0
0.54.0
0.53.0
0.52.0
0.51.0
0.50.0
0.49.0
0.48.0
0.47.0
0.46.0
0.45.0
0.44.0
0.43.0
0.42.0
0.41.0
0.40.0
0.39.0
0.38.0
0.37.0
0.36.0
0.35.0
0.34.0
0.33.0
0.32.0
0.31.0
0.30.0
0.29.0
0.28.0
0.27.0
0.26.0
0.25.0
0.24.0
0.23.0
0.22.0
0.21.0
0.20.0
0.19.0
0.18.0
0.17.0
0.16.0
0.15.0
0.14.0
0.13.0
0.12.0
0.11.0
0.10.0
0.9.0
0.8.0
0.7.0
0.6.3
0.6.1
0.6.0
0.5.0
0.4.0
0.3.0
0.1.3
Generate Gleam code from OpenAPI 3.x specifications
Current section
Files
Jump to
Current section
Files
src/oaspec@internal@openapi@diagnostic_format.erl
-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;
_ ->
<<<<<<Base/binary, " ("/utf8>>/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(
<<<<Kind/binary, "."/utf8>>/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.