Packages
oaspec
0.18.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@openapi@spec.erl
-module(oaspec@openapi@spec).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/oaspec/openapi/spec.gleam").
-export([unwrap_ref/1, parameter_schema/1, method_to_string/1, method_to_lower/1]).
-export_type([unresolved/0, resolved/0, ref_or/1, open_api_spec/1, info/0, contact/0, license/0, server/0, server_variable/0, external_doc/0, tag/0, components/1, security_scheme_in/0, parameter_style/0, security_scheme/0, o_auth2_flow/0, security_scheme_ref/0, security_requirement/0, path_item/1, operation/1, callback/1, parameter_in/0, parameter_payload/0, parameter/1, request_body/1, media_type/0, encoding/0, header/0, link/0, response/1, http_method/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
-type unresolved() :: unresolved.
-type resolved() :: resolved.
-type ref_or(HLN) :: {ref, binary()} | {value, HLN}.
-type open_api_spec(HLO) :: {open_api_spec,
binary(),
info(),
gleam@dict:dict(binary(), ref_or(path_item(HLO))),
gleam@option:option(components(HLO)),
list(server()),
list(security_requirement()),
gleam@dict:dict(binary(), ref_or(path_item(HLO))),
list(tag()),
gleam@option:option(external_doc()),
gleam@option:option(binary())}.
-type info() :: {info,
binary(),
gleam@option:option(binary()),
binary(),
gleam@option:option(binary()),
gleam@option:option(binary()),
gleam@option:option(contact()),
gleam@option:option(license())}.
-type contact() :: {contact,
gleam@option:option(binary()),
gleam@option:option(binary()),
gleam@option:option(binary())}.
-type license() :: {license, binary(), gleam@option:option(binary())}.
-type server() :: {server,
binary(),
gleam@option:option(binary()),
gleam@dict:dict(binary(), server_variable())}.
-type server_variable() :: {server_variable,
binary(),
list(binary()),
gleam@option:option(binary())}.
-type external_doc() :: {external_doc, binary(), gleam@option:option(binary())}.
-type tag() :: {tag,
binary(),
gleam@option:option(binary()),
gleam@option:option(external_doc())}.
-type components(HLP) :: {components,
gleam@dict:dict(binary(), oaspec@openapi@schema:schema_ref()),
gleam@dict:dict(binary(), ref_or(parameter(HLP))),
gleam@dict:dict(binary(), ref_or(request_body(HLP))),
gleam@dict:dict(binary(), ref_or(response(HLP))),
gleam@dict:dict(binary(), ref_or(security_scheme())),
gleam@dict:dict(binary(), ref_or(path_item(HLP))),
gleam@dict:dict(binary(), header()),
gleam@dict:dict(binary(), oaspec@openapi@value:json_value()),
gleam@dict:dict(binary(), link()),
gleam@dict:dict(binary(), ref_or(callback(HLP)))}.
-type security_scheme_in() :: scheme_in_header |
scheme_in_query |
scheme_in_cookie.
-type parameter_style() :: form_style |
simple_style |
deep_object_style |
matrix_style |
label_style |
space_delimited_style |
pipe_delimited_style.
-type security_scheme() :: {api_key_scheme, binary(), security_scheme_in()} |
{http_scheme, binary(), gleam@option:option(binary())} |
{o_auth2_scheme,
gleam@option:option(binary()),
gleam@dict:dict(binary(), o_auth2_flow())} |
{open_id_connect_scheme, binary(), gleam@option:option(binary())} |
{unsupported_scheme, binary()}.
-type o_auth2_flow() :: {o_auth2_flow,
gleam@option:option(binary()),
gleam@option:option(binary()),
gleam@option:option(binary()),
gleam@dict:dict(binary(), binary())}.
-type security_scheme_ref() :: {security_scheme_ref, binary(), list(binary())}.
-type security_requirement() :: {security_requirement,
list(security_scheme_ref())}.
-type path_item(HLQ) :: {path_item,
gleam@option:option(binary()),
gleam@option:option(binary()),
gleam@option:option(operation(HLQ)),
gleam@option:option(operation(HLQ)),
gleam@option:option(operation(HLQ)),
gleam@option:option(operation(HLQ)),
gleam@option:option(operation(HLQ)),
gleam@option:option(operation(HLQ)),
gleam@option:option(operation(HLQ)),
gleam@option:option(operation(HLQ)),
list(ref_or(parameter(HLQ))),
list(server())}.
-type operation(HLR) :: {operation,
gleam@option:option(binary()),
gleam@option:option(binary()),
gleam@option:option(binary()),
list(binary()),
list(ref_or(parameter(HLR))),
gleam@option:option(ref_or(request_body(HLR))),
gleam@dict:dict(oaspec@util@http:http_status_code(), ref_or(response(HLR))),
boolean(),
gleam@option:option(list(security_requirement())),
gleam@dict:dict(binary(), ref_or(callback(HLR))),
list(server()),
gleam@option:option(external_doc())}.
-type callback(HLS) :: {callback,
gleam@dict:dict(binary(), ref_or(path_item(HLS)))}.
-type parameter_in() :: in_path | in_query | in_header | in_cookie.
-type parameter_payload() :: {parameter_schema,
oaspec@openapi@schema:schema_ref()} |
{parameter_content, gleam@dict:dict(binary(), media_type())}.
-type parameter(HLT) :: {parameter,
binary(),
parameter_in(),
gleam@option:option(binary()),
boolean(),
parameter_payload(),
gleam@option:option(parameter_style()),
gleam@option:option(boolean()),
boolean(),
boolean(),
gleam@dict:dict(binary(), oaspec@openapi@value:json_value())} |
{gleam_phantom, HLT}.
-type request_body(HLU) :: {request_body,
gleam@option:option(binary()),
gleam@dict:dict(binary(), media_type()),
boolean()} |
{gleam_phantom, HLU}.
-type media_type() :: {media_type,
gleam@option:option(oaspec@openapi@schema:schema_ref()),
gleam@option:option(oaspec@openapi@value:json_value()),
gleam@dict:dict(binary(), oaspec@openapi@value:json_value()),
gleam@dict:dict(binary(), encoding())}.
-type encoding() :: {encoding,
gleam@option:option(binary()),
gleam@option:option(parameter_style()),
gleam@option:option(boolean())}.
-type header() :: {header,
gleam@option:option(binary()),
boolean(),
gleam@option:option(oaspec@openapi@schema:schema_ref())}.
-type link() :: {link,
gleam@option:option(binary()),
gleam@option:option(binary())}.
-type response(HLV) :: {response,
gleam@option:option(binary()),
gleam@dict:dict(binary(), media_type()),
gleam@dict:dict(binary(), header()),
gleam@dict:dict(binary(), link())} |
{gleam_phantom, HLV}.
-type http_method() :: get |
post |
put |
delete |
patch |
head |
options |
trace.
-file("src/oaspec/openapi/spec.gleam", 37).
?DOC(
" Unwrap a RefOr assuming it has been resolved. Panics on Ref.\n"
"\n"
" Callers are expected to hold a `RefOr(a)` from an `OpenApiSpec(Resolved)`\n"
" subtree; the resolve phase statically eliminates `Ref(_)` before this\n"
" runs, so reaching the `Ref` branch would indicate an internal invariant\n"
" violation rather than a user-facing error.\n"
).
-spec unwrap_ref(ref_or(HLW)) -> HLW.
unwrap_ref(Ref_or) ->
case Ref_or of
{value, V} ->
V;
{ref, R} ->
erlang:error(#{gleam_error => panic,
message => (<<"unwrap_ref on unresolved $ref: "/utf8,
R/binary>>),
file => <<?FILEPATH/utf8>>,
module => <<"oaspec/openapi/spec"/utf8>>,
function => <<"unwrap_ref"/utf8>>,
line => 41})
end.
-file("src/oaspec/openapi/spec.gleam", 275).
?DOC(" Extract the schema from a parameter's payload, if it uses schema encoding.\n").
-spec parameter_schema(parameter(any())) -> gleam@option:option(oaspec@openapi@schema:schema_ref()).
parameter_schema(Param) ->
case erlang:element(6, Param) of
{parameter_schema, S} ->
{some, S};
{parameter_content, _} ->
none
end.
-file("src/oaspec/openapi/spec.gleam", 347).
?DOC(" Convert HTTP method to string.\n").
-spec method_to_string(http_method()) -> binary().
method_to_string(Method) ->
case Method of
get ->
<<"GET"/utf8>>;
post ->
<<"POST"/utf8>>;
put ->
<<"PUT"/utf8>>;
delete ->
<<"DELETE"/utf8>>;
patch ->
<<"PATCH"/utf8>>;
head ->
<<"HEAD"/utf8>>;
options ->
<<"OPTIONS"/utf8>>;
trace ->
<<"TRACE"/utf8>>
end.
-file("src/oaspec/openapi/spec.gleam", 361).
?DOC(" Convert HTTP method to lowercase string.\n").
-spec method_to_lower(http_method()) -> binary().
method_to_lower(Method) ->
case Method of
get ->
<<"get"/utf8>>;
post ->
<<"post"/utf8>>;
put ->
<<"put"/utf8>>;
delete ->
<<"delete"/utf8>>;
patch ->
<<"patch"/utf8>>;
head ->
<<"head"/utf8>>;
options ->
<<"options"/utf8>>;
trace ->
<<"trace"/utf8>>
end.