Current section

Files

Jump to
oaspec src oaspec@util@http.erl
Raw

src/oaspec@util@http.erl

-module(oaspec@util@http).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/oaspec/util/http.gleam").
-export([status_code_suffix/1, status_code_to_int_pattern/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.
-file("src/oaspec/util/http.gleam", 4).
?DOC(
" Shared HTTP status code utilities for code generation.\n"
" Get a human-readable suffix for a given HTTP status code.\n"
" Used to build anonymous type names like \"ListPetsResponseOk\".\n"
).
-spec status_code_suffix(binary()) -> binary().
status_code_suffix(Code) ->
case Code of
<<"200"/utf8>> ->
<<"Ok"/utf8>>;
<<"201"/utf8>> ->
<<"Created"/utf8>>;
<<"204"/utf8>> ->
<<"NoContent"/utf8>>;
<<"400"/utf8>> ->
<<"BadRequest"/utf8>>;
<<"401"/utf8>> ->
<<"Unauthorized"/utf8>>;
<<"403"/utf8>> ->
<<"Forbidden"/utf8>>;
<<"404"/utf8>> ->
<<"NotFound"/utf8>>;
<<"409"/utf8>> ->
<<"Conflict"/utf8>>;
<<"422"/utf8>> ->
<<"UnprocessableEntity"/utf8>>;
<<"500"/utf8>> ->
<<"InternalServerError"/utf8>>;
<<"default"/utf8>> ->
<<"Default"/utf8>>;
Other ->
<<"Status"/utf8, Other/binary>>
end.
-file("src/oaspec/util/http.gleam", 23).
?DOC(
" Convert a status code string to an integer pattern for case matching.\n"
" The \"default\" status maps to \"_\" (catch-all).\n"
).
-spec status_code_to_int_pattern(binary()) -> binary().
status_code_to_int_pattern(Code) ->
case Code of
<<"default"/utf8>> ->
<<"_"/utf8>>;
_ ->
Code
end.