forked from loafle/openapi-generator-original
[Erlang Server] Add more type information and fix minor bugs (#19792)
* Add type information about classes and operation-ids * Remove unused logger included header * Bugfix badmatch in delete_resource handler * Bugfix: respect original indentation of operation_ids * Bugfix json schema correct refs * Add a bit more documentation * Regenerate erlang-server handlers
This commit is contained in:
parent
9163e00932
commit
77e8346fd7
@ -8,29 +8,32 @@ and `validate_response/4` respectively.
|
||||
|
||||
For example, the user-defined `Module:accept_callback/4` can be implemented as follows:
|
||||
```
|
||||
-spec accept_callback(atom(), openapi_api:operation_id(), cowboy_req:req(), context()) ->
|
||||
{cowboy:http_status(), cowboy:http_headers(), json:encode_value()}.
|
||||
accept_callback(Class, OperationID, Req, Context) ->
|
||||
-spec accept_callback(
|
||||
Class :: openapi_api:class(),
|
||||
OperationID :: openapi_api:operation_id(),
|
||||
Req :: cowboy_req:req(),
|
||||
Context :: openapi_logic_handler:context()) ->
|
||||
{openapi_logic_handler:accept_callback_return(),
|
||||
cowboy_req:req(),
|
||||
openapi_logic_handler:context()}.
|
||||
accept_callback(Class, OperationID, Req0, Context0) ->
|
||||
ValidatorState = openapi_api:prepare_validator(),
|
||||
case openapi_api:populate_request(OperationID, Req0, ValidatorState) of
|
||||
{ok, Populated, Req1} ->
|
||||
{Code, Headers, Body} = openapi_logic_handler:handle_request(
|
||||
LogicHandler,
|
||||
OperationID,
|
||||
Req1,
|
||||
maps:merge(State#state.context, Populated)
|
||||
),
|
||||
_ = openapi_api:validate_response(
|
||||
OperationID,
|
||||
Code,
|
||||
Body,
|
||||
ValidatorState
|
||||
),
|
||||
PreparedBody = prepare_body(Code, Body),
|
||||
Response = {ok, {Code, Headers, PreparedBody}},
|
||||
process_response(Response, Req1, State);
|
||||
{ok, Model, Req1} ->
|
||||
Context1 = maps:merge(Context0, Model),
|
||||
case do_accept_callback(Class, OperationID, Req1, Context1) of
|
||||
{false, Req2, Context2} ->
|
||||
{false, Req2, Context2};
|
||||
{{true, Code, Body}, Req2, Context2} ->
|
||||
case validate_response(OperationID, Code, Body, ValidatorState) of
|
||||
ok ->
|
||||
process_response({ok, Code, Body}, Req2, Context2);
|
||||
{error, Reason} ->
|
||||
process_response({error, Reason}, Req2, Context2)
|
||||
end
|
||||
end;
|
||||
{error, Reason, Req1} ->
|
||||
process_response({error, Reason}, Req1, State)
|
||||
process_response({error, Reason}, Req1, Context0)
|
||||
end.
|
||||
```
|
||||
""".
|
||||
@ -41,10 +44,17 @@ accept_callback(Class, OperationID, Req, Context) ->
|
||||
-ignore_xref([populate_request/3, validate_response/4]).
|
||||
-ignore_xref([prepare_validator/0, prepare_validator/1, prepare_validator/2]).
|
||||
|
||||
-type operation_id() :: atom().
|
||||
-type class() ::
|
||||
{{#apiInfo}}{{#apis}}{{#operations}} {{^-first}}| {{/-first}}'{{pathPrefix}}'{{#-last}}.{{/-last}}
|
||||
{{/operations}}{{/apis}}{{/apiInfo}}
|
||||
|
||||
-type operation_id() ::
|
||||
{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}} '{{operationIdOriginal}}' | %% {{summary}}
|
||||
{{/operation}}{{/operations}}{{/apis}}{{/apiInfo}} {error, unknown_operation}.
|
||||
|
||||
-type request_param() :: atom().
|
||||
|
||||
-export_type([operation_id/0]).
|
||||
-export_type([class/0, operation_id/0]).
|
||||
|
||||
-dialyzer({nowarn_function, [validate_response_body/4]}).
|
||||
|
||||
@ -64,6 +74,7 @@ accept_callback(Class, OperationID, Req, Context) ->
|
||||
{max_length, MaxLength :: integer()} |
|
||||
{min_length, MaxLength :: integer()} |
|
||||
{pattern, Pattern :: string()} |
|
||||
{schema, object | list, binary()} |
|
||||
schema |
|
||||
required |
|
||||
not_required.
|
||||
@ -111,7 +122,7 @@ for the `OperationID` operation.
|
||||
Body :: jesse:json_term(),
|
||||
ValidatorState :: jesse_state:state()) ->
|
||||
ok | {ok, term()} | [ok | {ok, term()}] | no_return().
|
||||
{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}{{#responses}}validate_response('{{operationId}}', {{code}}, Body, ValidatorState) ->
|
||||
{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}{{#responses}}validate_response('{{operationIdOriginal}}', {{code}}, Body, ValidatorState) ->
|
||||
validate_response_body('{{dataType}}', '{{baseType}}', Body, ValidatorState);
|
||||
{{/responses}}
|
||||
{{/operation}}{{/operations}}{{/apis}}{{/apiInfo}}validate_response(_OperationID, _Code, _Body, _ValidatorState) ->
|
||||
@ -119,17 +130,17 @@ for the `OperationID` operation.
|
||||
|
||||
%%%
|
||||
-spec request_params(OperationID :: operation_id()) -> [Param :: request_param()].
|
||||
{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}request_params('{{operationId}}') ->
|
||||
{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}request_params('{{operationIdOriginal}}') ->
|
||||
[{{#allParams}}{{^isBodyParam}}
|
||||
'{{baseName}}'{{/isBodyParam}}{{#isBodyParam}}
|
||||
'{{dataType}}'{{/isBodyParam}}{{^-last}},{{/-last}}{{/allParams}}
|
||||
{{#content.application/json.schema.openApiType}}'{{content.application/json.schema.openApiType}}'{{/content.application/json.schema.openApiType}}{{^content.application/json.schema.openApiType}}'{{dataType}}'{{/content.application/json.schema.openApiType}}{{/isBodyParam}}{{^-last}},{{/-last}}{{/allParams}}
|
||||
];
|
||||
{{/operation}}{{/operations}}{{/apis}}{{/apiInfo}}request_params(_) ->
|
||||
error(unknown_operation).
|
||||
|
||||
-spec request_param_info(OperationID :: operation_id(), Name :: request_param()) ->
|
||||
#{source => qs_val | binding | header | body, rules => [rule()]}.
|
||||
{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}{{#allParams}}request_param_info('{{operationId}}', {{^isBodyParam}}'{{baseName}}'{{/isBodyParam}}{{#isBodyParam}}'{{dataType}}'{{/isBodyParam}}) ->
|
||||
{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}{{#allParams}}request_param_info('{{operationIdOriginal}}', {{^isBodyParam}}'{{baseName}}'{{/isBodyParam}}{{#isBodyParam}}{{#content.application/json.schema.openApiType}}'{{content.application/json.schema.openApiType}}'{{/content.application/json.schema.openApiType}}{{^content.application/json.schema.openApiType}}'{{dataType}}'{{/content.application/json.schema.openApiType}}{{/isBodyParam}}) ->
|
||||
#{
|
||||
source => {{#isQueryParam}}qs_val{{/isQueryParam}}{{#isPathParam}}binding{{/isPathParam}}{{#isHeaderParam}}header{{/isHeaderParam}}{{#isBodyParam}}body{{/isBodyParam}}{{#isFormParam}}body{{/isFormParam}},
|
||||
rules => [{{#isString}}
|
||||
@ -150,8 +161,9 @@ for the `OperationID` operation.
|
||||
{exclusive_min, {{minimum}}},{{/exclusiveMinimum}}{{/minimum}}{{#maxLength}}
|
||||
{max_length, {{maxLength}}},{{/maxLength}}{{#minLength}}
|
||||
{min_length, {{minLength}}},{{/minLength}}{{#pattern}}
|
||||
{pattern, "{{{pattern}}}"},{{/pattern}}{{#isBodyParam}}
|
||||
schema,{{/isBodyParam}}{{#required}}
|
||||
{pattern, "{{{pattern}}}"},{{/pattern}}{{#isBodyParam}}{{#content.application/json.schema.ref}}
|
||||
{schema, object, <<"{{content.application/json.schema.ref}}">>},{{/content.application/json.schema.ref}}{{#content.application/json.schema.items.ref}}
|
||||
{schema, list, <<"{{content.application/json.schema.items.ref}}">>},{{/content.application/json.schema.items.ref}}{{/isBodyParam}}{{#required}}
|
||||
required{{/required}}{{^required}}
|
||||
not_required{{/required}}
|
||||
]
|
||||
@ -189,8 +201,6 @@ populate_request_param(OperationID, ReqParamName, Req0, ValidatorState) ->
|
||||
end
|
||||
end.
|
||||
|
||||
-include_lib("kernel/include/logger.hrl").
|
||||
|
||||
validate_response_body(list, ReturnBaseType, Body, ValidatorState) ->
|
||||
[
|
||||
validate(schema, Item, ReturnBaseType, ValidatorState)
|
||||
@ -281,8 +291,15 @@ validate(Rule = {pattern, Pattern}, Value, ReqParamName, _) ->
|
||||
{match, _} -> ok;
|
||||
_ -> validation_error(Rule, ReqParamName, Value)
|
||||
end;
|
||||
validate(Rule = schema, Value, ReqParamName, ValidatorState) ->
|
||||
validate(schema, Value, ReqParamName, ValidatorState) ->
|
||||
Definition = iolist_to_binary(["#/components/schemas/", atom_to_binary(ReqParamName, utf8)]),
|
||||
validate({schema, object, Definition}, Value, ReqParamName, ValidatorState);
|
||||
validate({schema, list, Definition}, Value, ReqParamName, ValidatorState) ->
|
||||
lists:foreach(
|
||||
fun(Item) ->
|
||||
validate({schema, object, Definition}, Item, ReqParamName, ValidatorState)
|
||||
end, Value);
|
||||
validate(Rule = {schema, object, Definition}, Value, ReqParamName, ValidatorState) ->
|
||||
try
|
||||
_ = validate_with_schema(Value, Definition, ValidatorState),
|
||||
ok
|
||||
|
@ -2,8 +2,9 @@
|
||||
-moduledoc """
|
||||
Exposes the following operation IDs:
|
||||
{{#operations}}{{#operation}}
|
||||
- `{{httpMethod}}` to `{{path}}`, OperationId: `{{operationId}}`:
|
||||
- `{{httpMethod}}` to `{{path}}`, OperationId: `{{operationIdOriginal}}`:
|
||||
{{summary}}.
|
||||
{{notes}}
|
||||
{{/operation}}{{/operations}}
|
||||
""".
|
||||
|
||||
@ -23,8 +24,16 @@ Exposes the following operation IDs:
|
||||
|
||||
-ignore_xref([handle_type_accepted/2, handle_type_provided/2]).
|
||||
|
||||
-export_type([class/0, operation_id/0]).
|
||||
|
||||
-type class() :: '{{operations.pathPrefix}}'.
|
||||
|
||||
-type operation_id() ::
|
||||
{{#operations}}{{#operation}} {{^-first}}| {{/-first}}'{{operationIdOriginal}}'{{#-last}}.{{/-last}} %% {{summary}}
|
||||
{{/operation}}{{/operations}}
|
||||
|
||||
-record(state,
|
||||
{operation_id :: {{packageName}}_api:operation_id(),
|
||||
{operation_id :: operation_id(),
|
||||
accept_callback :: {{packageName}}_logic_handler:accept_callback(),
|
||||
provide_callback :: {{packageName}}_logic_handler:provide_callback(),
|
||||
api_key_handler :: {{packageName}}_logic_handler:api_key_callback(),
|
||||
@ -48,7 +57,7 @@ init(Req, {Operations, Module}) ->
|
||||
|
||||
-spec allowed_methods(cowboy_req:req(), state()) ->
|
||||
{[binary()], cowboy_req:req(), state()}.
|
||||
{{#operations}}{{#operation}}allowed_methods(Req, #state{operation_id = '{{operationId}}'} = State) ->
|
||||
{{#operations}}{{#operation}}allowed_methods(Req, #state{operation_id = '{{operationIdOriginal}}'} = State) ->
|
||||
{[<<"{{httpMethod}}">>], Req, State};
|
||||
{{/operation}}{{/operations}}allowed_methods(Req, State) ->
|
||||
{[], Req, State}.
|
||||
@ -59,7 +68,7 @@ init(Req, {Operations, Module}) ->
|
||||
{{#operation}}
|
||||
{{#authMethods.size}}
|
||||
is_authorized(Req0,
|
||||
#state{operation_id = '{{operationId}}' = OperationID,
|
||||
#state{operation_id = '{{operationIdOriginal}}' = OperationID,
|
||||
api_key_handler = Handler} = State) ->
|
||||
case {{packageName}}_auth:authorize_api_key(Handler, OperationID, {{#isApiKey.isKeyInQuery}}qs_val, {{/isApiKey.isKeyInQuery}}{{^isApiKey.isKeyInQuery}}header, {{/isApiKey.isKeyInQuery}}{{#isApiKey}}"{{keyParamName}}", {{/isApiKey}}{{^isApiKey}}"authorization", {{/isApiKey}}Req0) of
|
||||
{true, Context, Req} ->
|
||||
@ -75,7 +84,7 @@ is_authorized(Req, State) ->
|
||||
|
||||
-spec content_types_accepted(cowboy_req:req(), state()) ->
|
||||
{[{binary(), atom()}], cowboy_req:req(), state()}.
|
||||
{{#operations}}{{#operation}}content_types_accepted(Req, #state{operation_id = '{{operationId}}'} = State) ->
|
||||
{{#operations}}{{#operation}}content_types_accepted(Req, #state{operation_id = '{{operationIdOriginal}}'} = State) ->
|
||||
{{^consumes.size}}
|
||||
{[], Req, State};
|
||||
{{/consumes.size}}
|
||||
@ -91,14 +100,14 @@ is_authorized(Req, State) ->
|
||||
|
||||
-spec valid_content_headers(cowboy_req:req(), state()) ->
|
||||
{boolean(), cowboy_req:req(), state()}.
|
||||
{{#operations}}{{#operation}}valid_content_headers(Req, #state{operation_id = '{{operationId}}'} = State) ->
|
||||
{{#operations}}{{#operation}}valid_content_headers(Req, #state{operation_id = '{{operationIdOriginal}}'} = State) ->
|
||||
{true, Req, State};
|
||||
{{/operation}}{{/operations}}valid_content_headers(Req, State) ->
|
||||
{false, Req, State}.
|
||||
|
||||
-spec content_types_provided(cowboy_req:req(), state()) ->
|
||||
{[{binary(), atom()}], cowboy_req:req(), state()}.
|
||||
{{#operations}}{{#operation}}content_types_provided(Req, #state{operation_id = '{{operationId}}'} = State) ->
|
||||
{{#operations}}{{#operation}}content_types_provided(Req, #state{operation_id = '{{operationIdOriginal}}'} = State) ->
|
||||
{{^produces.size}}
|
||||
{[], Req, State};
|
||||
{{/produces.size}}
|
||||
@ -115,8 +124,8 @@ is_authorized(Req, State) ->
|
||||
-spec delete_resource(cowboy_req:req(), state()) ->
|
||||
{boolean(), cowboy_req:req(), state()}.
|
||||
delete_resource(Req, State) ->
|
||||
{Res, Req1, State} = handle_type_accepted(Req, State),
|
||||
{true =:= Res, Req1, State}.
|
||||
{Res, Req1, State1} = handle_type_accepted(Req, State),
|
||||
{true =:= Res, Req1, State1}.
|
||||
|
||||
-spec handle_type_accepted(cowboy_req:req(), state()) ->
|
||||
{ {{packageName}}_logic_handler:accept_callback_return(), cowboy_req:req(), state()}.
|
||||
|
@ -11,10 +11,10 @@
|
||||
-type api_key_callback() ::
|
||||
fun(({{packageName}}_api:operation_id(), binary()) -> {true, context()} | {false, iodata()}).
|
||||
-type accept_callback() ::
|
||||
fun((atom(), {{packageName}}_api:operation_id(), cowboy_req:req(), context()) ->
|
||||
fun(({{packageName}}_api:class(), {{packageName}}_api:operation_id(), cowboy_req:req(), context()) ->
|
||||
{accept_callback_return(), cowboy_req:req(), context()}).
|
||||
-type provide_callback() ::
|
||||
fun((atom(), {{packageName}}_api:operation_id(), cowboy_req:req(), context()) ->
|
||||
fun(({{packageName}}_api:class(), {{packageName}}_api:operation_id(), cowboy_req:req(), context()) ->
|
||||
{cowboy_req:resp_body(), cowboy_req:req(), context()}).
|
||||
-type context() :: #{_ := _}.
|
||||
|
||||
@ -26,10 +26,10 @@
|
||||
-callback api_key_callback({{packageName}}_api:operation_id(), binary()) ->
|
||||
{true, context()} | {false, iodata()}.
|
||||
|
||||
-callback accept_callback(atom(), {{packageName}}_api:operation_id(), cowboy_req:req(), context()) ->
|
||||
-callback accept_callback({{packageName}}_api:class(), {{packageName}}_api:operation_id(), cowboy_req:req(), context()) ->
|
||||
{accept_callback_return(), cowboy_req:req(), context()}.
|
||||
|
||||
-callback provide_callback(atom(), {{packageName}}_api:operation_id(), cowboy_req:req(), context()) ->
|
||||
-callback provide_callback({{packageName}}_api:class(), {{packageName}}_api:operation_id(), cowboy_req:req(), context()) ->
|
||||
{cowboy_req:resp_body(), cowboy_req:req(), context()}.
|
||||
|
||||
-export([api_key_callback/2, accept_callback/4, provide_callback/4]).
|
||||
@ -42,7 +42,7 @@ api_key_callback(OperationID, ApiKey) ->
|
||||
api_key => ApiKey}),
|
||||
{true, #{}}.
|
||||
|
||||
-spec accept_callback(atom(), {{packageName}}_api:operation_id(), cowboy_req:req(), context()) ->
|
||||
-spec accept_callback({{packageName}}_api:class(), {{packageName}}_api:operation_id(), cowboy_req:req(), context()) ->
|
||||
{accept_callback_return(), cowboy_req:req(), context()}.
|
||||
accept_callback(Class, OperationID, Req, Context) ->
|
||||
?LOG_ERROR(#{what => "Got not implemented request to process",
|
||||
@ -52,7 +52,7 @@ accept_callback(Class, OperationID, Req, Context) ->
|
||||
context => Context}),
|
||||
{false, Req, Context}.
|
||||
|
||||
-spec provide_callback(atom(), {{packageName}}_api:operation_id(), cowboy_req:req(), context()) ->
|
||||
-spec provide_callback({{packageName}}_api:class(), {{packageName}}_api:operation_id(), cowboy_req:req(), context()) ->
|
||||
{cowboy_req:resp_body(), cowboy_req:req(), context()}.
|
||||
provide_callback(Class, OperationID, Req, Context) ->
|
||||
?LOG_ERROR(#{what => "Got not implemented request to process",
|
||||
|
@ -47,7 +47,7 @@ merge_paths(FullPaths, OperationID, Method, Handler, Acc) ->
|
||||
|
||||
get_operations() ->
|
||||
#{ {{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}
|
||||
'{{operationId}}' => #{
|
||||
'{{operationIdOriginal}}' => #{
|
||||
servers => [{{#servers}}"{{{url}}}"{{^-last}},{{/-last}}{{/servers}}],
|
||||
base_path => "{{{basePathWithoutHost}}}",
|
||||
path => "{{{path}}}",
|
||||
|
@ -8,29 +8,32 @@ and `validate_response/4` respectively.
|
||||
|
||||
For example, the user-defined `Module:accept_callback/4` can be implemented as follows:
|
||||
```
|
||||
-spec accept_callback(atom(), openapi_api:operation_id(), cowboy_req:req(), context()) ->
|
||||
{cowboy:http_status(), cowboy:http_headers(), json:encode_value()}.
|
||||
accept_callback(Class, OperationID, Req, Context) ->
|
||||
-spec accept_callback(
|
||||
Class :: openapi_api:class(),
|
||||
OperationID :: openapi_api:operation_id(),
|
||||
Req :: cowboy_req:req(),
|
||||
Context :: openapi_logic_handler:context()) ->
|
||||
{openapi_logic_handler:accept_callback_return(),
|
||||
cowboy_req:req(),
|
||||
openapi_logic_handler:context()}.
|
||||
accept_callback(Class, OperationID, Req0, Context0) ->
|
||||
ValidatorState = openapi_api:prepare_validator(),
|
||||
case openapi_api:populate_request(OperationID, Req0, ValidatorState) of
|
||||
{ok, Populated, Req1} ->
|
||||
{Code, Headers, Body} = openapi_logic_handler:handle_request(
|
||||
LogicHandler,
|
||||
OperationID,
|
||||
Req1,
|
||||
maps:merge(State#state.context, Populated)
|
||||
),
|
||||
_ = openapi_api:validate_response(
|
||||
OperationID,
|
||||
Code,
|
||||
Body,
|
||||
ValidatorState
|
||||
),
|
||||
PreparedBody = prepare_body(Code, Body),
|
||||
Response = {ok, {Code, Headers, PreparedBody}},
|
||||
process_response(Response, Req1, State);
|
||||
{ok, Model, Req1} ->
|
||||
Context1 = maps:merge(Context0, Model),
|
||||
case do_accept_callback(Class, OperationID, Req1, Context1) of
|
||||
{false, Req2, Context2} ->
|
||||
{false, Req2, Context2};
|
||||
{{true, Code, Body}, Req2, Context2} ->
|
||||
case validate_response(OperationID, Code, Body, ValidatorState) of
|
||||
ok ->
|
||||
process_response({ok, Code, Body}, Req2, Context2);
|
||||
{error, Reason} ->
|
||||
process_response({error, Reason}, Req2, Context2)
|
||||
end
|
||||
end;
|
||||
{error, Reason, Req1} ->
|
||||
process_response({error, Reason}, Req1, State)
|
||||
process_response({error, Reason}, Req1, Context0)
|
||||
end.
|
||||
```
|
||||
""".
|
||||
@ -41,10 +44,48 @@ accept_callback(Class, OperationID, Req, Context) ->
|
||||
-ignore_xref([populate_request/3, validate_response/4]).
|
||||
-ignore_xref([prepare_validator/0, prepare_validator/1, prepare_validator/2]).
|
||||
|
||||
-type operation_id() :: atom().
|
||||
-type class() ::
|
||||
'auth'
|
||||
| 'body'
|
||||
| 'form'
|
||||
| 'header'
|
||||
| 'path'
|
||||
| 'query'.
|
||||
|
||||
|
||||
-type operation_id() ::
|
||||
'test/auth/http/basic' | %% To test HTTP basic authentication
|
||||
'test/auth/http/bearer' | %% To test HTTP bearer authentication
|
||||
'test/binary/gif' | %% Test binary (gif) response body
|
||||
'test/body/application/octetstream/binary' | %% Test body parameter(s)
|
||||
'test/body/multipart/formdata/array_of_binary' | %% Test array of binary in multipart mime
|
||||
'test/body/multipart/formdata/single_binary' | %% Test single binary in multipart mime
|
||||
'test/echo/body/allOf/Pet' | %% Test body parameter(s)
|
||||
'test/echo/body/FreeFormObject/response_string' | %% Test free form object
|
||||
'test/echo/body/Pet' | %% Test body parameter(s)
|
||||
'test/echo/body/Pet/response_string' | %% Test empty response body
|
||||
'test/echo/body/string_enum' | %% Test string enum response body
|
||||
'test/echo/body/Tag/response_string' | %% Test empty json (request body)
|
||||
'test/form/integer/boolean/string' | %% Test form parameter(s)
|
||||
'test/form/object/multipart' | %% Test form parameter(s) for multipart schema
|
||||
'test/form/oneof' | %% Test form parameter(s) for oneOf schema
|
||||
'test/header/integer/boolean/string/enums' | %% Test header parameter(s)
|
||||
'tests/path/string/{path_string}/integer/{path_integer}/{enum_nonref_string_path}/{enum_ref_string_path}' | %% Test path parameter(s)
|
||||
'test/enum_ref_string' | %% Test query parameter(s)
|
||||
'test/query/datetime/date/string' | %% Test query parameter(s)
|
||||
'test/query/integer/boolean/string' | %% Test query parameter(s)
|
||||
'test/query/style_deepObject/explode_true/object' | %% Test query parameter(s)
|
||||
'test/query/style_deepObject/explode_true/object/allOf' | %% Test query parameter(s)
|
||||
'test/query/style_form/explode_false/array_integer' | %% Test query parameter(s)
|
||||
'test/query/style_form/explode_false/array_string' | %% Test query parameter(s)
|
||||
'test/query/style_form/explode_true/array_string' | %% Test query parameter(s)
|
||||
'test/query/style_form/explode_true/object' | %% Test query parameter(s)
|
||||
'test/query/style_form/explode_true/object/allOf' | %% Test query parameter(s)
|
||||
{error, unknown_operation}.
|
||||
|
||||
-type request_param() :: atom().
|
||||
|
||||
-export_type([operation_id/0]).
|
||||
-export_type([class/0, operation_id/0]).
|
||||
|
||||
-dialyzer({nowarn_function, [validate_response_body/4]}).
|
||||
|
||||
@ -64,6 +105,7 @@ accept_callback(Class, OperationID, Req, Context) ->
|
||||
{max_length, MaxLength :: integer()} |
|
||||
{min_length, MaxLength :: integer()} |
|
||||
{pattern, Pattern :: string()} |
|
||||
{schema, object | list, binary()} |
|
||||
schema |
|
||||
required |
|
||||
not_required.
|
||||
@ -111,121 +153,121 @@ for the `OperationID` operation.
|
||||
Body :: jesse:json_term(),
|
||||
ValidatorState :: jesse_state:state()) ->
|
||||
ok | {ok, term()} | [ok | {ok, term()}] | no_return().
|
||||
validate_response('TestAuthHttpBasic', 200, Body, ValidatorState) ->
|
||||
validate_response('test/auth/http/basic', 200, Body, ValidatorState) ->
|
||||
validate_response_body('binary', 'string', Body, ValidatorState);
|
||||
validate_response('TestAuthHttpBearer', 200, Body, ValidatorState) ->
|
||||
validate_response('test/auth/http/bearer', 200, Body, ValidatorState) ->
|
||||
validate_response_body('binary', 'string', Body, ValidatorState);
|
||||
validate_response('TestBinaryGif', 200, Body, ValidatorState) ->
|
||||
validate_response('test/binary/gif', 200, Body, ValidatorState) ->
|
||||
validate_response_body('file', 'file', Body, ValidatorState);
|
||||
validate_response('TestBodyApplicationOctetstreamBinary', 200, Body, ValidatorState) ->
|
||||
validate_response('test/body/application/octetstream/binary', 200, Body, ValidatorState) ->
|
||||
validate_response_body('binary', 'string', Body, ValidatorState);
|
||||
validate_response('TestBodyMultipartFormdataArrayOfBinary', 200, Body, ValidatorState) ->
|
||||
validate_response('test/body/multipart/formdata/array_of_binary', 200, Body, ValidatorState) ->
|
||||
validate_response_body('binary', 'string', Body, ValidatorState);
|
||||
validate_response('TestBodyMultipartFormdataSingleBinary', 200, Body, ValidatorState) ->
|
||||
validate_response('test/body/multipart/formdata/single_binary', 200, Body, ValidatorState) ->
|
||||
validate_response_body('binary', 'string', Body, ValidatorState);
|
||||
validate_response('TestEchoBodyAllOfPet', 200, Body, ValidatorState) ->
|
||||
validate_response('test/echo/body/allOf/Pet', 200, Body, ValidatorState) ->
|
||||
validate_response_body('Pet', 'Pet', Body, ValidatorState);
|
||||
validate_response('TestEchoBodyFreeFormObjectResponseString', 200, Body, ValidatorState) ->
|
||||
validate_response('test/echo/body/FreeFormObject/response_string', 200, Body, ValidatorState) ->
|
||||
validate_response_body('binary', 'string', Body, ValidatorState);
|
||||
validate_response('TestEchoBodyPet', 200, Body, ValidatorState) ->
|
||||
validate_response('test/echo/body/Pet', 200, Body, ValidatorState) ->
|
||||
validate_response_body('Pet', 'Pet', Body, ValidatorState);
|
||||
validate_response('TestEchoBodyPetResponseString', 200, Body, ValidatorState) ->
|
||||
validate_response('test/echo/body/Pet/response_string', 200, Body, ValidatorState) ->
|
||||
validate_response_body('binary', 'string', Body, ValidatorState);
|
||||
validate_response('TestEchoBodyStringEnum', 200, Body, ValidatorState) ->
|
||||
validate_response('test/echo/body/string_enum', 200, Body, ValidatorState) ->
|
||||
validate_response_body('StringEnumRef', 'StringEnumRef', Body, ValidatorState);
|
||||
validate_response('TestEchoBodyTagResponseString', 200, Body, ValidatorState) ->
|
||||
validate_response('test/echo/body/Tag/response_string', 200, Body, ValidatorState) ->
|
||||
validate_response_body('binary', 'string', Body, ValidatorState);
|
||||
validate_response('TestFormIntegerBooleanString', 200, Body, ValidatorState) ->
|
||||
validate_response('test/form/integer/boolean/string', 200, Body, ValidatorState) ->
|
||||
validate_response_body('binary', 'string', Body, ValidatorState);
|
||||
validate_response('TestFormObjectMultipart', 200, Body, ValidatorState) ->
|
||||
validate_response('test/form/object/multipart', 200, Body, ValidatorState) ->
|
||||
validate_response_body('binary', 'string', Body, ValidatorState);
|
||||
validate_response('TestFormOneof', 200, Body, ValidatorState) ->
|
||||
validate_response('test/form/oneof', 200, Body, ValidatorState) ->
|
||||
validate_response_body('binary', 'string', Body, ValidatorState);
|
||||
validate_response('TestHeaderIntegerBooleanStringEnums', 200, Body, ValidatorState) ->
|
||||
validate_response('test/header/integer/boolean/string/enums', 200, Body, ValidatorState) ->
|
||||
validate_response_body('binary', 'string', Body, ValidatorState);
|
||||
validate_response('TestsPathString{pathString}Integer{pathInteger}{enumNonrefStringPath}{enumRefStringPath}', 200, Body, ValidatorState) ->
|
||||
validate_response('tests/path/string/{path_string}/integer/{path_integer}/{enum_nonref_string_path}/{enum_ref_string_path}', 200, Body, ValidatorState) ->
|
||||
validate_response_body('binary', 'string', Body, ValidatorState);
|
||||
validate_response('TestEnumRefString', 200, Body, ValidatorState) ->
|
||||
validate_response('test/enum_ref_string', 200, Body, ValidatorState) ->
|
||||
validate_response_body('binary', 'string', Body, ValidatorState);
|
||||
validate_response('TestQueryDatetimeDateString', 200, Body, ValidatorState) ->
|
||||
validate_response('test/query/datetime/date/string', 200, Body, ValidatorState) ->
|
||||
validate_response_body('binary', 'string', Body, ValidatorState);
|
||||
validate_response('TestQueryIntegerBooleanString', 200, Body, ValidatorState) ->
|
||||
validate_response('test/query/integer/boolean/string', 200, Body, ValidatorState) ->
|
||||
validate_response_body('binary', 'string', Body, ValidatorState);
|
||||
validate_response('TestQueryStyleDeepObjectExplodeTrueObject', 200, Body, ValidatorState) ->
|
||||
validate_response('test/query/style_deepObject/explode_true/object', 200, Body, ValidatorState) ->
|
||||
validate_response_body('binary', 'string', Body, ValidatorState);
|
||||
validate_response('TestQueryStyleDeepObjectExplodeTrueObjectAllOf', 200, Body, ValidatorState) ->
|
||||
validate_response('test/query/style_deepObject/explode_true/object/allOf', 200, Body, ValidatorState) ->
|
||||
validate_response_body('binary', 'string', Body, ValidatorState);
|
||||
validate_response('TestQueryStyleFormExplodeFalseArrayInteger', 200, Body, ValidatorState) ->
|
||||
validate_response('test/query/style_form/explode_false/array_integer', 200, Body, ValidatorState) ->
|
||||
validate_response_body('binary', 'string', Body, ValidatorState);
|
||||
validate_response('TestQueryStyleFormExplodeFalseArrayString', 200, Body, ValidatorState) ->
|
||||
validate_response('test/query/style_form/explode_false/array_string', 200, Body, ValidatorState) ->
|
||||
validate_response_body('binary', 'string', Body, ValidatorState);
|
||||
validate_response('TestQueryStyleFormExplodeTrueArrayString', 200, Body, ValidatorState) ->
|
||||
validate_response('test/query/style_form/explode_true/array_string', 200, Body, ValidatorState) ->
|
||||
validate_response_body('binary', 'string', Body, ValidatorState);
|
||||
validate_response('TestQueryStyleFormExplodeTrueObject', 200, Body, ValidatorState) ->
|
||||
validate_response('test/query/style_form/explode_true/object', 200, Body, ValidatorState) ->
|
||||
validate_response_body('binary', 'string', Body, ValidatorState);
|
||||
validate_response('TestQueryStyleFormExplodeTrueObjectAllOf', 200, Body, ValidatorState) ->
|
||||
validate_response('test/query/style_form/explode_true/object/allOf', 200, Body, ValidatorState) ->
|
||||
validate_response_body('binary', 'string', Body, ValidatorState);
|
||||
validate_response(_OperationID, _Code, _Body, _ValidatorState) ->
|
||||
ok.
|
||||
|
||||
%%%
|
||||
-spec request_params(OperationID :: operation_id()) -> [Param :: request_param()].
|
||||
request_params('TestAuthHttpBasic') ->
|
||||
request_params('test/auth/http/basic') ->
|
||||
[
|
||||
];
|
||||
request_params('TestAuthHttpBearer') ->
|
||||
request_params('test/auth/http/bearer') ->
|
||||
[
|
||||
];
|
||||
request_params('TestBinaryGif') ->
|
||||
request_params('test/binary/gif') ->
|
||||
[
|
||||
];
|
||||
request_params('TestBodyApplicationOctetstreamBinary') ->
|
||||
request_params('test/body/application/octetstream/binary') ->
|
||||
[
|
||||
'file'
|
||||
];
|
||||
request_params('TestBodyMultipartFormdataArrayOfBinary') ->
|
||||
request_params('test/body/multipart/formdata/array_of_binary') ->
|
||||
[
|
||||
'files'
|
||||
];
|
||||
request_params('TestBodyMultipartFormdataSingleBinary') ->
|
||||
request_params('test/body/multipart/formdata/single_binary') ->
|
||||
[
|
||||
'my-file'
|
||||
];
|
||||
request_params('TestEchoBodyAllOfPet') ->
|
||||
request_params('test/echo/body/allOf/Pet') ->
|
||||
[
|
||||
'Pet'
|
||||
];
|
||||
request_params('TestEchoBodyFreeFormObjectResponseString') ->
|
||||
request_params('test/echo/body/FreeFormObject/response_string') ->
|
||||
[
|
||||
'object'
|
||||
];
|
||||
request_params('TestEchoBodyPet') ->
|
||||
request_params('test/echo/body/Pet') ->
|
||||
[
|
||||
'Pet'
|
||||
];
|
||||
request_params('TestEchoBodyPetResponseString') ->
|
||||
request_params('test/echo/body/Pet/response_string') ->
|
||||
[
|
||||
'Pet'
|
||||
];
|
||||
request_params('TestEchoBodyStringEnum') ->
|
||||
request_params('test/echo/body/string_enum') ->
|
||||
[
|
||||
'binary'
|
||||
'StringEnumRef'
|
||||
];
|
||||
request_params('TestEchoBodyTagResponseString') ->
|
||||
request_params('test/echo/body/Tag/response_string') ->
|
||||
[
|
||||
'Tag'
|
||||
];
|
||||
request_params('TestFormIntegerBooleanString') ->
|
||||
request_params('test/form/integer/boolean/string') ->
|
||||
[
|
||||
'integer_form',
|
||||
'boolean_form',
|
||||
'string_form'
|
||||
];
|
||||
request_params('TestFormObjectMultipart') ->
|
||||
request_params('test/form/object/multipart') ->
|
||||
[
|
||||
'marker'
|
||||
];
|
||||
request_params('TestFormOneof') ->
|
||||
request_params('test/form/oneof') ->
|
||||
[
|
||||
'form1',
|
||||
'form2',
|
||||
@ -234,7 +276,7 @@ request_params('TestFormOneof') ->
|
||||
'id',
|
||||
'name'
|
||||
];
|
||||
request_params('TestHeaderIntegerBooleanStringEnums') ->
|
||||
request_params('test/header/integer/boolean/string/enums') ->
|
||||
[
|
||||
'integer_header',
|
||||
'boolean_header',
|
||||
@ -242,55 +284,55 @@ request_params('TestHeaderIntegerBooleanStringEnums') ->
|
||||
'enum_nonref_string_header',
|
||||
'enum_ref_string_header'
|
||||
];
|
||||
request_params('TestsPathString{pathString}Integer{pathInteger}{enumNonrefStringPath}{enumRefStringPath}') ->
|
||||
request_params('tests/path/string/{path_string}/integer/{path_integer}/{enum_nonref_string_path}/{enum_ref_string_path}') ->
|
||||
[
|
||||
'path_string',
|
||||
'path_integer',
|
||||
'enum_nonref_string_path',
|
||||
'enum_ref_string_path'
|
||||
];
|
||||
request_params('TestEnumRefString') ->
|
||||
request_params('test/enum_ref_string') ->
|
||||
[
|
||||
'enum_nonref_string_query',
|
||||
'enum_ref_string_query'
|
||||
];
|
||||
request_params('TestQueryDatetimeDateString') ->
|
||||
request_params('test/query/datetime/date/string') ->
|
||||
[
|
||||
'datetime_query',
|
||||
'date_query',
|
||||
'string_query'
|
||||
];
|
||||
request_params('TestQueryIntegerBooleanString') ->
|
||||
request_params('test/query/integer/boolean/string') ->
|
||||
[
|
||||
'integer_query',
|
||||
'boolean_query',
|
||||
'string_query'
|
||||
];
|
||||
request_params('TestQueryStyleDeepObjectExplodeTrueObject') ->
|
||||
request_params('test/query/style_deepObject/explode_true/object') ->
|
||||
[
|
||||
'query_object'
|
||||
];
|
||||
request_params('TestQueryStyleDeepObjectExplodeTrueObjectAllOf') ->
|
||||
request_params('test/query/style_deepObject/explode_true/object/allOf') ->
|
||||
[
|
||||
'query_object'
|
||||
];
|
||||
request_params('TestQueryStyleFormExplodeFalseArrayInteger') ->
|
||||
request_params('test/query/style_form/explode_false/array_integer') ->
|
||||
[
|
||||
'query_object'
|
||||
];
|
||||
request_params('TestQueryStyleFormExplodeFalseArrayString') ->
|
||||
request_params('test/query/style_form/explode_false/array_string') ->
|
||||
[
|
||||
'query_object'
|
||||
];
|
||||
request_params('TestQueryStyleFormExplodeTrueArrayString') ->
|
||||
request_params('test/query/style_form/explode_true/array_string') ->
|
||||
[
|
||||
'query_object'
|
||||
];
|
||||
request_params('TestQueryStyleFormExplodeTrueObject') ->
|
||||
request_params('test/query/style_form/explode_true/object') ->
|
||||
[
|
||||
'query_object'
|
||||
];
|
||||
request_params('TestQueryStyleFormExplodeTrueObjectAllOf') ->
|
||||
request_params('test/query/style_form/explode_true/object/allOf') ->
|
||||
[
|
||||
'query_object'
|
||||
];
|
||||
@ -299,23 +341,22 @@ request_params(_) ->
|
||||
|
||||
-spec request_param_info(OperationID :: operation_id(), Name :: request_param()) ->
|
||||
#{source => qs_val | binding | header | body, rules => [rule()]}.
|
||||
request_param_info('TestBodyApplicationOctetstreamBinary', 'file') ->
|
||||
request_param_info('test/body/application/octetstream/binary', 'file') ->
|
||||
#{
|
||||
source => body,
|
||||
rules => [
|
||||
{type, binary},
|
||||
schema,
|
||||
not_required
|
||||
]
|
||||
};
|
||||
request_param_info('TestBodyMultipartFormdataArrayOfBinary', 'files') ->
|
||||
request_param_info('test/body/multipart/formdata/array_of_binary', 'files') ->
|
||||
#{
|
||||
source => body,
|
||||
rules => [
|
||||
required
|
||||
]
|
||||
};
|
||||
request_param_info('TestBodyMultipartFormdataSingleBinary', 'my-file') ->
|
||||
request_param_info('test/body/multipart/formdata/single_binary', 'my-file') ->
|
||||
#{
|
||||
source => body,
|
||||
rules => [
|
||||
@ -323,55 +364,54 @@ request_param_info('TestBodyMultipartFormdataSingleBinary', 'my-file') ->
|
||||
not_required
|
||||
]
|
||||
};
|
||||
request_param_info('TestEchoBodyAllOfPet', 'Pet') ->
|
||||
request_param_info('test/echo/body/allOf/Pet', 'Pet') ->
|
||||
#{
|
||||
source => body,
|
||||
rules => [
|
||||
schema,
|
||||
{schema, object, <<"#/components/schemas/Pet">>},
|
||||
not_required
|
||||
]
|
||||
};
|
||||
request_param_info('TestEchoBodyFreeFormObjectResponseString', 'object') ->
|
||||
request_param_info('test/echo/body/FreeFormObject/response_string', 'object') ->
|
||||
#{
|
||||
source => body,
|
||||
rules => [
|
||||
schema,
|
||||
not_required
|
||||
]
|
||||
};
|
||||
request_param_info('TestEchoBodyPet', 'Pet') ->
|
||||
request_param_info('test/echo/body/Pet', 'Pet') ->
|
||||
#{
|
||||
source => body,
|
||||
rules => [
|
||||
schema,
|
||||
{schema, object, <<"#/components/schemas/Pet">>},
|
||||
not_required
|
||||
]
|
||||
};
|
||||
request_param_info('TestEchoBodyPetResponseString', 'Pet') ->
|
||||
request_param_info('test/echo/body/Pet/response_string', 'Pet') ->
|
||||
#{
|
||||
source => body,
|
||||
rules => [
|
||||
schema,
|
||||
{schema, object, <<"#/components/schemas/Pet">>},
|
||||
not_required
|
||||
]
|
||||
};
|
||||
request_param_info('TestEchoBodyStringEnum', 'binary') ->
|
||||
request_param_info('test/echo/body/string_enum', 'StringEnumRef') ->
|
||||
#{
|
||||
source => body,
|
||||
rules => [
|
||||
schema,
|
||||
{schema, object, <<"#/components/schemas/StringEnumRef">>},
|
||||
not_required
|
||||
]
|
||||
};
|
||||
request_param_info('TestEchoBodyTagResponseString', 'Tag') ->
|
||||
request_param_info('test/echo/body/Tag/response_string', 'Tag') ->
|
||||
#{
|
||||
source => body,
|
||||
rules => [
|
||||
schema,
|
||||
{schema, object, <<"#/components/schemas/Tag">>},
|
||||
not_required
|
||||
]
|
||||
};
|
||||
request_param_info('TestFormIntegerBooleanString', 'integer_form') ->
|
||||
request_param_info('test/form/integer/boolean/string', 'integer_form') ->
|
||||
#{
|
||||
source => body,
|
||||
rules => [
|
||||
@ -379,7 +419,7 @@ request_param_info('TestFormIntegerBooleanString', 'integer_form') ->
|
||||
not_required
|
||||
]
|
||||
};
|
||||
request_param_info('TestFormIntegerBooleanString', 'boolean_form') ->
|
||||
request_param_info('test/form/integer/boolean/string', 'boolean_form') ->
|
||||
#{
|
||||
source => body,
|
||||
rules => [
|
||||
@ -387,7 +427,7 @@ request_param_info('TestFormIntegerBooleanString', 'boolean_form') ->
|
||||
not_required
|
||||
]
|
||||
};
|
||||
request_param_info('TestFormIntegerBooleanString', 'string_form') ->
|
||||
request_param_info('test/form/integer/boolean/string', 'string_form') ->
|
||||
#{
|
||||
source => body,
|
||||
rules => [
|
||||
@ -395,14 +435,14 @@ request_param_info('TestFormIntegerBooleanString', 'string_form') ->
|
||||
not_required
|
||||
]
|
||||
};
|
||||
request_param_info('TestFormObjectMultipart', 'marker') ->
|
||||
request_param_info('test/form/object/multipart', 'marker') ->
|
||||
#{
|
||||
source => body,
|
||||
rules => [
|
||||
required
|
||||
]
|
||||
};
|
||||
request_param_info('TestFormOneof', 'form1') ->
|
||||
request_param_info('test/form/oneof', 'form1') ->
|
||||
#{
|
||||
source => body,
|
||||
rules => [
|
||||
@ -410,7 +450,7 @@ request_param_info('TestFormOneof', 'form1') ->
|
||||
not_required
|
||||
]
|
||||
};
|
||||
request_param_info('TestFormOneof', 'form2') ->
|
||||
request_param_info('test/form/oneof', 'form2') ->
|
||||
#{
|
||||
source => body,
|
||||
rules => [
|
||||
@ -418,7 +458,7 @@ request_param_info('TestFormOneof', 'form2') ->
|
||||
not_required
|
||||
]
|
||||
};
|
||||
request_param_info('TestFormOneof', 'form3') ->
|
||||
request_param_info('test/form/oneof', 'form3') ->
|
||||
#{
|
||||
source => body,
|
||||
rules => [
|
||||
@ -426,7 +466,7 @@ request_param_info('TestFormOneof', 'form3') ->
|
||||
not_required
|
||||
]
|
||||
};
|
||||
request_param_info('TestFormOneof', 'form4') ->
|
||||
request_param_info('test/form/oneof', 'form4') ->
|
||||
#{
|
||||
source => body,
|
||||
rules => [
|
||||
@ -434,7 +474,7 @@ request_param_info('TestFormOneof', 'form4') ->
|
||||
not_required
|
||||
]
|
||||
};
|
||||
request_param_info('TestFormOneof', 'id') ->
|
||||
request_param_info('test/form/oneof', 'id') ->
|
||||
#{
|
||||
source => body,
|
||||
rules => [
|
||||
@ -442,7 +482,7 @@ request_param_info('TestFormOneof', 'id') ->
|
||||
not_required
|
||||
]
|
||||
};
|
||||
request_param_info('TestFormOneof', 'name') ->
|
||||
request_param_info('test/form/oneof', 'name') ->
|
||||
#{
|
||||
source => body,
|
||||
rules => [
|
||||
@ -450,7 +490,7 @@ request_param_info('TestFormOneof', 'name') ->
|
||||
not_required
|
||||
]
|
||||
};
|
||||
request_param_info('TestHeaderIntegerBooleanStringEnums', 'integer_header') ->
|
||||
request_param_info('test/header/integer/boolean/string/enums', 'integer_header') ->
|
||||
#{
|
||||
source => header,
|
||||
rules => [
|
||||
@ -458,7 +498,7 @@ request_param_info('TestHeaderIntegerBooleanStringEnums', 'integer_header') ->
|
||||
not_required
|
||||
]
|
||||
};
|
||||
request_param_info('TestHeaderIntegerBooleanStringEnums', 'boolean_header') ->
|
||||
request_param_info('test/header/integer/boolean/string/enums', 'boolean_header') ->
|
||||
#{
|
||||
source => header,
|
||||
rules => [
|
||||
@ -466,7 +506,7 @@ request_param_info('TestHeaderIntegerBooleanStringEnums', 'boolean_header') ->
|
||||
not_required
|
||||
]
|
||||
};
|
||||
request_param_info('TestHeaderIntegerBooleanStringEnums', 'string_header') ->
|
||||
request_param_info('test/header/integer/boolean/string/enums', 'string_header') ->
|
||||
#{
|
||||
source => header,
|
||||
rules => [
|
||||
@ -474,7 +514,7 @@ request_param_info('TestHeaderIntegerBooleanStringEnums', 'string_header') ->
|
||||
not_required
|
||||
]
|
||||
};
|
||||
request_param_info('TestHeaderIntegerBooleanStringEnums', 'enum_nonref_string_header') ->
|
||||
request_param_info('test/header/integer/boolean/string/enums', 'enum_nonref_string_header') ->
|
||||
#{
|
||||
source => header,
|
||||
rules => [
|
||||
@ -483,14 +523,14 @@ request_param_info('TestHeaderIntegerBooleanStringEnums', 'enum_nonref_string_he
|
||||
not_required
|
||||
]
|
||||
};
|
||||
request_param_info('TestHeaderIntegerBooleanStringEnums', 'enum_ref_string_header') ->
|
||||
request_param_info('test/header/integer/boolean/string/enums', 'enum_ref_string_header') ->
|
||||
#{
|
||||
source => header,
|
||||
rules => [
|
||||
not_required
|
||||
]
|
||||
};
|
||||
request_param_info('TestsPathString{pathString}Integer{pathInteger}{enumNonrefStringPath}{enumRefStringPath}', 'path_string') ->
|
||||
request_param_info('tests/path/string/{path_string}/integer/{path_integer}/{enum_nonref_string_path}/{enum_ref_string_path}', 'path_string') ->
|
||||
#{
|
||||
source => binding,
|
||||
rules => [
|
||||
@ -498,7 +538,7 @@ request_param_info('TestsPathString{pathString}Integer{pathInteger}{enumNonrefSt
|
||||
required
|
||||
]
|
||||
};
|
||||
request_param_info('TestsPathString{pathString}Integer{pathInteger}{enumNonrefStringPath}{enumRefStringPath}', 'path_integer') ->
|
||||
request_param_info('tests/path/string/{path_string}/integer/{path_integer}/{enum_nonref_string_path}/{enum_ref_string_path}', 'path_integer') ->
|
||||
#{
|
||||
source => binding,
|
||||
rules => [
|
||||
@ -506,7 +546,7 @@ request_param_info('TestsPathString{pathString}Integer{pathInteger}{enumNonrefSt
|
||||
required
|
||||
]
|
||||
};
|
||||
request_param_info('TestsPathString{pathString}Integer{pathInteger}{enumNonrefStringPath}{enumRefStringPath}', 'enum_nonref_string_path') ->
|
||||
request_param_info('tests/path/string/{path_string}/integer/{path_integer}/{enum_nonref_string_path}/{enum_ref_string_path}', 'enum_nonref_string_path') ->
|
||||
#{
|
||||
source => binding,
|
||||
rules => [
|
||||
@ -515,14 +555,14 @@ request_param_info('TestsPathString{pathString}Integer{pathInteger}{enumNonrefSt
|
||||
required
|
||||
]
|
||||
};
|
||||
request_param_info('TestsPathString{pathString}Integer{pathInteger}{enumNonrefStringPath}{enumRefStringPath}', 'enum_ref_string_path') ->
|
||||
request_param_info('tests/path/string/{path_string}/integer/{path_integer}/{enum_nonref_string_path}/{enum_ref_string_path}', 'enum_ref_string_path') ->
|
||||
#{
|
||||
source => binding,
|
||||
rules => [
|
||||
required
|
||||
]
|
||||
};
|
||||
request_param_info('TestEnumRefString', 'enum_nonref_string_query') ->
|
||||
request_param_info('test/enum_ref_string', 'enum_nonref_string_query') ->
|
||||
#{
|
||||
source => qs_val,
|
||||
rules => [
|
||||
@ -531,14 +571,14 @@ request_param_info('TestEnumRefString', 'enum_nonref_string_query') ->
|
||||
not_required
|
||||
]
|
||||
};
|
||||
request_param_info('TestEnumRefString', 'enum_ref_string_query') ->
|
||||
request_param_info('test/enum_ref_string', 'enum_ref_string_query') ->
|
||||
#{
|
||||
source => qs_val,
|
||||
rules => [
|
||||
not_required
|
||||
]
|
||||
};
|
||||
request_param_info('TestQueryDatetimeDateString', 'datetime_query') ->
|
||||
request_param_info('test/query/datetime/date/string', 'datetime_query') ->
|
||||
#{
|
||||
source => qs_val,
|
||||
rules => [
|
||||
@ -546,7 +586,7 @@ request_param_info('TestQueryDatetimeDateString', 'datetime_query') ->
|
||||
not_required
|
||||
]
|
||||
};
|
||||
request_param_info('TestQueryDatetimeDateString', 'date_query') ->
|
||||
request_param_info('test/query/datetime/date/string', 'date_query') ->
|
||||
#{
|
||||
source => qs_val,
|
||||
rules => [
|
||||
@ -554,7 +594,7 @@ request_param_info('TestQueryDatetimeDateString', 'date_query') ->
|
||||
not_required
|
||||
]
|
||||
};
|
||||
request_param_info('TestQueryDatetimeDateString', 'string_query') ->
|
||||
request_param_info('test/query/datetime/date/string', 'string_query') ->
|
||||
#{
|
||||
source => qs_val,
|
||||
rules => [
|
||||
@ -562,7 +602,7 @@ request_param_info('TestQueryDatetimeDateString', 'string_query') ->
|
||||
not_required
|
||||
]
|
||||
};
|
||||
request_param_info('TestQueryIntegerBooleanString', 'integer_query') ->
|
||||
request_param_info('test/query/integer/boolean/string', 'integer_query') ->
|
||||
#{
|
||||
source => qs_val,
|
||||
rules => [
|
||||
@ -570,7 +610,7 @@ request_param_info('TestQueryIntegerBooleanString', 'integer_query') ->
|
||||
not_required
|
||||
]
|
||||
};
|
||||
request_param_info('TestQueryIntegerBooleanString', 'boolean_query') ->
|
||||
request_param_info('test/query/integer/boolean/string', 'boolean_query') ->
|
||||
#{
|
||||
source => qs_val,
|
||||
rules => [
|
||||
@ -578,7 +618,7 @@ request_param_info('TestQueryIntegerBooleanString', 'boolean_query') ->
|
||||
not_required
|
||||
]
|
||||
};
|
||||
request_param_info('TestQueryIntegerBooleanString', 'string_query') ->
|
||||
request_param_info('test/query/integer/boolean/string', 'string_query') ->
|
||||
#{
|
||||
source => qs_val,
|
||||
rules => [
|
||||
@ -586,49 +626,49 @@ request_param_info('TestQueryIntegerBooleanString', 'string_query') ->
|
||||
not_required
|
||||
]
|
||||
};
|
||||
request_param_info('TestQueryStyleDeepObjectExplodeTrueObject', 'query_object') ->
|
||||
request_param_info('test/query/style_deepObject/explode_true/object', 'query_object') ->
|
||||
#{
|
||||
source => qs_val,
|
||||
rules => [
|
||||
not_required
|
||||
]
|
||||
};
|
||||
request_param_info('TestQueryStyleDeepObjectExplodeTrueObjectAllOf', 'query_object') ->
|
||||
request_param_info('test/query/style_deepObject/explode_true/object/allOf', 'query_object') ->
|
||||
#{
|
||||
source => qs_val,
|
||||
rules => [
|
||||
not_required
|
||||
]
|
||||
};
|
||||
request_param_info('TestQueryStyleFormExplodeFalseArrayInteger', 'query_object') ->
|
||||
request_param_info('test/query/style_form/explode_false/array_integer', 'query_object') ->
|
||||
#{
|
||||
source => qs_val,
|
||||
rules => [
|
||||
not_required
|
||||
]
|
||||
};
|
||||
request_param_info('TestQueryStyleFormExplodeFalseArrayString', 'query_object') ->
|
||||
request_param_info('test/query/style_form/explode_false/array_string', 'query_object') ->
|
||||
#{
|
||||
source => qs_val,
|
||||
rules => [
|
||||
not_required
|
||||
]
|
||||
};
|
||||
request_param_info('TestQueryStyleFormExplodeTrueArrayString', 'query_object') ->
|
||||
request_param_info('test/query/style_form/explode_true/array_string', 'query_object') ->
|
||||
#{
|
||||
source => qs_val,
|
||||
rules => [
|
||||
not_required
|
||||
]
|
||||
};
|
||||
request_param_info('TestQueryStyleFormExplodeTrueObject', 'query_object') ->
|
||||
request_param_info('test/query/style_form/explode_true/object', 'query_object') ->
|
||||
#{
|
||||
source => qs_val,
|
||||
rules => [
|
||||
not_required
|
||||
]
|
||||
};
|
||||
request_param_info('TestQueryStyleFormExplodeTrueObjectAllOf', 'query_object') ->
|
||||
request_param_info('test/query/style_form/explode_true/object/allOf', 'query_object') ->
|
||||
#{
|
||||
source => qs_val,
|
||||
rules => [
|
||||
@ -668,8 +708,6 @@ populate_request_param(OperationID, ReqParamName, Req0, ValidatorState) ->
|
||||
end
|
||||
end.
|
||||
|
||||
-include_lib("kernel/include/logger.hrl").
|
||||
|
||||
validate_response_body(list, ReturnBaseType, Body, ValidatorState) ->
|
||||
[
|
||||
validate(schema, Item, ReturnBaseType, ValidatorState)
|
||||
@ -760,8 +798,15 @@ validate(Rule = {pattern, Pattern}, Value, ReqParamName, _) ->
|
||||
{match, _} -> ok;
|
||||
_ -> validation_error(Rule, ReqParamName, Value)
|
||||
end;
|
||||
validate(Rule = schema, Value, ReqParamName, ValidatorState) ->
|
||||
validate(schema, Value, ReqParamName, ValidatorState) ->
|
||||
Definition = iolist_to_binary(["#/components/schemas/", atom_to_binary(ReqParamName, utf8)]),
|
||||
validate({schema, object, Definition}, Value, ReqParamName, ValidatorState);
|
||||
validate({schema, list, Definition}, Value, ReqParamName, ValidatorState) ->
|
||||
lists:foreach(
|
||||
fun(Item) ->
|
||||
validate({schema, object, Definition}, Item, ReqParamName, ValidatorState)
|
||||
end, Value);
|
||||
validate(Rule = {schema, object, Definition}, Value, ReqParamName, ValidatorState) ->
|
||||
try
|
||||
_ = validate_with_schema(Value, Definition, ValidatorState),
|
||||
ok
|
||||
|
@ -2,11 +2,13 @@
|
||||
-moduledoc """
|
||||
Exposes the following operation IDs:
|
||||
|
||||
- `POST` to `/auth/http/basic`, OperationId: `TestAuthHttpBasic`:
|
||||
- `POST` to `/auth/http/basic`, OperationId: `test/auth/http/basic`:
|
||||
To test HTTP basic authentication.
|
||||
To test HTTP basic authentication
|
||||
|
||||
- `POST` to `/auth/http/bearer`, OperationId: `TestAuthHttpBearer`:
|
||||
- `POST` to `/auth/http/bearer`, OperationId: `test/auth/http/bearer`:
|
||||
To test HTTP bearer authentication.
|
||||
To test HTTP bearer authentication
|
||||
|
||||
""".
|
||||
|
||||
@ -26,8 +28,17 @@ To test HTTP bearer authentication.
|
||||
|
||||
-ignore_xref([handle_type_accepted/2, handle_type_provided/2]).
|
||||
|
||||
-export_type([class/0, operation_id/0]).
|
||||
|
||||
-type class() :: 'auth'.
|
||||
|
||||
-type operation_id() ::
|
||||
'test/auth/http/basic' %% To test HTTP basic authentication
|
||||
| 'test/auth/http/bearer'. %% To test HTTP bearer authentication
|
||||
|
||||
|
||||
-record(state,
|
||||
{operation_id :: openapi_api:operation_id(),
|
||||
{operation_id :: operation_id(),
|
||||
accept_callback :: openapi_logic_handler:accept_callback(),
|
||||
provide_callback :: openapi_logic_handler:provide_callback(),
|
||||
api_key_handler :: openapi_logic_handler:api_key_callback(),
|
||||
@ -51,9 +62,9 @@ init(Req, {Operations, Module}) ->
|
||||
|
||||
-spec allowed_methods(cowboy_req:req(), state()) ->
|
||||
{[binary()], cowboy_req:req(), state()}.
|
||||
allowed_methods(Req, #state{operation_id = 'TestAuthHttpBasic'} = State) ->
|
||||
allowed_methods(Req, #state{operation_id = 'test/auth/http/basic'} = State) ->
|
||||
{[<<"POST">>], Req, State};
|
||||
allowed_methods(Req, #state{operation_id = 'TestAuthHttpBearer'} = State) ->
|
||||
allowed_methods(Req, #state{operation_id = 'test/auth/http/bearer'} = State) ->
|
||||
{[<<"POST">>], Req, State};
|
||||
allowed_methods(Req, State) ->
|
||||
{[], Req, State}.
|
||||
@ -61,7 +72,7 @@ allowed_methods(Req, State) ->
|
||||
-spec is_authorized(cowboy_req:req(), state()) ->
|
||||
{true | {false, iodata()}, cowboy_req:req(), state()}.
|
||||
is_authorized(Req0,
|
||||
#state{operation_id = 'TestAuthHttpBasic' = OperationID,
|
||||
#state{operation_id = 'test/auth/http/basic' = OperationID,
|
||||
api_key_handler = Handler} = State) ->
|
||||
case openapi_auth:authorize_api_key(Handler, OperationID, header, "authorization", Req0) of
|
||||
{true, Context, Req} ->
|
||||
@ -70,7 +81,7 @@ is_authorized(Req0,
|
||||
{{false, AuthHeader}, Req, State}
|
||||
end;
|
||||
is_authorized(Req0,
|
||||
#state{operation_id = 'TestAuthHttpBearer' = OperationID,
|
||||
#state{operation_id = 'test/auth/http/bearer' = OperationID,
|
||||
api_key_handler = Handler} = State) ->
|
||||
case openapi_auth:authorize_api_key(Handler, OperationID, header, "authorization", Req0) of
|
||||
{true, Context, Req} ->
|
||||
@ -83,29 +94,29 @@ is_authorized(Req, State) ->
|
||||
|
||||
-spec content_types_accepted(cowboy_req:req(), state()) ->
|
||||
{[{binary(), atom()}], cowboy_req:req(), state()}.
|
||||
content_types_accepted(Req, #state{operation_id = 'TestAuthHttpBasic'} = State) ->
|
||||
content_types_accepted(Req, #state{operation_id = 'test/auth/http/basic'} = State) ->
|
||||
{[], Req, State};
|
||||
content_types_accepted(Req, #state{operation_id = 'TestAuthHttpBearer'} = State) ->
|
||||
content_types_accepted(Req, #state{operation_id = 'test/auth/http/bearer'} = State) ->
|
||||
{[], Req, State};
|
||||
content_types_accepted(Req, State) ->
|
||||
{[], Req, State}.
|
||||
|
||||
-spec valid_content_headers(cowboy_req:req(), state()) ->
|
||||
{boolean(), cowboy_req:req(), state()}.
|
||||
valid_content_headers(Req, #state{operation_id = 'TestAuthHttpBasic'} = State) ->
|
||||
valid_content_headers(Req, #state{operation_id = 'test/auth/http/basic'} = State) ->
|
||||
{true, Req, State};
|
||||
valid_content_headers(Req, #state{operation_id = 'TestAuthHttpBearer'} = State) ->
|
||||
valid_content_headers(Req, #state{operation_id = 'test/auth/http/bearer'} = State) ->
|
||||
{true, Req, State};
|
||||
valid_content_headers(Req, State) ->
|
||||
{false, Req, State}.
|
||||
|
||||
-spec content_types_provided(cowboy_req:req(), state()) ->
|
||||
{[{binary(), atom()}], cowboy_req:req(), state()}.
|
||||
content_types_provided(Req, #state{operation_id = 'TestAuthHttpBasic'} = State) ->
|
||||
content_types_provided(Req, #state{operation_id = 'test/auth/http/basic'} = State) ->
|
||||
{[
|
||||
{<<"text/plain">>, handle_type_provided}
|
||||
], Req, State};
|
||||
content_types_provided(Req, #state{operation_id = 'TestAuthHttpBearer'} = State) ->
|
||||
content_types_provided(Req, #state{operation_id = 'test/auth/http/bearer'} = State) ->
|
||||
{[
|
||||
{<<"text/plain">>, handle_type_provided}
|
||||
], Req, State};
|
||||
@ -115,8 +126,8 @@ content_types_provided(Req, State) ->
|
||||
-spec delete_resource(cowboy_req:req(), state()) ->
|
||||
{boolean(), cowboy_req:req(), state()}.
|
||||
delete_resource(Req, State) ->
|
||||
{Res, Req1, State} = handle_type_accepted(Req, State),
|
||||
{true =:= Res, Req1, State}.
|
||||
{Res, Req1, State1} = handle_type_accepted(Req, State),
|
||||
{true =:= Res, Req1, State1}.
|
||||
|
||||
-spec handle_type_accepted(cowboy_req:req(), state()) ->
|
||||
{ openapi_logic_handler:accept_callback_return(), cowboy_req:req(), state()}.
|
||||
|
@ -2,35 +2,45 @@
|
||||
-moduledoc """
|
||||
Exposes the following operation IDs:
|
||||
|
||||
- `POST` to `/binary/gif`, OperationId: `TestBinaryGif`:
|
||||
- `POST` to `/binary/gif`, OperationId: `test/binary/gif`:
|
||||
Test binary (gif) response body.
|
||||
Test binary (gif) response body
|
||||
|
||||
- `POST` to `/body/application/octetstream/binary`, OperationId: `TestBodyApplicationOctetstreamBinary`:
|
||||
- `POST` to `/body/application/octetstream/binary`, OperationId: `test/body/application/octetstream/binary`:
|
||||
Test body parameter(s).
|
||||
Test body parameter(s)
|
||||
|
||||
- `POST` to `/body/application/octetstream/array_of_binary`, OperationId: `TestBodyMultipartFormdataArrayOfBinary`:
|
||||
- `POST` to `/body/application/octetstream/array_of_binary`, OperationId: `test/body/multipart/formdata/array_of_binary`:
|
||||
Test array of binary in multipart mime.
|
||||
Test array of binary in multipart mime
|
||||
|
||||
- `POST` to `/body/application/octetstream/single_binary`, OperationId: `TestBodyMultipartFormdataSingleBinary`:
|
||||
- `POST` to `/body/application/octetstream/single_binary`, OperationId: `test/body/multipart/formdata/single_binary`:
|
||||
Test single binary in multipart mime.
|
||||
Test single binary in multipart mime
|
||||
|
||||
- `POST` to `/echo/body/allOf/Pet`, OperationId: `TestEchoBodyAllOfPet`:
|
||||
- `POST` to `/echo/body/allOf/Pet`, OperationId: `test/echo/body/allOf/Pet`:
|
||||
Test body parameter(s).
|
||||
Test body parameter(s)
|
||||
|
||||
- `POST` to `/echo/body/FreeFormObject/response_string`, OperationId: `TestEchoBodyFreeFormObjectResponseString`:
|
||||
- `POST` to `/echo/body/FreeFormObject/response_string`, OperationId: `test/echo/body/FreeFormObject/response_string`:
|
||||
Test free form object.
|
||||
Test free form object
|
||||
|
||||
- `POST` to `/echo/body/Pet`, OperationId: `TestEchoBodyPet`:
|
||||
- `POST` to `/echo/body/Pet`, OperationId: `test/echo/body/Pet`:
|
||||
Test body parameter(s).
|
||||
Test body parameter(s)
|
||||
|
||||
- `POST` to `/echo/body/Pet/response_string`, OperationId: `TestEchoBodyPetResponseString`:
|
||||
- `POST` to `/echo/body/Pet/response_string`, OperationId: `test/echo/body/Pet/response_string`:
|
||||
Test empty response body.
|
||||
Test empty response body
|
||||
|
||||
- `POST` to `/echo/body/string_enum`, OperationId: `TestEchoBodyStringEnum`:
|
||||
- `POST` to `/echo/body/string_enum`, OperationId: `test/echo/body/string_enum`:
|
||||
Test string enum response body.
|
||||
Test string enum response body
|
||||
|
||||
- `POST` to `/echo/body/Tag/response_string`, OperationId: `TestEchoBodyTagResponseString`:
|
||||
- `POST` to `/echo/body/Tag/response_string`, OperationId: `test/echo/body/Tag/response_string`:
|
||||
Test empty json (request body).
|
||||
Test empty json (request body)
|
||||
|
||||
""".
|
||||
|
||||
@ -50,8 +60,25 @@ Test empty json (request body).
|
||||
|
||||
-ignore_xref([handle_type_accepted/2, handle_type_provided/2]).
|
||||
|
||||
-export_type([class/0, operation_id/0]).
|
||||
|
||||
-type class() :: 'body'.
|
||||
|
||||
-type operation_id() ::
|
||||
'test/binary/gif' %% Test binary (gif) response body
|
||||
| 'test/body/application/octetstream/binary' %% Test body parameter(s)
|
||||
| 'test/body/multipart/formdata/array_of_binary' %% Test array of binary in multipart mime
|
||||
| 'test/body/multipart/formdata/single_binary' %% Test single binary in multipart mime
|
||||
| 'test/echo/body/allOf/Pet' %% Test body parameter(s)
|
||||
| 'test/echo/body/FreeFormObject/response_string' %% Test free form object
|
||||
| 'test/echo/body/Pet' %% Test body parameter(s)
|
||||
| 'test/echo/body/Pet/response_string' %% Test empty response body
|
||||
| 'test/echo/body/string_enum' %% Test string enum response body
|
||||
| 'test/echo/body/Tag/response_string'. %% Test empty json (request body)
|
||||
|
||||
|
||||
-record(state,
|
||||
{operation_id :: openapi_api:operation_id(),
|
||||
{operation_id :: operation_id(),
|
||||
accept_callback :: openapi_logic_handler:accept_callback(),
|
||||
provide_callback :: openapi_logic_handler:provide_callback(),
|
||||
api_key_handler :: openapi_logic_handler:api_key_callback(),
|
||||
@ -75,25 +102,25 @@ init(Req, {Operations, Module}) ->
|
||||
|
||||
-spec allowed_methods(cowboy_req:req(), state()) ->
|
||||
{[binary()], cowboy_req:req(), state()}.
|
||||
allowed_methods(Req, #state{operation_id = 'TestBinaryGif'} = State) ->
|
||||
allowed_methods(Req, #state{operation_id = 'test/binary/gif'} = State) ->
|
||||
{[<<"POST">>], Req, State};
|
||||
allowed_methods(Req, #state{operation_id = 'TestBodyApplicationOctetstreamBinary'} = State) ->
|
||||
allowed_methods(Req, #state{operation_id = 'test/body/application/octetstream/binary'} = State) ->
|
||||
{[<<"POST">>], Req, State};
|
||||
allowed_methods(Req, #state{operation_id = 'TestBodyMultipartFormdataArrayOfBinary'} = State) ->
|
||||
allowed_methods(Req, #state{operation_id = 'test/body/multipart/formdata/array_of_binary'} = State) ->
|
||||
{[<<"POST">>], Req, State};
|
||||
allowed_methods(Req, #state{operation_id = 'TestBodyMultipartFormdataSingleBinary'} = State) ->
|
||||
allowed_methods(Req, #state{operation_id = 'test/body/multipart/formdata/single_binary'} = State) ->
|
||||
{[<<"POST">>], Req, State};
|
||||
allowed_methods(Req, #state{operation_id = 'TestEchoBodyAllOfPet'} = State) ->
|
||||
allowed_methods(Req, #state{operation_id = 'test/echo/body/allOf/Pet'} = State) ->
|
||||
{[<<"POST">>], Req, State};
|
||||
allowed_methods(Req, #state{operation_id = 'TestEchoBodyFreeFormObjectResponseString'} = State) ->
|
||||
allowed_methods(Req, #state{operation_id = 'test/echo/body/FreeFormObject/response_string'} = State) ->
|
||||
{[<<"POST">>], Req, State};
|
||||
allowed_methods(Req, #state{operation_id = 'TestEchoBodyPet'} = State) ->
|
||||
allowed_methods(Req, #state{operation_id = 'test/echo/body/Pet'} = State) ->
|
||||
{[<<"POST">>], Req, State};
|
||||
allowed_methods(Req, #state{operation_id = 'TestEchoBodyPetResponseString'} = State) ->
|
||||
allowed_methods(Req, #state{operation_id = 'test/echo/body/Pet/response_string'} = State) ->
|
||||
{[<<"POST">>], Req, State};
|
||||
allowed_methods(Req, #state{operation_id = 'TestEchoBodyStringEnum'} = State) ->
|
||||
allowed_methods(Req, #state{operation_id = 'test/echo/body/string_enum'} = State) ->
|
||||
{[<<"POST">>], Req, State};
|
||||
allowed_methods(Req, #state{operation_id = 'TestEchoBodyTagResponseString'} = State) ->
|
||||
allowed_methods(Req, #state{operation_id = 'test/echo/body/Tag/response_string'} = State) ->
|
||||
{[<<"POST">>], Req, State};
|
||||
allowed_methods(Req, State) ->
|
||||
{[], Req, State}.
|
||||
@ -105,41 +132,41 @@ is_authorized(Req, State) ->
|
||||
|
||||
-spec content_types_accepted(cowboy_req:req(), state()) ->
|
||||
{[{binary(), atom()}], cowboy_req:req(), state()}.
|
||||
content_types_accepted(Req, #state{operation_id = 'TestBinaryGif'} = State) ->
|
||||
content_types_accepted(Req, #state{operation_id = 'test/binary/gif'} = State) ->
|
||||
{[], Req, State};
|
||||
content_types_accepted(Req, #state{operation_id = 'TestBodyApplicationOctetstreamBinary'} = State) ->
|
||||
content_types_accepted(Req, #state{operation_id = 'test/body/application/octetstream/binary'} = State) ->
|
||||
{[
|
||||
{<<"application/octet-stream">>, handle_type_accepted}
|
||||
], Req, State};
|
||||
content_types_accepted(Req, #state{operation_id = 'TestBodyMultipartFormdataArrayOfBinary'} = State) ->
|
||||
content_types_accepted(Req, #state{operation_id = 'test/body/multipart/formdata/array_of_binary'} = State) ->
|
||||
{[
|
||||
{<<"multipart/form-data">>, handle_type_accepted}
|
||||
], Req, State};
|
||||
content_types_accepted(Req, #state{operation_id = 'TestBodyMultipartFormdataSingleBinary'} = State) ->
|
||||
content_types_accepted(Req, #state{operation_id = 'test/body/multipart/formdata/single_binary'} = State) ->
|
||||
{[
|
||||
{<<"multipart/form-data">>, handle_type_accepted}
|
||||
], Req, State};
|
||||
content_types_accepted(Req, #state{operation_id = 'TestEchoBodyAllOfPet'} = State) ->
|
||||
content_types_accepted(Req, #state{operation_id = 'test/echo/body/allOf/Pet'} = State) ->
|
||||
{[
|
||||
{<<"application/json">>, handle_type_accepted}
|
||||
], Req, State};
|
||||
content_types_accepted(Req, #state{operation_id = 'TestEchoBodyFreeFormObjectResponseString'} = State) ->
|
||||
content_types_accepted(Req, #state{operation_id = 'test/echo/body/FreeFormObject/response_string'} = State) ->
|
||||
{[
|
||||
{<<"application/json">>, handle_type_accepted}
|
||||
], Req, State};
|
||||
content_types_accepted(Req, #state{operation_id = 'TestEchoBodyPet'} = State) ->
|
||||
content_types_accepted(Req, #state{operation_id = 'test/echo/body/Pet'} = State) ->
|
||||
{[
|
||||
{<<"application/json">>, handle_type_accepted}
|
||||
], Req, State};
|
||||
content_types_accepted(Req, #state{operation_id = 'TestEchoBodyPetResponseString'} = State) ->
|
||||
content_types_accepted(Req, #state{operation_id = 'test/echo/body/Pet/response_string'} = State) ->
|
||||
{[
|
||||
{<<"application/json">>, handle_type_accepted}
|
||||
], Req, State};
|
||||
content_types_accepted(Req, #state{operation_id = 'TestEchoBodyStringEnum'} = State) ->
|
||||
content_types_accepted(Req, #state{operation_id = 'test/echo/body/string_enum'} = State) ->
|
||||
{[
|
||||
{<<"application/json">>, handle_type_accepted}
|
||||
], Req, State};
|
||||
content_types_accepted(Req, #state{operation_id = 'TestEchoBodyTagResponseString'} = State) ->
|
||||
content_types_accepted(Req, #state{operation_id = 'test/echo/body/Tag/response_string'} = State) ->
|
||||
{[
|
||||
{<<"application/json">>, handle_type_accepted}
|
||||
], Req, State};
|
||||
@ -148,68 +175,68 @@ content_types_accepted(Req, State) ->
|
||||
|
||||
-spec valid_content_headers(cowboy_req:req(), state()) ->
|
||||
{boolean(), cowboy_req:req(), state()}.
|
||||
valid_content_headers(Req, #state{operation_id = 'TestBinaryGif'} = State) ->
|
||||
valid_content_headers(Req, #state{operation_id = 'test/binary/gif'} = State) ->
|
||||
{true, Req, State};
|
||||
valid_content_headers(Req, #state{operation_id = 'TestBodyApplicationOctetstreamBinary'} = State) ->
|
||||
valid_content_headers(Req, #state{operation_id = 'test/body/application/octetstream/binary'} = State) ->
|
||||
{true, Req, State};
|
||||
valid_content_headers(Req, #state{operation_id = 'TestBodyMultipartFormdataArrayOfBinary'} = State) ->
|
||||
valid_content_headers(Req, #state{operation_id = 'test/body/multipart/formdata/array_of_binary'} = State) ->
|
||||
{true, Req, State};
|
||||
valid_content_headers(Req, #state{operation_id = 'TestBodyMultipartFormdataSingleBinary'} = State) ->
|
||||
valid_content_headers(Req, #state{operation_id = 'test/body/multipart/formdata/single_binary'} = State) ->
|
||||
{true, Req, State};
|
||||
valid_content_headers(Req, #state{operation_id = 'TestEchoBodyAllOfPet'} = State) ->
|
||||
valid_content_headers(Req, #state{operation_id = 'test/echo/body/allOf/Pet'} = State) ->
|
||||
{true, Req, State};
|
||||
valid_content_headers(Req, #state{operation_id = 'TestEchoBodyFreeFormObjectResponseString'} = State) ->
|
||||
valid_content_headers(Req, #state{operation_id = 'test/echo/body/FreeFormObject/response_string'} = State) ->
|
||||
{true, Req, State};
|
||||
valid_content_headers(Req, #state{operation_id = 'TestEchoBodyPet'} = State) ->
|
||||
valid_content_headers(Req, #state{operation_id = 'test/echo/body/Pet'} = State) ->
|
||||
{true, Req, State};
|
||||
valid_content_headers(Req, #state{operation_id = 'TestEchoBodyPetResponseString'} = State) ->
|
||||
valid_content_headers(Req, #state{operation_id = 'test/echo/body/Pet/response_string'} = State) ->
|
||||
{true, Req, State};
|
||||
valid_content_headers(Req, #state{operation_id = 'TestEchoBodyStringEnum'} = State) ->
|
||||
valid_content_headers(Req, #state{operation_id = 'test/echo/body/string_enum'} = State) ->
|
||||
{true, Req, State};
|
||||
valid_content_headers(Req, #state{operation_id = 'TestEchoBodyTagResponseString'} = State) ->
|
||||
valid_content_headers(Req, #state{operation_id = 'test/echo/body/Tag/response_string'} = State) ->
|
||||
{true, Req, State};
|
||||
valid_content_headers(Req, State) ->
|
||||
{false, Req, State}.
|
||||
|
||||
-spec content_types_provided(cowboy_req:req(), state()) ->
|
||||
{[{binary(), atom()}], cowboy_req:req(), state()}.
|
||||
content_types_provided(Req, #state{operation_id = 'TestBinaryGif'} = State) ->
|
||||
content_types_provided(Req, #state{operation_id = 'test/binary/gif'} = State) ->
|
||||
{[
|
||||
{<<"image/gif">>, handle_type_provided}
|
||||
], Req, State};
|
||||
content_types_provided(Req, #state{operation_id = 'TestBodyApplicationOctetstreamBinary'} = State) ->
|
||||
content_types_provided(Req, #state{operation_id = 'test/body/application/octetstream/binary'} = State) ->
|
||||
{[
|
||||
{<<"text/plain">>, handle_type_provided}
|
||||
], Req, State};
|
||||
content_types_provided(Req, #state{operation_id = 'TestBodyMultipartFormdataArrayOfBinary'} = State) ->
|
||||
content_types_provided(Req, #state{operation_id = 'test/body/multipart/formdata/array_of_binary'} = State) ->
|
||||
{[
|
||||
{<<"text/plain">>, handle_type_provided}
|
||||
], Req, State};
|
||||
content_types_provided(Req, #state{operation_id = 'TestBodyMultipartFormdataSingleBinary'} = State) ->
|
||||
content_types_provided(Req, #state{operation_id = 'test/body/multipart/formdata/single_binary'} = State) ->
|
||||
{[
|
||||
{<<"text/plain">>, handle_type_provided}
|
||||
], Req, State};
|
||||
content_types_provided(Req, #state{operation_id = 'TestEchoBodyAllOfPet'} = State) ->
|
||||
content_types_provided(Req, #state{operation_id = 'test/echo/body/allOf/Pet'} = State) ->
|
||||
{[
|
||||
{<<"application/json">>, handle_type_provided}
|
||||
], Req, State};
|
||||
content_types_provided(Req, #state{operation_id = 'TestEchoBodyFreeFormObjectResponseString'} = State) ->
|
||||
content_types_provided(Req, #state{operation_id = 'test/echo/body/FreeFormObject/response_string'} = State) ->
|
||||
{[
|
||||
{<<"text/plain">>, handle_type_provided}
|
||||
], Req, State};
|
||||
content_types_provided(Req, #state{operation_id = 'TestEchoBodyPet'} = State) ->
|
||||
content_types_provided(Req, #state{operation_id = 'test/echo/body/Pet'} = State) ->
|
||||
{[
|
||||
{<<"application/json">>, handle_type_provided}
|
||||
], Req, State};
|
||||
content_types_provided(Req, #state{operation_id = 'TestEchoBodyPetResponseString'} = State) ->
|
||||
content_types_provided(Req, #state{operation_id = 'test/echo/body/Pet/response_string'} = State) ->
|
||||
{[
|
||||
{<<"text/plain">>, handle_type_provided}
|
||||
], Req, State};
|
||||
content_types_provided(Req, #state{operation_id = 'TestEchoBodyStringEnum'} = State) ->
|
||||
content_types_provided(Req, #state{operation_id = 'test/echo/body/string_enum'} = State) ->
|
||||
{[
|
||||
{<<"application/json">>, handle_type_provided}
|
||||
], Req, State};
|
||||
content_types_provided(Req, #state{operation_id = 'TestEchoBodyTagResponseString'} = State) ->
|
||||
content_types_provided(Req, #state{operation_id = 'test/echo/body/Tag/response_string'} = State) ->
|
||||
{[
|
||||
{<<"text/plain">>, handle_type_provided}
|
||||
], Req, State};
|
||||
@ -219,8 +246,8 @@ content_types_provided(Req, State) ->
|
||||
-spec delete_resource(cowboy_req:req(), state()) ->
|
||||
{boolean(), cowboy_req:req(), state()}.
|
||||
delete_resource(Req, State) ->
|
||||
{Res, Req1, State} = handle_type_accepted(Req, State),
|
||||
{true =:= Res, Req1, State}.
|
||||
{Res, Req1, State1} = handle_type_accepted(Req, State),
|
||||
{true =:= Res, Req1, State1}.
|
||||
|
||||
-spec handle_type_accepted(cowboy_req:req(), state()) ->
|
||||
{ openapi_logic_handler:accept_callback_return(), cowboy_req:req(), state()}.
|
||||
|
@ -2,14 +2,17 @@
|
||||
-moduledoc """
|
||||
Exposes the following operation IDs:
|
||||
|
||||
- `POST` to `/form/integer/boolean/string`, OperationId: `TestFormIntegerBooleanString`:
|
||||
- `POST` to `/form/integer/boolean/string`, OperationId: `test/form/integer/boolean/string`:
|
||||
Test form parameter(s).
|
||||
Test form parameter(s)
|
||||
|
||||
- `POST` to `/form/object/multipart`, OperationId: `TestFormObjectMultipart`:
|
||||
- `POST` to `/form/object/multipart`, OperationId: `test/form/object/multipart`:
|
||||
Test form parameter(s) for multipart schema.
|
||||
Test form parameter(s) for multipart schema
|
||||
|
||||
- `POST` to `/form/oneof`, OperationId: `TestFormOneof`:
|
||||
- `POST` to `/form/oneof`, OperationId: `test/form/oneof`:
|
||||
Test form parameter(s) for oneOf schema.
|
||||
Test form parameter(s) for oneOf schema
|
||||
|
||||
""".
|
||||
|
||||
@ -29,8 +32,18 @@ Test form parameter(s) for oneOf schema.
|
||||
|
||||
-ignore_xref([handle_type_accepted/2, handle_type_provided/2]).
|
||||
|
||||
-export_type([class/0, operation_id/0]).
|
||||
|
||||
-type class() :: 'form'.
|
||||
|
||||
-type operation_id() ::
|
||||
'test/form/integer/boolean/string' %% Test form parameter(s)
|
||||
| 'test/form/object/multipart' %% Test form parameter(s) for multipart schema
|
||||
| 'test/form/oneof'. %% Test form parameter(s) for oneOf schema
|
||||
|
||||
|
||||
-record(state,
|
||||
{operation_id :: openapi_api:operation_id(),
|
||||
{operation_id :: operation_id(),
|
||||
accept_callback :: openapi_logic_handler:accept_callback(),
|
||||
provide_callback :: openapi_logic_handler:provide_callback(),
|
||||
api_key_handler :: openapi_logic_handler:api_key_callback(),
|
||||
@ -54,11 +67,11 @@ init(Req, {Operations, Module}) ->
|
||||
|
||||
-spec allowed_methods(cowboy_req:req(), state()) ->
|
||||
{[binary()], cowboy_req:req(), state()}.
|
||||
allowed_methods(Req, #state{operation_id = 'TestFormIntegerBooleanString'} = State) ->
|
||||
allowed_methods(Req, #state{operation_id = 'test/form/integer/boolean/string'} = State) ->
|
||||
{[<<"POST">>], Req, State};
|
||||
allowed_methods(Req, #state{operation_id = 'TestFormObjectMultipart'} = State) ->
|
||||
allowed_methods(Req, #state{operation_id = 'test/form/object/multipart'} = State) ->
|
||||
{[<<"POST">>], Req, State};
|
||||
allowed_methods(Req, #state{operation_id = 'TestFormOneof'} = State) ->
|
||||
allowed_methods(Req, #state{operation_id = 'test/form/oneof'} = State) ->
|
||||
{[<<"POST">>], Req, State};
|
||||
allowed_methods(Req, State) ->
|
||||
{[], Req, State}.
|
||||
@ -70,15 +83,15 @@ is_authorized(Req, State) ->
|
||||
|
||||
-spec content_types_accepted(cowboy_req:req(), state()) ->
|
||||
{[{binary(), atom()}], cowboy_req:req(), state()}.
|
||||
content_types_accepted(Req, #state{operation_id = 'TestFormIntegerBooleanString'} = State) ->
|
||||
content_types_accepted(Req, #state{operation_id = 'test/form/integer/boolean/string'} = State) ->
|
||||
{[
|
||||
{<<"application/x-www-form-urlencoded">>, handle_type_accepted}
|
||||
], Req, State};
|
||||
content_types_accepted(Req, #state{operation_id = 'TestFormObjectMultipart'} = State) ->
|
||||
content_types_accepted(Req, #state{operation_id = 'test/form/object/multipart'} = State) ->
|
||||
{[
|
||||
{<<"multipart/form-data">>, handle_type_accepted}
|
||||
], Req, State};
|
||||
content_types_accepted(Req, #state{operation_id = 'TestFormOneof'} = State) ->
|
||||
content_types_accepted(Req, #state{operation_id = 'test/form/oneof'} = State) ->
|
||||
{[
|
||||
{<<"application/x-www-form-urlencoded">>, handle_type_accepted}
|
||||
], Req, State};
|
||||
@ -87,26 +100,26 @@ content_types_accepted(Req, State) ->
|
||||
|
||||
-spec valid_content_headers(cowboy_req:req(), state()) ->
|
||||
{boolean(), cowboy_req:req(), state()}.
|
||||
valid_content_headers(Req, #state{operation_id = 'TestFormIntegerBooleanString'} = State) ->
|
||||
valid_content_headers(Req, #state{operation_id = 'test/form/integer/boolean/string'} = State) ->
|
||||
{true, Req, State};
|
||||
valid_content_headers(Req, #state{operation_id = 'TestFormObjectMultipart'} = State) ->
|
||||
valid_content_headers(Req, #state{operation_id = 'test/form/object/multipart'} = State) ->
|
||||
{true, Req, State};
|
||||
valid_content_headers(Req, #state{operation_id = 'TestFormOneof'} = State) ->
|
||||
valid_content_headers(Req, #state{operation_id = 'test/form/oneof'} = State) ->
|
||||
{true, Req, State};
|
||||
valid_content_headers(Req, State) ->
|
||||
{false, Req, State}.
|
||||
|
||||
-spec content_types_provided(cowboy_req:req(), state()) ->
|
||||
{[{binary(), atom()}], cowboy_req:req(), state()}.
|
||||
content_types_provided(Req, #state{operation_id = 'TestFormIntegerBooleanString'} = State) ->
|
||||
content_types_provided(Req, #state{operation_id = 'test/form/integer/boolean/string'} = State) ->
|
||||
{[
|
||||
{<<"text/plain">>, handle_type_provided}
|
||||
], Req, State};
|
||||
content_types_provided(Req, #state{operation_id = 'TestFormObjectMultipart'} = State) ->
|
||||
content_types_provided(Req, #state{operation_id = 'test/form/object/multipart'} = State) ->
|
||||
{[
|
||||
{<<"text/plain">>, handle_type_provided}
|
||||
], Req, State};
|
||||
content_types_provided(Req, #state{operation_id = 'TestFormOneof'} = State) ->
|
||||
content_types_provided(Req, #state{operation_id = 'test/form/oneof'} = State) ->
|
||||
{[
|
||||
{<<"text/plain">>, handle_type_provided}
|
||||
], Req, State};
|
||||
@ -116,8 +129,8 @@ content_types_provided(Req, State) ->
|
||||
-spec delete_resource(cowboy_req:req(), state()) ->
|
||||
{boolean(), cowboy_req:req(), state()}.
|
||||
delete_resource(Req, State) ->
|
||||
{Res, Req1, State} = handle_type_accepted(Req, State),
|
||||
{true =:= Res, Req1, State}.
|
||||
{Res, Req1, State1} = handle_type_accepted(Req, State),
|
||||
{true =:= Res, Req1, State1}.
|
||||
|
||||
-spec handle_type_accepted(cowboy_req:req(), state()) ->
|
||||
{ openapi_logic_handler:accept_callback_return(), cowboy_req:req(), state()}.
|
||||
|
@ -2,8 +2,9 @@
|
||||
-moduledoc """
|
||||
Exposes the following operation IDs:
|
||||
|
||||
- `GET` to `/header/integer/boolean/string/enums`, OperationId: `TestHeaderIntegerBooleanStringEnums`:
|
||||
- `GET` to `/header/integer/boolean/string/enums`, OperationId: `test/header/integer/boolean/string/enums`:
|
||||
Test header parameter(s).
|
||||
Test header parameter(s)
|
||||
|
||||
""".
|
||||
|
||||
@ -23,8 +24,16 @@ Test header parameter(s).
|
||||
|
||||
-ignore_xref([handle_type_accepted/2, handle_type_provided/2]).
|
||||
|
||||
-export_type([class/0, operation_id/0]).
|
||||
|
||||
-type class() :: 'header'.
|
||||
|
||||
-type operation_id() ::
|
||||
'test/header/integer/boolean/string/enums'. %% Test header parameter(s)
|
||||
|
||||
|
||||
-record(state,
|
||||
{operation_id :: openapi_api:operation_id(),
|
||||
{operation_id :: operation_id(),
|
||||
accept_callback :: openapi_logic_handler:accept_callback(),
|
||||
provide_callback :: openapi_logic_handler:provide_callback(),
|
||||
api_key_handler :: openapi_logic_handler:api_key_callback(),
|
||||
@ -48,7 +57,7 @@ init(Req, {Operations, Module}) ->
|
||||
|
||||
-spec allowed_methods(cowboy_req:req(), state()) ->
|
||||
{[binary()], cowboy_req:req(), state()}.
|
||||
allowed_methods(Req, #state{operation_id = 'TestHeaderIntegerBooleanStringEnums'} = State) ->
|
||||
allowed_methods(Req, #state{operation_id = 'test/header/integer/boolean/string/enums'} = State) ->
|
||||
{[<<"GET">>], Req, State};
|
||||
allowed_methods(Req, State) ->
|
||||
{[], Req, State}.
|
||||
@ -60,21 +69,21 @@ is_authorized(Req, State) ->
|
||||
|
||||
-spec content_types_accepted(cowboy_req:req(), state()) ->
|
||||
{[{binary(), atom()}], cowboy_req:req(), state()}.
|
||||
content_types_accepted(Req, #state{operation_id = 'TestHeaderIntegerBooleanStringEnums'} = State) ->
|
||||
content_types_accepted(Req, #state{operation_id = 'test/header/integer/boolean/string/enums'} = State) ->
|
||||
{[], Req, State};
|
||||
content_types_accepted(Req, State) ->
|
||||
{[], Req, State}.
|
||||
|
||||
-spec valid_content_headers(cowboy_req:req(), state()) ->
|
||||
{boolean(), cowboy_req:req(), state()}.
|
||||
valid_content_headers(Req, #state{operation_id = 'TestHeaderIntegerBooleanStringEnums'} = State) ->
|
||||
valid_content_headers(Req, #state{operation_id = 'test/header/integer/boolean/string/enums'} = State) ->
|
||||
{true, Req, State};
|
||||
valid_content_headers(Req, State) ->
|
||||
{false, Req, State}.
|
||||
|
||||
-spec content_types_provided(cowboy_req:req(), state()) ->
|
||||
{[{binary(), atom()}], cowboy_req:req(), state()}.
|
||||
content_types_provided(Req, #state{operation_id = 'TestHeaderIntegerBooleanStringEnums'} = State) ->
|
||||
content_types_provided(Req, #state{operation_id = 'test/header/integer/boolean/string/enums'} = State) ->
|
||||
{[
|
||||
{<<"text/plain">>, handle_type_provided}
|
||||
], Req, State};
|
||||
@ -84,8 +93,8 @@ content_types_provided(Req, State) ->
|
||||
-spec delete_resource(cowboy_req:req(), state()) ->
|
||||
{boolean(), cowboy_req:req(), state()}.
|
||||
delete_resource(Req, State) ->
|
||||
{Res, Req1, State} = handle_type_accepted(Req, State),
|
||||
{true =:= Res, Req1, State}.
|
||||
{Res, Req1, State1} = handle_type_accepted(Req, State),
|
||||
{true =:= Res, Req1, State1}.
|
||||
|
||||
-spec handle_type_accepted(cowboy_req:req(), state()) ->
|
||||
{ openapi_logic_handler:accept_callback_return(), cowboy_req:req(), state()}.
|
||||
|
@ -11,10 +11,10 @@
|
||||
-type api_key_callback() ::
|
||||
fun((openapi_api:operation_id(), binary()) -> {true, context()} | {false, iodata()}).
|
||||
-type accept_callback() ::
|
||||
fun((atom(), openapi_api:operation_id(), cowboy_req:req(), context()) ->
|
||||
fun((openapi_api:class(), openapi_api:operation_id(), cowboy_req:req(), context()) ->
|
||||
{accept_callback_return(), cowboy_req:req(), context()}).
|
||||
-type provide_callback() ::
|
||||
fun((atom(), openapi_api:operation_id(), cowboy_req:req(), context()) ->
|
||||
fun((openapi_api:class(), openapi_api:operation_id(), cowboy_req:req(), context()) ->
|
||||
{cowboy_req:resp_body(), cowboy_req:req(), context()}).
|
||||
-type context() :: #{_ := _}.
|
||||
|
||||
@ -26,10 +26,10 @@
|
||||
-callback api_key_callback(openapi_api:operation_id(), binary()) ->
|
||||
{true, context()} | {false, iodata()}.
|
||||
|
||||
-callback accept_callback(atom(), openapi_api:operation_id(), cowboy_req:req(), context()) ->
|
||||
-callback accept_callback(openapi_api:class(), openapi_api:operation_id(), cowboy_req:req(), context()) ->
|
||||
{accept_callback_return(), cowboy_req:req(), context()}.
|
||||
|
||||
-callback provide_callback(atom(), openapi_api:operation_id(), cowboy_req:req(), context()) ->
|
||||
-callback provide_callback(openapi_api:class(), openapi_api:operation_id(), cowboy_req:req(), context()) ->
|
||||
{cowboy_req:resp_body(), cowboy_req:req(), context()}.
|
||||
|
||||
-export([api_key_callback/2, accept_callback/4, provide_callback/4]).
|
||||
@ -42,7 +42,7 @@ api_key_callback(OperationID, ApiKey) ->
|
||||
api_key => ApiKey}),
|
||||
{true, #{}}.
|
||||
|
||||
-spec accept_callback(atom(), openapi_api:operation_id(), cowboy_req:req(), context()) ->
|
||||
-spec accept_callback(openapi_api:class(), openapi_api:operation_id(), cowboy_req:req(), context()) ->
|
||||
{accept_callback_return(), cowboy_req:req(), context()}.
|
||||
accept_callback(Class, OperationID, Req, Context) ->
|
||||
?LOG_ERROR(#{what => "Got not implemented request to process",
|
||||
@ -52,7 +52,7 @@ accept_callback(Class, OperationID, Req, Context) ->
|
||||
context => Context}),
|
||||
{false, Req, Context}.
|
||||
|
||||
-spec provide_callback(atom(), openapi_api:operation_id(), cowboy_req:req(), context()) ->
|
||||
-spec provide_callback(openapi_api:class(), openapi_api:operation_id(), cowboy_req:req(), context()) ->
|
||||
{cowboy_req:resp_body(), cowboy_req:req(), context()}.
|
||||
provide_callback(Class, OperationID, Req, Context) ->
|
||||
?LOG_ERROR(#{what => "Got not implemented request to process",
|
||||
|
@ -2,8 +2,9 @@
|
||||
-moduledoc """
|
||||
Exposes the following operation IDs:
|
||||
|
||||
- `GET` to `/path/string/:path_string/integer/:path_integer/:enum_nonref_string_path/:enum_ref_string_path`, OperationId: `TestsPathString{pathString}Integer{pathInteger}{enumNonrefStringPath}{enumRefStringPath}`:
|
||||
- `GET` to `/path/string/:path_string/integer/:path_integer/:enum_nonref_string_path/:enum_ref_string_path`, OperationId: `tests/path/string/{path_string}/integer/{path_integer}/{enum_nonref_string_path}/{enum_ref_string_path}`:
|
||||
Test path parameter(s).
|
||||
Test path parameter(s)
|
||||
|
||||
""".
|
||||
|
||||
@ -23,8 +24,16 @@ Test path parameter(s).
|
||||
|
||||
-ignore_xref([handle_type_accepted/2, handle_type_provided/2]).
|
||||
|
||||
-export_type([class/0, operation_id/0]).
|
||||
|
||||
-type class() :: 'path'.
|
||||
|
||||
-type operation_id() ::
|
||||
'tests/path/string/{path_string}/integer/{path_integer}/{enum_nonref_string_path}/{enum_ref_string_path}'. %% Test path parameter(s)
|
||||
|
||||
|
||||
-record(state,
|
||||
{operation_id :: openapi_api:operation_id(),
|
||||
{operation_id :: operation_id(),
|
||||
accept_callback :: openapi_logic_handler:accept_callback(),
|
||||
provide_callback :: openapi_logic_handler:provide_callback(),
|
||||
api_key_handler :: openapi_logic_handler:api_key_callback(),
|
||||
@ -48,7 +57,7 @@ init(Req, {Operations, Module}) ->
|
||||
|
||||
-spec allowed_methods(cowboy_req:req(), state()) ->
|
||||
{[binary()], cowboy_req:req(), state()}.
|
||||
allowed_methods(Req, #state{operation_id = 'TestsPathString{pathString}Integer{pathInteger}{enumNonrefStringPath}{enumRefStringPath}'} = State) ->
|
||||
allowed_methods(Req, #state{operation_id = 'tests/path/string/{path_string}/integer/{path_integer}/{enum_nonref_string_path}/{enum_ref_string_path}'} = State) ->
|
||||
{[<<"GET">>], Req, State};
|
||||
allowed_methods(Req, State) ->
|
||||
{[], Req, State}.
|
||||
@ -60,21 +69,21 @@ is_authorized(Req, State) ->
|
||||
|
||||
-spec content_types_accepted(cowboy_req:req(), state()) ->
|
||||
{[{binary(), atom()}], cowboy_req:req(), state()}.
|
||||
content_types_accepted(Req, #state{operation_id = 'TestsPathString{pathString}Integer{pathInteger}{enumNonrefStringPath}{enumRefStringPath}'} = State) ->
|
||||
content_types_accepted(Req, #state{operation_id = 'tests/path/string/{path_string}/integer/{path_integer}/{enum_nonref_string_path}/{enum_ref_string_path}'} = State) ->
|
||||
{[], Req, State};
|
||||
content_types_accepted(Req, State) ->
|
||||
{[], Req, State}.
|
||||
|
||||
-spec valid_content_headers(cowboy_req:req(), state()) ->
|
||||
{boolean(), cowboy_req:req(), state()}.
|
||||
valid_content_headers(Req, #state{operation_id = 'TestsPathString{pathString}Integer{pathInteger}{enumNonrefStringPath}{enumRefStringPath}'} = State) ->
|
||||
valid_content_headers(Req, #state{operation_id = 'tests/path/string/{path_string}/integer/{path_integer}/{enum_nonref_string_path}/{enum_ref_string_path}'} = State) ->
|
||||
{true, Req, State};
|
||||
valid_content_headers(Req, State) ->
|
||||
{false, Req, State}.
|
||||
|
||||
-spec content_types_provided(cowboy_req:req(), state()) ->
|
||||
{[{binary(), atom()}], cowboy_req:req(), state()}.
|
||||
content_types_provided(Req, #state{operation_id = 'TestsPathString{pathString}Integer{pathInteger}{enumNonrefStringPath}{enumRefStringPath}'} = State) ->
|
||||
content_types_provided(Req, #state{operation_id = 'tests/path/string/{path_string}/integer/{path_integer}/{enum_nonref_string_path}/{enum_ref_string_path}'} = State) ->
|
||||
{[
|
||||
{<<"text/plain">>, handle_type_provided}
|
||||
], Req, State};
|
||||
@ -84,8 +93,8 @@ content_types_provided(Req, State) ->
|
||||
-spec delete_resource(cowboy_req:req(), state()) ->
|
||||
{boolean(), cowboy_req:req(), state()}.
|
||||
delete_resource(Req, State) ->
|
||||
{Res, Req1, State} = handle_type_accepted(Req, State),
|
||||
{true =:= Res, Req1, State}.
|
||||
{Res, Req1, State1} = handle_type_accepted(Req, State),
|
||||
{true =:= Res, Req1, State1}.
|
||||
|
||||
-spec handle_type_accepted(cowboy_req:req(), state()) ->
|
||||
{ openapi_logic_handler:accept_callback_return(), cowboy_req:req(), state()}.
|
||||
|
@ -2,35 +2,45 @@
|
||||
-moduledoc """
|
||||
Exposes the following operation IDs:
|
||||
|
||||
- `GET` to `/query/enum_ref_string`, OperationId: `TestEnumRefString`:
|
||||
- `GET` to `/query/enum_ref_string`, OperationId: `test/enum_ref_string`:
|
||||
Test query parameter(s).
|
||||
Test query parameter(s)
|
||||
|
||||
- `GET` to `/query/datetime/date/string`, OperationId: `TestQueryDatetimeDateString`:
|
||||
- `GET` to `/query/datetime/date/string`, OperationId: `test/query/datetime/date/string`:
|
||||
Test query parameter(s).
|
||||
Test query parameter(s)
|
||||
|
||||
- `GET` to `/query/integer/boolean/string`, OperationId: `TestQueryIntegerBooleanString`:
|
||||
- `GET` to `/query/integer/boolean/string`, OperationId: `test/query/integer/boolean/string`:
|
||||
Test query parameter(s).
|
||||
Test query parameter(s)
|
||||
|
||||
- `GET` to `/query/style_deepObject/explode_true/object`, OperationId: `TestQueryStyleDeepObjectExplodeTrueObject`:
|
||||
- `GET` to `/query/style_deepObject/explode_true/object`, OperationId: `test/query/style_deepObject/explode_true/object`:
|
||||
Test query parameter(s).
|
||||
Test query parameter(s)
|
||||
|
||||
- `GET` to `/query/style_deepObject/explode_true/object/allOf`, OperationId: `TestQueryStyleDeepObjectExplodeTrueObjectAllOf`:
|
||||
- `GET` to `/query/style_deepObject/explode_true/object/allOf`, OperationId: `test/query/style_deepObject/explode_true/object/allOf`:
|
||||
Test query parameter(s).
|
||||
Test query parameter(s)
|
||||
|
||||
- `GET` to `/query/style_form/explode_false/array_integer`, OperationId: `TestQueryStyleFormExplodeFalseArrayInteger`:
|
||||
- `GET` to `/query/style_form/explode_false/array_integer`, OperationId: `test/query/style_form/explode_false/array_integer`:
|
||||
Test query parameter(s).
|
||||
Test query parameter(s)
|
||||
|
||||
- `GET` to `/query/style_form/explode_false/array_string`, OperationId: `TestQueryStyleFormExplodeFalseArrayString`:
|
||||
- `GET` to `/query/style_form/explode_false/array_string`, OperationId: `test/query/style_form/explode_false/array_string`:
|
||||
Test query parameter(s).
|
||||
Test query parameter(s)
|
||||
|
||||
- `GET` to `/query/style_form/explode_true/array_string`, OperationId: `TestQueryStyleFormExplodeTrueArrayString`:
|
||||
- `GET` to `/query/style_form/explode_true/array_string`, OperationId: `test/query/style_form/explode_true/array_string`:
|
||||
Test query parameter(s).
|
||||
Test query parameter(s)
|
||||
|
||||
- `GET` to `/query/style_form/explode_true/object`, OperationId: `TestQueryStyleFormExplodeTrueObject`:
|
||||
- `GET` to `/query/style_form/explode_true/object`, OperationId: `test/query/style_form/explode_true/object`:
|
||||
Test query parameter(s).
|
||||
Test query parameter(s)
|
||||
|
||||
- `GET` to `/query/style_form/explode_true/object/allOf`, OperationId: `TestQueryStyleFormExplodeTrueObjectAllOf`:
|
||||
- `GET` to `/query/style_form/explode_true/object/allOf`, OperationId: `test/query/style_form/explode_true/object/allOf`:
|
||||
Test query parameter(s).
|
||||
Test query parameter(s)
|
||||
|
||||
""".
|
||||
|
||||
@ -50,8 +60,25 @@ Test query parameter(s).
|
||||
|
||||
-ignore_xref([handle_type_accepted/2, handle_type_provided/2]).
|
||||
|
||||
-export_type([class/0, operation_id/0]).
|
||||
|
||||
-type class() :: 'query'.
|
||||
|
||||
-type operation_id() ::
|
||||
'test/enum_ref_string' %% Test query parameter(s)
|
||||
| 'test/query/datetime/date/string' %% Test query parameter(s)
|
||||
| 'test/query/integer/boolean/string' %% Test query parameter(s)
|
||||
| 'test/query/style_deepObject/explode_true/object' %% Test query parameter(s)
|
||||
| 'test/query/style_deepObject/explode_true/object/allOf' %% Test query parameter(s)
|
||||
| 'test/query/style_form/explode_false/array_integer' %% Test query parameter(s)
|
||||
| 'test/query/style_form/explode_false/array_string' %% Test query parameter(s)
|
||||
| 'test/query/style_form/explode_true/array_string' %% Test query parameter(s)
|
||||
| 'test/query/style_form/explode_true/object' %% Test query parameter(s)
|
||||
| 'test/query/style_form/explode_true/object/allOf'. %% Test query parameter(s)
|
||||
|
||||
|
||||
-record(state,
|
||||
{operation_id :: openapi_api:operation_id(),
|
||||
{operation_id :: operation_id(),
|
||||
accept_callback :: openapi_logic_handler:accept_callback(),
|
||||
provide_callback :: openapi_logic_handler:provide_callback(),
|
||||
api_key_handler :: openapi_logic_handler:api_key_callback(),
|
||||
@ -75,25 +102,25 @@ init(Req, {Operations, Module}) ->
|
||||
|
||||
-spec allowed_methods(cowboy_req:req(), state()) ->
|
||||
{[binary()], cowboy_req:req(), state()}.
|
||||
allowed_methods(Req, #state{operation_id = 'TestEnumRefString'} = State) ->
|
||||
allowed_methods(Req, #state{operation_id = 'test/enum_ref_string'} = State) ->
|
||||
{[<<"GET">>], Req, State};
|
||||
allowed_methods(Req, #state{operation_id = 'TestQueryDatetimeDateString'} = State) ->
|
||||
allowed_methods(Req, #state{operation_id = 'test/query/datetime/date/string'} = State) ->
|
||||
{[<<"GET">>], Req, State};
|
||||
allowed_methods(Req, #state{operation_id = 'TestQueryIntegerBooleanString'} = State) ->
|
||||
allowed_methods(Req, #state{operation_id = 'test/query/integer/boolean/string'} = State) ->
|
||||
{[<<"GET">>], Req, State};
|
||||
allowed_methods(Req, #state{operation_id = 'TestQueryStyleDeepObjectExplodeTrueObject'} = State) ->
|
||||
allowed_methods(Req, #state{operation_id = 'test/query/style_deepObject/explode_true/object'} = State) ->
|
||||
{[<<"GET">>], Req, State};
|
||||
allowed_methods(Req, #state{operation_id = 'TestQueryStyleDeepObjectExplodeTrueObjectAllOf'} = State) ->
|
||||
allowed_methods(Req, #state{operation_id = 'test/query/style_deepObject/explode_true/object/allOf'} = State) ->
|
||||
{[<<"GET">>], Req, State};
|
||||
allowed_methods(Req, #state{operation_id = 'TestQueryStyleFormExplodeFalseArrayInteger'} = State) ->
|
||||
allowed_methods(Req, #state{operation_id = 'test/query/style_form/explode_false/array_integer'} = State) ->
|
||||
{[<<"GET">>], Req, State};
|
||||
allowed_methods(Req, #state{operation_id = 'TestQueryStyleFormExplodeFalseArrayString'} = State) ->
|
||||
allowed_methods(Req, #state{operation_id = 'test/query/style_form/explode_false/array_string'} = State) ->
|
||||
{[<<"GET">>], Req, State};
|
||||
allowed_methods(Req, #state{operation_id = 'TestQueryStyleFormExplodeTrueArrayString'} = State) ->
|
||||
allowed_methods(Req, #state{operation_id = 'test/query/style_form/explode_true/array_string'} = State) ->
|
||||
{[<<"GET">>], Req, State};
|
||||
allowed_methods(Req, #state{operation_id = 'TestQueryStyleFormExplodeTrueObject'} = State) ->
|
||||
allowed_methods(Req, #state{operation_id = 'test/query/style_form/explode_true/object'} = State) ->
|
||||
{[<<"GET">>], Req, State};
|
||||
allowed_methods(Req, #state{operation_id = 'TestQueryStyleFormExplodeTrueObjectAllOf'} = State) ->
|
||||
allowed_methods(Req, #state{operation_id = 'test/query/style_form/explode_true/object/allOf'} = State) ->
|
||||
{[<<"GET">>], Req, State};
|
||||
allowed_methods(Req, State) ->
|
||||
{[], Req, State}.
|
||||
@ -105,93 +132,93 @@ is_authorized(Req, State) ->
|
||||
|
||||
-spec content_types_accepted(cowboy_req:req(), state()) ->
|
||||
{[{binary(), atom()}], cowboy_req:req(), state()}.
|
||||
content_types_accepted(Req, #state{operation_id = 'TestEnumRefString'} = State) ->
|
||||
content_types_accepted(Req, #state{operation_id = 'test/enum_ref_string'} = State) ->
|
||||
{[], Req, State};
|
||||
content_types_accepted(Req, #state{operation_id = 'TestQueryDatetimeDateString'} = State) ->
|
||||
content_types_accepted(Req, #state{operation_id = 'test/query/datetime/date/string'} = State) ->
|
||||
{[], Req, State};
|
||||
content_types_accepted(Req, #state{operation_id = 'TestQueryIntegerBooleanString'} = State) ->
|
||||
content_types_accepted(Req, #state{operation_id = 'test/query/integer/boolean/string'} = State) ->
|
||||
{[], Req, State};
|
||||
content_types_accepted(Req, #state{operation_id = 'TestQueryStyleDeepObjectExplodeTrueObject'} = State) ->
|
||||
content_types_accepted(Req, #state{operation_id = 'test/query/style_deepObject/explode_true/object'} = State) ->
|
||||
{[], Req, State};
|
||||
content_types_accepted(Req, #state{operation_id = 'TestQueryStyleDeepObjectExplodeTrueObjectAllOf'} = State) ->
|
||||
content_types_accepted(Req, #state{operation_id = 'test/query/style_deepObject/explode_true/object/allOf'} = State) ->
|
||||
{[], Req, State};
|
||||
content_types_accepted(Req, #state{operation_id = 'TestQueryStyleFormExplodeFalseArrayInteger'} = State) ->
|
||||
content_types_accepted(Req, #state{operation_id = 'test/query/style_form/explode_false/array_integer'} = State) ->
|
||||
{[], Req, State};
|
||||
content_types_accepted(Req, #state{operation_id = 'TestQueryStyleFormExplodeFalseArrayString'} = State) ->
|
||||
content_types_accepted(Req, #state{operation_id = 'test/query/style_form/explode_false/array_string'} = State) ->
|
||||
{[], Req, State};
|
||||
content_types_accepted(Req, #state{operation_id = 'TestQueryStyleFormExplodeTrueArrayString'} = State) ->
|
||||
content_types_accepted(Req, #state{operation_id = 'test/query/style_form/explode_true/array_string'} = State) ->
|
||||
{[], Req, State};
|
||||
content_types_accepted(Req, #state{operation_id = 'TestQueryStyleFormExplodeTrueObject'} = State) ->
|
||||
content_types_accepted(Req, #state{operation_id = 'test/query/style_form/explode_true/object'} = State) ->
|
||||
{[], Req, State};
|
||||
content_types_accepted(Req, #state{operation_id = 'TestQueryStyleFormExplodeTrueObjectAllOf'} = State) ->
|
||||
content_types_accepted(Req, #state{operation_id = 'test/query/style_form/explode_true/object/allOf'} = State) ->
|
||||
{[], Req, State};
|
||||
content_types_accepted(Req, State) ->
|
||||
{[], Req, State}.
|
||||
|
||||
-spec valid_content_headers(cowboy_req:req(), state()) ->
|
||||
{boolean(), cowboy_req:req(), state()}.
|
||||
valid_content_headers(Req, #state{operation_id = 'TestEnumRefString'} = State) ->
|
||||
valid_content_headers(Req, #state{operation_id = 'test/enum_ref_string'} = State) ->
|
||||
{true, Req, State};
|
||||
valid_content_headers(Req, #state{operation_id = 'TestQueryDatetimeDateString'} = State) ->
|
||||
valid_content_headers(Req, #state{operation_id = 'test/query/datetime/date/string'} = State) ->
|
||||
{true, Req, State};
|
||||
valid_content_headers(Req, #state{operation_id = 'TestQueryIntegerBooleanString'} = State) ->
|
||||
valid_content_headers(Req, #state{operation_id = 'test/query/integer/boolean/string'} = State) ->
|
||||
{true, Req, State};
|
||||
valid_content_headers(Req, #state{operation_id = 'TestQueryStyleDeepObjectExplodeTrueObject'} = State) ->
|
||||
valid_content_headers(Req, #state{operation_id = 'test/query/style_deepObject/explode_true/object'} = State) ->
|
||||
{true, Req, State};
|
||||
valid_content_headers(Req, #state{operation_id = 'TestQueryStyleDeepObjectExplodeTrueObjectAllOf'} = State) ->
|
||||
valid_content_headers(Req, #state{operation_id = 'test/query/style_deepObject/explode_true/object/allOf'} = State) ->
|
||||
{true, Req, State};
|
||||
valid_content_headers(Req, #state{operation_id = 'TestQueryStyleFormExplodeFalseArrayInteger'} = State) ->
|
||||
valid_content_headers(Req, #state{operation_id = 'test/query/style_form/explode_false/array_integer'} = State) ->
|
||||
{true, Req, State};
|
||||
valid_content_headers(Req, #state{operation_id = 'TestQueryStyleFormExplodeFalseArrayString'} = State) ->
|
||||
valid_content_headers(Req, #state{operation_id = 'test/query/style_form/explode_false/array_string'} = State) ->
|
||||
{true, Req, State};
|
||||
valid_content_headers(Req, #state{operation_id = 'TestQueryStyleFormExplodeTrueArrayString'} = State) ->
|
||||
valid_content_headers(Req, #state{operation_id = 'test/query/style_form/explode_true/array_string'} = State) ->
|
||||
{true, Req, State};
|
||||
valid_content_headers(Req, #state{operation_id = 'TestQueryStyleFormExplodeTrueObject'} = State) ->
|
||||
valid_content_headers(Req, #state{operation_id = 'test/query/style_form/explode_true/object'} = State) ->
|
||||
{true, Req, State};
|
||||
valid_content_headers(Req, #state{operation_id = 'TestQueryStyleFormExplodeTrueObjectAllOf'} = State) ->
|
||||
valid_content_headers(Req, #state{operation_id = 'test/query/style_form/explode_true/object/allOf'} = State) ->
|
||||
{true, Req, State};
|
||||
valid_content_headers(Req, State) ->
|
||||
{false, Req, State}.
|
||||
|
||||
-spec content_types_provided(cowboy_req:req(), state()) ->
|
||||
{[{binary(), atom()}], cowboy_req:req(), state()}.
|
||||
content_types_provided(Req, #state{operation_id = 'TestEnumRefString'} = State) ->
|
||||
content_types_provided(Req, #state{operation_id = 'test/enum_ref_string'} = State) ->
|
||||
{[
|
||||
{<<"text/plain">>, handle_type_provided}
|
||||
], Req, State};
|
||||
content_types_provided(Req, #state{operation_id = 'TestQueryDatetimeDateString'} = State) ->
|
||||
content_types_provided(Req, #state{operation_id = 'test/query/datetime/date/string'} = State) ->
|
||||
{[
|
||||
{<<"text/plain">>, handle_type_provided}
|
||||
], Req, State};
|
||||
content_types_provided(Req, #state{operation_id = 'TestQueryIntegerBooleanString'} = State) ->
|
||||
content_types_provided(Req, #state{operation_id = 'test/query/integer/boolean/string'} = State) ->
|
||||
{[
|
||||
{<<"text/plain">>, handle_type_provided}
|
||||
], Req, State};
|
||||
content_types_provided(Req, #state{operation_id = 'TestQueryStyleDeepObjectExplodeTrueObject'} = State) ->
|
||||
content_types_provided(Req, #state{operation_id = 'test/query/style_deepObject/explode_true/object'} = State) ->
|
||||
{[
|
||||
{<<"text/plain">>, handle_type_provided}
|
||||
], Req, State};
|
||||
content_types_provided(Req, #state{operation_id = 'TestQueryStyleDeepObjectExplodeTrueObjectAllOf'} = State) ->
|
||||
content_types_provided(Req, #state{operation_id = 'test/query/style_deepObject/explode_true/object/allOf'} = State) ->
|
||||
{[
|
||||
{<<"text/plain">>, handle_type_provided}
|
||||
], Req, State};
|
||||
content_types_provided(Req, #state{operation_id = 'TestQueryStyleFormExplodeFalseArrayInteger'} = State) ->
|
||||
content_types_provided(Req, #state{operation_id = 'test/query/style_form/explode_false/array_integer'} = State) ->
|
||||
{[
|
||||
{<<"text/plain">>, handle_type_provided}
|
||||
], Req, State};
|
||||
content_types_provided(Req, #state{operation_id = 'TestQueryStyleFormExplodeFalseArrayString'} = State) ->
|
||||
content_types_provided(Req, #state{operation_id = 'test/query/style_form/explode_false/array_string'} = State) ->
|
||||
{[
|
||||
{<<"text/plain">>, handle_type_provided}
|
||||
], Req, State};
|
||||
content_types_provided(Req, #state{operation_id = 'TestQueryStyleFormExplodeTrueArrayString'} = State) ->
|
||||
content_types_provided(Req, #state{operation_id = 'test/query/style_form/explode_true/array_string'} = State) ->
|
||||
{[
|
||||
{<<"text/plain">>, handle_type_provided}
|
||||
], Req, State};
|
||||
content_types_provided(Req, #state{operation_id = 'TestQueryStyleFormExplodeTrueObject'} = State) ->
|
||||
content_types_provided(Req, #state{operation_id = 'test/query/style_form/explode_true/object'} = State) ->
|
||||
{[
|
||||
{<<"text/plain">>, handle_type_provided}
|
||||
], Req, State};
|
||||
content_types_provided(Req, #state{operation_id = 'TestQueryStyleFormExplodeTrueObjectAllOf'} = State) ->
|
||||
content_types_provided(Req, #state{operation_id = 'test/query/style_form/explode_true/object/allOf'} = State) ->
|
||||
{[
|
||||
{<<"text/plain">>, handle_type_provided}
|
||||
], Req, State};
|
||||
@ -201,8 +228,8 @@ content_types_provided(Req, State) ->
|
||||
-spec delete_resource(cowboy_req:req(), state()) ->
|
||||
{boolean(), cowboy_req:req(), state()}.
|
||||
delete_resource(Req, State) ->
|
||||
{Res, Req1, State} = handle_type_accepted(Req, State),
|
||||
{true =:= Res, Req1, State}.
|
||||
{Res, Req1, State1} = handle_type_accepted(Req, State),
|
||||
{true =:= Res, Req1, State1}.
|
||||
|
||||
-spec handle_type_accepted(cowboy_req:req(), state()) ->
|
||||
{ openapi_logic_handler:accept_callback_return(), cowboy_req:req(), state()}.
|
||||
|
@ -47,189 +47,189 @@ merge_paths(FullPaths, OperationID, Method, Handler, Acc) ->
|
||||
|
||||
get_operations() ->
|
||||
#{
|
||||
'TestAuthHttpBasic' => #{
|
||||
'test/auth/http/basic' => #{
|
||||
servers => [],
|
||||
base_path => "",
|
||||
path => "/auth/http/basic",
|
||||
method => <<"POST">>,
|
||||
handler => 'openapi_auth_handler'
|
||||
},
|
||||
'TestAuthHttpBearer' => #{
|
||||
'test/auth/http/bearer' => #{
|
||||
servers => [],
|
||||
base_path => "",
|
||||
path => "/auth/http/bearer",
|
||||
method => <<"POST">>,
|
||||
handler => 'openapi_auth_handler'
|
||||
},
|
||||
'TestBinaryGif' => #{
|
||||
'test/binary/gif' => #{
|
||||
servers => [],
|
||||
base_path => "",
|
||||
path => "/binary/gif",
|
||||
method => <<"POST">>,
|
||||
handler => 'openapi_body_handler'
|
||||
},
|
||||
'TestBodyApplicationOctetstreamBinary' => #{
|
||||
'test/body/application/octetstream/binary' => #{
|
||||
servers => [],
|
||||
base_path => "",
|
||||
path => "/body/application/octetstream/binary",
|
||||
method => <<"POST">>,
|
||||
handler => 'openapi_body_handler'
|
||||
},
|
||||
'TestBodyMultipartFormdataArrayOfBinary' => #{
|
||||
'test/body/multipart/formdata/array_of_binary' => #{
|
||||
servers => [],
|
||||
base_path => "",
|
||||
path => "/body/application/octetstream/array_of_binary",
|
||||
method => <<"POST">>,
|
||||
handler => 'openapi_body_handler'
|
||||
},
|
||||
'TestBodyMultipartFormdataSingleBinary' => #{
|
||||
'test/body/multipart/formdata/single_binary' => #{
|
||||
servers => [],
|
||||
base_path => "",
|
||||
path => "/body/application/octetstream/single_binary",
|
||||
method => <<"POST">>,
|
||||
handler => 'openapi_body_handler'
|
||||
},
|
||||
'TestEchoBodyAllOfPet' => #{
|
||||
'test/echo/body/allOf/Pet' => #{
|
||||
servers => [],
|
||||
base_path => "",
|
||||
path => "/echo/body/allOf/Pet",
|
||||
method => <<"POST">>,
|
||||
handler => 'openapi_body_handler'
|
||||
},
|
||||
'TestEchoBodyFreeFormObjectResponseString' => #{
|
||||
'test/echo/body/FreeFormObject/response_string' => #{
|
||||
servers => [],
|
||||
base_path => "",
|
||||
path => "/echo/body/FreeFormObject/response_string",
|
||||
method => <<"POST">>,
|
||||
handler => 'openapi_body_handler'
|
||||
},
|
||||
'TestEchoBodyPet' => #{
|
||||
'test/echo/body/Pet' => #{
|
||||
servers => [],
|
||||
base_path => "",
|
||||
path => "/echo/body/Pet",
|
||||
method => <<"POST">>,
|
||||
handler => 'openapi_body_handler'
|
||||
},
|
||||
'TestEchoBodyPetResponseString' => #{
|
||||
'test/echo/body/Pet/response_string' => #{
|
||||
servers => [],
|
||||
base_path => "",
|
||||
path => "/echo/body/Pet/response_string",
|
||||
method => <<"POST">>,
|
||||
handler => 'openapi_body_handler'
|
||||
},
|
||||
'TestEchoBodyStringEnum' => #{
|
||||
'test/echo/body/string_enum' => #{
|
||||
servers => [],
|
||||
base_path => "",
|
||||
path => "/echo/body/string_enum",
|
||||
method => <<"POST">>,
|
||||
handler => 'openapi_body_handler'
|
||||
},
|
||||
'TestEchoBodyTagResponseString' => #{
|
||||
'test/echo/body/Tag/response_string' => #{
|
||||
servers => [],
|
||||
base_path => "",
|
||||
path => "/echo/body/Tag/response_string",
|
||||
method => <<"POST">>,
|
||||
handler => 'openapi_body_handler'
|
||||
},
|
||||
'TestFormIntegerBooleanString' => #{
|
||||
'test/form/integer/boolean/string' => #{
|
||||
servers => [],
|
||||
base_path => "",
|
||||
path => "/form/integer/boolean/string",
|
||||
method => <<"POST">>,
|
||||
handler => 'openapi_form_handler'
|
||||
},
|
||||
'TestFormObjectMultipart' => #{
|
||||
'test/form/object/multipart' => #{
|
||||
servers => [],
|
||||
base_path => "",
|
||||
path => "/form/object/multipart",
|
||||
method => <<"POST">>,
|
||||
handler => 'openapi_form_handler'
|
||||
},
|
||||
'TestFormOneof' => #{
|
||||
'test/form/oneof' => #{
|
||||
servers => [],
|
||||
base_path => "",
|
||||
path => "/form/oneof",
|
||||
method => <<"POST">>,
|
||||
handler => 'openapi_form_handler'
|
||||
},
|
||||
'TestHeaderIntegerBooleanStringEnums' => #{
|
||||
'test/header/integer/boolean/string/enums' => #{
|
||||
servers => [],
|
||||
base_path => "",
|
||||
path => "/header/integer/boolean/string/enums",
|
||||
method => <<"GET">>,
|
||||
handler => 'openapi_header_handler'
|
||||
},
|
||||
'TestsPathString{pathString}Integer{pathInteger}{enumNonrefStringPath}{enumRefStringPath}' => #{
|
||||
'tests/path/string/{path_string}/integer/{path_integer}/{enum_nonref_string_path}/{enum_ref_string_path}' => #{
|
||||
servers => [],
|
||||
base_path => "",
|
||||
path => "/path/string/:path_string/integer/:path_integer/:enum_nonref_string_path/:enum_ref_string_path",
|
||||
method => <<"GET">>,
|
||||
handler => 'openapi_path_handler'
|
||||
},
|
||||
'TestEnumRefString' => #{
|
||||
'test/enum_ref_string' => #{
|
||||
servers => [],
|
||||
base_path => "",
|
||||
path => "/query/enum_ref_string",
|
||||
method => <<"GET">>,
|
||||
handler => 'openapi_query_handler'
|
||||
},
|
||||
'TestQueryDatetimeDateString' => #{
|
||||
'test/query/datetime/date/string' => #{
|
||||
servers => [],
|
||||
base_path => "",
|
||||
path => "/query/datetime/date/string",
|
||||
method => <<"GET">>,
|
||||
handler => 'openapi_query_handler'
|
||||
},
|
||||
'TestQueryIntegerBooleanString' => #{
|
||||
'test/query/integer/boolean/string' => #{
|
||||
servers => [],
|
||||
base_path => "",
|
||||
path => "/query/integer/boolean/string",
|
||||
method => <<"GET">>,
|
||||
handler => 'openapi_query_handler'
|
||||
},
|
||||
'TestQueryStyleDeepObjectExplodeTrueObject' => #{
|
||||
'test/query/style_deepObject/explode_true/object' => #{
|
||||
servers => [],
|
||||
base_path => "",
|
||||
path => "/query/style_deepObject/explode_true/object",
|
||||
method => <<"GET">>,
|
||||
handler => 'openapi_query_handler'
|
||||
},
|
||||
'TestQueryStyleDeepObjectExplodeTrueObjectAllOf' => #{
|
||||
'test/query/style_deepObject/explode_true/object/allOf' => #{
|
||||
servers => [],
|
||||
base_path => "",
|
||||
path => "/query/style_deepObject/explode_true/object/allOf",
|
||||
method => <<"GET">>,
|
||||
handler => 'openapi_query_handler'
|
||||
},
|
||||
'TestQueryStyleFormExplodeFalseArrayInteger' => #{
|
||||
'test/query/style_form/explode_false/array_integer' => #{
|
||||
servers => [],
|
||||
base_path => "",
|
||||
path => "/query/style_form/explode_false/array_integer",
|
||||
method => <<"GET">>,
|
||||
handler => 'openapi_query_handler'
|
||||
},
|
||||
'TestQueryStyleFormExplodeFalseArrayString' => #{
|
||||
'test/query/style_form/explode_false/array_string' => #{
|
||||
servers => [],
|
||||
base_path => "",
|
||||
path => "/query/style_form/explode_false/array_string",
|
||||
method => <<"GET">>,
|
||||
handler => 'openapi_query_handler'
|
||||
},
|
||||
'TestQueryStyleFormExplodeTrueArrayString' => #{
|
||||
'test/query/style_form/explode_true/array_string' => #{
|
||||
servers => [],
|
||||
base_path => "",
|
||||
path => "/query/style_form/explode_true/array_string",
|
||||
method => <<"GET">>,
|
||||
handler => 'openapi_query_handler'
|
||||
},
|
||||
'TestQueryStyleFormExplodeTrueObject' => #{
|
||||
'test/query/style_form/explode_true/object' => #{
|
||||
servers => [],
|
||||
base_path => "",
|
||||
path => "/query/style_form/explode_true/object",
|
||||
method => <<"GET">>,
|
||||
handler => 'openapi_query_handler'
|
||||
},
|
||||
'TestQueryStyleFormExplodeTrueObjectAllOf' => #{
|
||||
'test/query/style_form/explode_true/object/allOf' => #{
|
||||
servers => [],
|
||||
base_path => "",
|
||||
path => "/query/style_form/explode_true/object/allOf",
|
||||
|
@ -8,29 +8,32 @@ and `validate_response/4` respectively.
|
||||
|
||||
For example, the user-defined `Module:accept_callback/4` can be implemented as follows:
|
||||
```
|
||||
-spec accept_callback(atom(), openapi_api:operation_id(), cowboy_req:req(), context()) ->
|
||||
{cowboy:http_status(), cowboy:http_headers(), json:encode_value()}.
|
||||
accept_callback(Class, OperationID, Req, Context) ->
|
||||
-spec accept_callback(
|
||||
Class :: openapi_api:class(),
|
||||
OperationID :: openapi_api:operation_id(),
|
||||
Req :: cowboy_req:req(),
|
||||
Context :: openapi_logic_handler:context()) ->
|
||||
{openapi_logic_handler:accept_callback_return(),
|
||||
cowboy_req:req(),
|
||||
openapi_logic_handler:context()}.
|
||||
accept_callback(Class, OperationID, Req0, Context0) ->
|
||||
ValidatorState = openapi_api:prepare_validator(),
|
||||
case openapi_api:populate_request(OperationID, Req0, ValidatorState) of
|
||||
{ok, Populated, Req1} ->
|
||||
{Code, Headers, Body} = openapi_logic_handler:handle_request(
|
||||
LogicHandler,
|
||||
OperationID,
|
||||
Req1,
|
||||
maps:merge(State#state.context, Populated)
|
||||
),
|
||||
_ = openapi_api:validate_response(
|
||||
OperationID,
|
||||
Code,
|
||||
Body,
|
||||
ValidatorState
|
||||
),
|
||||
PreparedBody = prepare_body(Code, Body),
|
||||
Response = {ok, {Code, Headers, PreparedBody}},
|
||||
process_response(Response, Req1, State);
|
||||
{ok, Model, Req1} ->
|
||||
Context1 = maps:merge(Context0, Model),
|
||||
case do_accept_callback(Class, OperationID, Req1, Context1) of
|
||||
{false, Req2, Context2} ->
|
||||
{false, Req2, Context2};
|
||||
{{true, Code, Body}, Req2, Context2} ->
|
||||
case validate_response(OperationID, Code, Body, ValidatorState) of
|
||||
ok ->
|
||||
process_response({ok, Code, Body}, Req2, Context2);
|
||||
{error, Reason} ->
|
||||
process_response({error, Reason}, Req2, Context2)
|
||||
end
|
||||
end;
|
||||
{error, Reason, Req1} ->
|
||||
process_response({error, Reason}, Req1, State)
|
||||
process_response({error, Reason}, Req1, Context0)
|
||||
end.
|
||||
```
|
||||
""".
|
||||
@ -41,10 +44,38 @@ accept_callback(Class, OperationID, Req, Context) ->
|
||||
-ignore_xref([populate_request/3, validate_response/4]).
|
||||
-ignore_xref([prepare_validator/0, prepare_validator/1, prepare_validator/2]).
|
||||
|
||||
-type operation_id() :: atom().
|
||||
-type class() ::
|
||||
'pet'
|
||||
| 'store'
|
||||
| 'user'.
|
||||
|
||||
|
||||
-type operation_id() ::
|
||||
'addPet' | %% Add a new pet to the store
|
||||
'deletePet' | %% Deletes a pet
|
||||
'findPetsByStatus' | %% Finds Pets by status
|
||||
'findPetsByTags' | %% Finds Pets by tags
|
||||
'getPetById' | %% Find pet by ID
|
||||
'updatePet' | %% Update an existing pet
|
||||
'updatePetWithForm' | %% Updates a pet in the store with form data
|
||||
'uploadFile' | %% uploads an image
|
||||
'deleteOrder' | %% Delete purchase order by ID
|
||||
'getInventory' | %% Returns pet inventories by status
|
||||
'getOrderById' | %% Find purchase order by ID
|
||||
'placeOrder' | %% Place an order for a pet
|
||||
'createUser' | %% Create user
|
||||
'createUsersWithArrayInput' | %% Creates list of users with given input array
|
||||
'createUsersWithListInput' | %% Creates list of users with given input array
|
||||
'deleteUser' | %% Delete user
|
||||
'getUserByName' | %% Get user by user name
|
||||
'loginUser' | %% Logs user into the system
|
||||
'logoutUser' | %% Logs out current logged in user session
|
||||
'updateUser' | %% Updated user
|
||||
{error, unknown_operation}.
|
||||
|
||||
-type request_param() :: atom().
|
||||
|
||||
-export_type([operation_id/0]).
|
||||
-export_type([class/0, operation_id/0]).
|
||||
|
||||
-dialyzer({nowarn_function, [validate_response_body/4]}).
|
||||
|
||||
@ -64,6 +95,7 @@ accept_callback(Class, OperationID, Req, Context) ->
|
||||
{max_length, MaxLength :: integer()} |
|
||||
{min_length, MaxLength :: integer()} |
|
||||
{pattern, Pattern :: string()} |
|
||||
{schema, object | list, binary()} |
|
||||
schema |
|
||||
required |
|
||||
not_required.
|
||||
@ -111,166 +143,166 @@ for the `OperationID` operation.
|
||||
Body :: jesse:json_term(),
|
||||
ValidatorState :: jesse_state:state()) ->
|
||||
ok | {ok, term()} | [ok | {ok, term()}] | no_return().
|
||||
validate_response('AddPet', 200, Body, ValidatorState) ->
|
||||
validate_response('addPet', 200, Body, ValidatorState) ->
|
||||
validate_response_body('Pet', 'Pet', Body, ValidatorState);
|
||||
validate_response('AddPet', 405, Body, ValidatorState) ->
|
||||
validate_response('addPet', 405, Body, ValidatorState) ->
|
||||
validate_response_body('', '', Body, ValidatorState);
|
||||
validate_response('DeletePet', 400, Body, ValidatorState) ->
|
||||
validate_response('deletePet', 400, Body, ValidatorState) ->
|
||||
validate_response_body('', '', Body, ValidatorState);
|
||||
validate_response('FindPetsByStatus', 200, Body, ValidatorState) ->
|
||||
validate_response('findPetsByStatus', 200, Body, ValidatorState) ->
|
||||
validate_response_body('list', 'Pet', Body, ValidatorState);
|
||||
validate_response('FindPetsByStatus', 400, Body, ValidatorState) ->
|
||||
validate_response('findPetsByStatus', 400, Body, ValidatorState) ->
|
||||
validate_response_body('', '', Body, ValidatorState);
|
||||
validate_response('FindPetsByTags', 200, Body, ValidatorState) ->
|
||||
validate_response('findPetsByTags', 200, Body, ValidatorState) ->
|
||||
validate_response_body('list', 'Pet', Body, ValidatorState);
|
||||
validate_response('FindPetsByTags', 400, Body, ValidatorState) ->
|
||||
validate_response('findPetsByTags', 400, Body, ValidatorState) ->
|
||||
validate_response_body('', '', Body, ValidatorState);
|
||||
validate_response('GetPetById', 200, Body, ValidatorState) ->
|
||||
validate_response('getPetById', 200, Body, ValidatorState) ->
|
||||
validate_response_body('Pet', 'Pet', Body, ValidatorState);
|
||||
validate_response('GetPetById', 400, Body, ValidatorState) ->
|
||||
validate_response('getPetById', 400, Body, ValidatorState) ->
|
||||
validate_response_body('', '', Body, ValidatorState);
|
||||
validate_response('GetPetById', 404, Body, ValidatorState) ->
|
||||
validate_response('getPetById', 404, Body, ValidatorState) ->
|
||||
validate_response_body('', '', Body, ValidatorState);
|
||||
validate_response('UpdatePet', 200, Body, ValidatorState) ->
|
||||
validate_response('updatePet', 200, Body, ValidatorState) ->
|
||||
validate_response_body('Pet', 'Pet', Body, ValidatorState);
|
||||
validate_response('UpdatePet', 400, Body, ValidatorState) ->
|
||||
validate_response('updatePet', 400, Body, ValidatorState) ->
|
||||
validate_response_body('', '', Body, ValidatorState);
|
||||
validate_response('UpdatePet', 404, Body, ValidatorState) ->
|
||||
validate_response('updatePet', 404, Body, ValidatorState) ->
|
||||
validate_response_body('', '', Body, ValidatorState);
|
||||
validate_response('UpdatePet', 405, Body, ValidatorState) ->
|
||||
validate_response('updatePet', 405, Body, ValidatorState) ->
|
||||
validate_response_body('', '', Body, ValidatorState);
|
||||
validate_response('UpdatePetWithForm', 405, Body, ValidatorState) ->
|
||||
validate_response('updatePetWithForm', 405, Body, ValidatorState) ->
|
||||
validate_response_body('', '', Body, ValidatorState);
|
||||
validate_response('UploadFile', 200, Body, ValidatorState) ->
|
||||
validate_response('uploadFile', 200, Body, ValidatorState) ->
|
||||
validate_response_body('ApiResponse', 'ApiResponse', Body, ValidatorState);
|
||||
validate_response('DeleteOrder', 400, Body, ValidatorState) ->
|
||||
validate_response('deleteOrder', 400, Body, ValidatorState) ->
|
||||
validate_response_body('', '', Body, ValidatorState);
|
||||
validate_response('DeleteOrder', 404, Body, ValidatorState) ->
|
||||
validate_response('deleteOrder', 404, Body, ValidatorState) ->
|
||||
validate_response_body('', '', Body, ValidatorState);
|
||||
validate_response('GetInventory', 200, Body, ValidatorState) ->
|
||||
validate_response('getInventory', 200, Body, ValidatorState) ->
|
||||
validate_response_body('map', 'integer', Body, ValidatorState);
|
||||
validate_response('GetOrderById', 200, Body, ValidatorState) ->
|
||||
validate_response('getOrderById', 200, Body, ValidatorState) ->
|
||||
validate_response_body('Order', 'Order', Body, ValidatorState);
|
||||
validate_response('GetOrderById', 400, Body, ValidatorState) ->
|
||||
validate_response('getOrderById', 400, Body, ValidatorState) ->
|
||||
validate_response_body('', '', Body, ValidatorState);
|
||||
validate_response('GetOrderById', 404, Body, ValidatorState) ->
|
||||
validate_response('getOrderById', 404, Body, ValidatorState) ->
|
||||
validate_response_body('', '', Body, ValidatorState);
|
||||
validate_response('PlaceOrder', 200, Body, ValidatorState) ->
|
||||
validate_response('placeOrder', 200, Body, ValidatorState) ->
|
||||
validate_response_body('Order', 'Order', Body, ValidatorState);
|
||||
validate_response('PlaceOrder', 400, Body, ValidatorState) ->
|
||||
validate_response('placeOrder', 400, Body, ValidatorState) ->
|
||||
validate_response_body('', '', Body, ValidatorState);
|
||||
validate_response('CreateUser', 0, Body, ValidatorState) ->
|
||||
validate_response('createUser', 0, Body, ValidatorState) ->
|
||||
validate_response_body('', '', Body, ValidatorState);
|
||||
validate_response('CreateUsersWithArrayInput', 0, Body, ValidatorState) ->
|
||||
validate_response('createUsersWithArrayInput', 0, Body, ValidatorState) ->
|
||||
validate_response_body('', '', Body, ValidatorState);
|
||||
validate_response('CreateUsersWithListInput', 0, Body, ValidatorState) ->
|
||||
validate_response('createUsersWithListInput', 0, Body, ValidatorState) ->
|
||||
validate_response_body('', '', Body, ValidatorState);
|
||||
validate_response('DeleteUser', 400, Body, ValidatorState) ->
|
||||
validate_response('deleteUser', 400, Body, ValidatorState) ->
|
||||
validate_response_body('', '', Body, ValidatorState);
|
||||
validate_response('DeleteUser', 404, Body, ValidatorState) ->
|
||||
validate_response('deleteUser', 404, Body, ValidatorState) ->
|
||||
validate_response_body('', '', Body, ValidatorState);
|
||||
validate_response('GetUserByName', 200, Body, ValidatorState) ->
|
||||
validate_response('getUserByName', 200, Body, ValidatorState) ->
|
||||
validate_response_body('User', 'User', Body, ValidatorState);
|
||||
validate_response('GetUserByName', 400, Body, ValidatorState) ->
|
||||
validate_response('getUserByName', 400, Body, ValidatorState) ->
|
||||
validate_response_body('', '', Body, ValidatorState);
|
||||
validate_response('GetUserByName', 404, Body, ValidatorState) ->
|
||||
validate_response('getUserByName', 404, Body, ValidatorState) ->
|
||||
validate_response_body('', '', Body, ValidatorState);
|
||||
validate_response('LoginUser', 200, Body, ValidatorState) ->
|
||||
validate_response('loginUser', 200, Body, ValidatorState) ->
|
||||
validate_response_body('binary', 'string', Body, ValidatorState);
|
||||
validate_response('LoginUser', 400, Body, ValidatorState) ->
|
||||
validate_response('loginUser', 400, Body, ValidatorState) ->
|
||||
validate_response_body('', '', Body, ValidatorState);
|
||||
validate_response('LogoutUser', 0, Body, ValidatorState) ->
|
||||
validate_response('logoutUser', 0, Body, ValidatorState) ->
|
||||
validate_response_body('', '', Body, ValidatorState);
|
||||
validate_response('UpdateUser', 400, Body, ValidatorState) ->
|
||||
validate_response('updateUser', 400, Body, ValidatorState) ->
|
||||
validate_response_body('', '', Body, ValidatorState);
|
||||
validate_response('UpdateUser', 404, Body, ValidatorState) ->
|
||||
validate_response('updateUser', 404, Body, ValidatorState) ->
|
||||
validate_response_body('', '', Body, ValidatorState);
|
||||
validate_response(_OperationID, _Code, _Body, _ValidatorState) ->
|
||||
ok.
|
||||
|
||||
%%%
|
||||
-spec request_params(OperationID :: operation_id()) -> [Param :: request_param()].
|
||||
request_params('AddPet') ->
|
||||
request_params('addPet') ->
|
||||
[
|
||||
'Pet'
|
||||
];
|
||||
request_params('DeletePet') ->
|
||||
request_params('deletePet') ->
|
||||
[
|
||||
'petId',
|
||||
'api_key'
|
||||
];
|
||||
request_params('FindPetsByStatus') ->
|
||||
request_params('findPetsByStatus') ->
|
||||
[
|
||||
'status'
|
||||
];
|
||||
request_params('FindPetsByTags') ->
|
||||
request_params('findPetsByTags') ->
|
||||
[
|
||||
'tags'
|
||||
];
|
||||
request_params('GetPetById') ->
|
||||
request_params('getPetById') ->
|
||||
[
|
||||
'petId'
|
||||
];
|
||||
request_params('UpdatePet') ->
|
||||
request_params('updatePet') ->
|
||||
[
|
||||
'Pet'
|
||||
];
|
||||
request_params('UpdatePetWithForm') ->
|
||||
request_params('updatePetWithForm') ->
|
||||
[
|
||||
'petId',
|
||||
'name',
|
||||
'status'
|
||||
];
|
||||
request_params('UploadFile') ->
|
||||
request_params('uploadFile') ->
|
||||
[
|
||||
'petId',
|
||||
'additionalMetadata',
|
||||
'file'
|
||||
];
|
||||
request_params('DeleteOrder') ->
|
||||
request_params('deleteOrder') ->
|
||||
[
|
||||
'orderId'
|
||||
];
|
||||
request_params('GetInventory') ->
|
||||
request_params('getInventory') ->
|
||||
[
|
||||
];
|
||||
request_params('GetOrderById') ->
|
||||
request_params('getOrderById') ->
|
||||
[
|
||||
'orderId'
|
||||
];
|
||||
request_params('PlaceOrder') ->
|
||||
request_params('placeOrder') ->
|
||||
[
|
||||
'Order'
|
||||
];
|
||||
request_params('CreateUser') ->
|
||||
request_params('createUser') ->
|
||||
[
|
||||
'User'
|
||||
];
|
||||
request_params('CreateUsersWithArrayInput') ->
|
||||
request_params('createUsersWithArrayInput') ->
|
||||
[
|
||||
'list'
|
||||
'array'
|
||||
];
|
||||
request_params('CreateUsersWithListInput') ->
|
||||
request_params('createUsersWithListInput') ->
|
||||
[
|
||||
'list'
|
||||
'array'
|
||||
];
|
||||
request_params('DeleteUser') ->
|
||||
request_params('deleteUser') ->
|
||||
[
|
||||
'username'
|
||||
];
|
||||
request_params('GetUserByName') ->
|
||||
request_params('getUserByName') ->
|
||||
[
|
||||
'username'
|
||||
];
|
||||
request_params('LoginUser') ->
|
||||
request_params('loginUser') ->
|
||||
[
|
||||
'username',
|
||||
'password'
|
||||
];
|
||||
request_params('LogoutUser') ->
|
||||
request_params('logoutUser') ->
|
||||
[
|
||||
];
|
||||
request_params('UpdateUser') ->
|
||||
request_params('updateUser') ->
|
||||
[
|
||||
'username',
|
||||
'User'
|
||||
@ -280,15 +312,15 @@ request_params(_) ->
|
||||
|
||||
-spec request_param_info(OperationID :: operation_id(), Name :: request_param()) ->
|
||||
#{source => qs_val | binding | header | body, rules => [rule()]}.
|
||||
request_param_info('AddPet', 'Pet') ->
|
||||
request_param_info('addPet', 'Pet') ->
|
||||
#{
|
||||
source => body,
|
||||
rules => [
|
||||
schema,
|
||||
{schema, object, <<"#/components/schemas/Pet">>},
|
||||
required
|
||||
]
|
||||
};
|
||||
request_param_info('DeletePet', 'petId') ->
|
||||
request_param_info('deletePet', 'petId') ->
|
||||
#{
|
||||
source => binding,
|
||||
rules => [
|
||||
@ -296,7 +328,7 @@ request_param_info('DeletePet', 'petId') ->
|
||||
required
|
||||
]
|
||||
};
|
||||
request_param_info('DeletePet', 'api_key') ->
|
||||
request_param_info('deletePet', 'api_key') ->
|
||||
#{
|
||||
source => header,
|
||||
rules => [
|
||||
@ -304,7 +336,7 @@ request_param_info('DeletePet', 'api_key') ->
|
||||
not_required
|
||||
]
|
||||
};
|
||||
request_param_info('FindPetsByStatus', 'status') ->
|
||||
request_param_info('findPetsByStatus', 'status') ->
|
||||
#{
|
||||
source => qs_val,
|
||||
rules => [
|
||||
@ -312,14 +344,14 @@ request_param_info('FindPetsByStatus', 'status') ->
|
||||
required
|
||||
]
|
||||
};
|
||||
request_param_info('FindPetsByTags', 'tags') ->
|
||||
request_param_info('findPetsByTags', 'tags') ->
|
||||
#{
|
||||
source => qs_val,
|
||||
rules => [
|
||||
required
|
||||
]
|
||||
};
|
||||
request_param_info('GetPetById', 'petId') ->
|
||||
request_param_info('getPetById', 'petId') ->
|
||||
#{
|
||||
source => binding,
|
||||
rules => [
|
||||
@ -327,15 +359,15 @@ request_param_info('GetPetById', 'petId') ->
|
||||
required
|
||||
]
|
||||
};
|
||||
request_param_info('UpdatePet', 'Pet') ->
|
||||
request_param_info('updatePet', 'Pet') ->
|
||||
#{
|
||||
source => body,
|
||||
rules => [
|
||||
schema,
|
||||
{schema, object, <<"#/components/schemas/Pet">>},
|
||||
required
|
||||
]
|
||||
};
|
||||
request_param_info('UpdatePetWithForm', 'petId') ->
|
||||
request_param_info('updatePetWithForm', 'petId') ->
|
||||
#{
|
||||
source => binding,
|
||||
rules => [
|
||||
@ -343,7 +375,7 @@ request_param_info('UpdatePetWithForm', 'petId') ->
|
||||
required
|
||||
]
|
||||
};
|
||||
request_param_info('UpdatePetWithForm', 'name') ->
|
||||
request_param_info('updatePetWithForm', 'name') ->
|
||||
#{
|
||||
source => body,
|
||||
rules => [
|
||||
@ -351,7 +383,7 @@ request_param_info('UpdatePetWithForm', 'name') ->
|
||||
not_required
|
||||
]
|
||||
};
|
||||
request_param_info('UpdatePetWithForm', 'status') ->
|
||||
request_param_info('updatePetWithForm', 'status') ->
|
||||
#{
|
||||
source => body,
|
||||
rules => [
|
||||
@ -359,7 +391,7 @@ request_param_info('UpdatePetWithForm', 'status') ->
|
||||
not_required
|
||||
]
|
||||
};
|
||||
request_param_info('UploadFile', 'petId') ->
|
||||
request_param_info('uploadFile', 'petId') ->
|
||||
#{
|
||||
source => binding,
|
||||
rules => [
|
||||
@ -367,7 +399,7 @@ request_param_info('UploadFile', 'petId') ->
|
||||
required
|
||||
]
|
||||
};
|
||||
request_param_info('UploadFile', 'additionalMetadata') ->
|
||||
request_param_info('uploadFile', 'additionalMetadata') ->
|
||||
#{
|
||||
source => body,
|
||||
rules => [
|
||||
@ -375,7 +407,7 @@ request_param_info('UploadFile', 'additionalMetadata') ->
|
||||
not_required
|
||||
]
|
||||
};
|
||||
request_param_info('UploadFile', 'file') ->
|
||||
request_param_info('uploadFile', 'file') ->
|
||||
#{
|
||||
source => body,
|
||||
rules => [
|
||||
@ -383,7 +415,7 @@ request_param_info('UploadFile', 'file') ->
|
||||
not_required
|
||||
]
|
||||
};
|
||||
request_param_info('DeleteOrder', 'orderId') ->
|
||||
request_param_info('deleteOrder', 'orderId') ->
|
||||
#{
|
||||
source => binding,
|
||||
rules => [
|
||||
@ -391,7 +423,7 @@ request_param_info('DeleteOrder', 'orderId') ->
|
||||
required
|
||||
]
|
||||
};
|
||||
request_param_info('GetOrderById', 'orderId') ->
|
||||
request_param_info('getOrderById', 'orderId') ->
|
||||
#{
|
||||
source => binding,
|
||||
rules => [
|
||||
@ -401,39 +433,39 @@ request_param_info('GetOrderById', 'orderId') ->
|
||||
required
|
||||
]
|
||||
};
|
||||
request_param_info('PlaceOrder', 'Order') ->
|
||||
request_param_info('placeOrder', 'Order') ->
|
||||
#{
|
||||
source => body,
|
||||
rules => [
|
||||
schema,
|
||||
{schema, object, <<"#/components/schemas/Order">>},
|
||||
required
|
||||
]
|
||||
};
|
||||
request_param_info('CreateUser', 'User') ->
|
||||
request_param_info('createUser', 'User') ->
|
||||
#{
|
||||
source => body,
|
||||
rules => [
|
||||
schema,
|
||||
{schema, object, <<"#/components/schemas/User">>},
|
||||
required
|
||||
]
|
||||
};
|
||||
request_param_info('CreateUsersWithArrayInput', 'list') ->
|
||||
request_param_info('createUsersWithArrayInput', 'array') ->
|
||||
#{
|
||||
source => body,
|
||||
rules => [
|
||||
schema,
|
||||
{schema, list, <<"#/components/schemas/User">>},
|
||||
required
|
||||
]
|
||||
};
|
||||
request_param_info('CreateUsersWithListInput', 'list') ->
|
||||
request_param_info('createUsersWithListInput', 'array') ->
|
||||
#{
|
||||
source => body,
|
||||
rules => [
|
||||
schema,
|
||||
{schema, list, <<"#/components/schemas/User">>},
|
||||
required
|
||||
]
|
||||
};
|
||||
request_param_info('DeleteUser', 'username') ->
|
||||
request_param_info('deleteUser', 'username') ->
|
||||
#{
|
||||
source => binding,
|
||||
rules => [
|
||||
@ -441,7 +473,7 @@ request_param_info('DeleteUser', 'username') ->
|
||||
required
|
||||
]
|
||||
};
|
||||
request_param_info('GetUserByName', 'username') ->
|
||||
request_param_info('getUserByName', 'username') ->
|
||||
#{
|
||||
source => binding,
|
||||
rules => [
|
||||
@ -449,7 +481,7 @@ request_param_info('GetUserByName', 'username') ->
|
||||
required
|
||||
]
|
||||
};
|
||||
request_param_info('LoginUser', 'username') ->
|
||||
request_param_info('loginUser', 'username') ->
|
||||
#{
|
||||
source => qs_val,
|
||||
rules => [
|
||||
@ -458,7 +490,7 @@ request_param_info('LoginUser', 'username') ->
|
||||
required
|
||||
]
|
||||
};
|
||||
request_param_info('LoginUser', 'password') ->
|
||||
request_param_info('loginUser', 'password') ->
|
||||
#{
|
||||
source => qs_val,
|
||||
rules => [
|
||||
@ -466,7 +498,7 @@ request_param_info('LoginUser', 'password') ->
|
||||
required
|
||||
]
|
||||
};
|
||||
request_param_info('UpdateUser', 'username') ->
|
||||
request_param_info('updateUser', 'username') ->
|
||||
#{
|
||||
source => binding,
|
||||
rules => [
|
||||
@ -474,11 +506,11 @@ request_param_info('UpdateUser', 'username') ->
|
||||
required
|
||||
]
|
||||
};
|
||||
request_param_info('UpdateUser', 'User') ->
|
||||
request_param_info('updateUser', 'User') ->
|
||||
#{
|
||||
source => body,
|
||||
rules => [
|
||||
schema,
|
||||
{schema, object, <<"#/components/schemas/User">>},
|
||||
required
|
||||
]
|
||||
};
|
||||
@ -515,8 +547,6 @@ populate_request_param(OperationID, ReqParamName, Req0, ValidatorState) ->
|
||||
end
|
||||
end.
|
||||
|
||||
-include_lib("kernel/include/logger.hrl").
|
||||
|
||||
validate_response_body(list, ReturnBaseType, Body, ValidatorState) ->
|
||||
[
|
||||
validate(schema, Item, ReturnBaseType, ValidatorState)
|
||||
@ -607,8 +637,15 @@ validate(Rule = {pattern, Pattern}, Value, ReqParamName, _) ->
|
||||
{match, _} -> ok;
|
||||
_ -> validation_error(Rule, ReqParamName, Value)
|
||||
end;
|
||||
validate(Rule = schema, Value, ReqParamName, ValidatorState) ->
|
||||
validate(schema, Value, ReqParamName, ValidatorState) ->
|
||||
Definition = iolist_to_binary(["#/components/schemas/", atom_to_binary(ReqParamName, utf8)]),
|
||||
validate({schema, object, Definition}, Value, ReqParamName, ValidatorState);
|
||||
validate({schema, list, Definition}, Value, ReqParamName, ValidatorState) ->
|
||||
lists:foreach(
|
||||
fun(Item) ->
|
||||
validate({schema, object, Definition}, Item, ReqParamName, ValidatorState)
|
||||
end, Value);
|
||||
validate(Rule = {schema, object, Definition}, Value, ReqParamName, ValidatorState) ->
|
||||
try
|
||||
_ = validate_with_schema(Value, Definition, ValidatorState),
|
||||
ok
|
||||
|
@ -11,10 +11,10 @@
|
||||
-type api_key_callback() ::
|
||||
fun((openapi_api:operation_id(), binary()) -> {true, context()} | {false, iodata()}).
|
||||
-type accept_callback() ::
|
||||
fun((atom(), openapi_api:operation_id(), cowboy_req:req(), context()) ->
|
||||
fun((openapi_api:class(), openapi_api:operation_id(), cowboy_req:req(), context()) ->
|
||||
{accept_callback_return(), cowboy_req:req(), context()}).
|
||||
-type provide_callback() ::
|
||||
fun((atom(), openapi_api:operation_id(), cowboy_req:req(), context()) ->
|
||||
fun((openapi_api:class(), openapi_api:operation_id(), cowboy_req:req(), context()) ->
|
||||
{cowboy_req:resp_body(), cowboy_req:req(), context()}).
|
||||
-type context() :: #{_ := _}.
|
||||
|
||||
@ -26,10 +26,10 @@
|
||||
-callback api_key_callback(openapi_api:operation_id(), binary()) ->
|
||||
{true, context()} | {false, iodata()}.
|
||||
|
||||
-callback accept_callback(atom(), openapi_api:operation_id(), cowboy_req:req(), context()) ->
|
||||
-callback accept_callback(openapi_api:class(), openapi_api:operation_id(), cowboy_req:req(), context()) ->
|
||||
{accept_callback_return(), cowboy_req:req(), context()}.
|
||||
|
||||
-callback provide_callback(atom(), openapi_api:operation_id(), cowboy_req:req(), context()) ->
|
||||
-callback provide_callback(openapi_api:class(), openapi_api:operation_id(), cowboy_req:req(), context()) ->
|
||||
{cowboy_req:resp_body(), cowboy_req:req(), context()}.
|
||||
|
||||
-export([api_key_callback/2, accept_callback/4, provide_callback/4]).
|
||||
@ -42,7 +42,7 @@ api_key_callback(OperationID, ApiKey) ->
|
||||
api_key => ApiKey}),
|
||||
{true, #{}}.
|
||||
|
||||
-spec accept_callback(atom(), openapi_api:operation_id(), cowboy_req:req(), context()) ->
|
||||
-spec accept_callback(openapi_api:class(), openapi_api:operation_id(), cowboy_req:req(), context()) ->
|
||||
{accept_callback_return(), cowboy_req:req(), context()}.
|
||||
accept_callback(Class, OperationID, Req, Context) ->
|
||||
?LOG_ERROR(#{what => "Got not implemented request to process",
|
||||
@ -52,7 +52,7 @@ accept_callback(Class, OperationID, Req, Context) ->
|
||||
context => Context}),
|
||||
{false, Req, Context}.
|
||||
|
||||
-spec provide_callback(atom(), openapi_api:operation_id(), cowboy_req:req(), context()) ->
|
||||
-spec provide_callback(openapi_api:class(), openapi_api:operation_id(), cowboy_req:req(), context()) ->
|
||||
{cowboy_req:resp_body(), cowboy_req:req(), context()}.
|
||||
provide_callback(Class, OperationID, Req, Context) ->
|
||||
?LOG_ERROR(#{what => "Got not implemented request to process",
|
||||
|
@ -2,30 +2,38 @@
|
||||
-moduledoc """
|
||||
Exposes the following operation IDs:
|
||||
|
||||
- `POST` to `/pet`, OperationId: `AddPet`:
|
||||
- `POST` to `/pet`, OperationId: `addPet`:
|
||||
Add a new pet to the store.
|
||||
|
||||
- `DELETE` to `/pet/:petId`, OperationId: `DeletePet`:
|
||||
|
||||
- `DELETE` to `/pet/:petId`, OperationId: `deletePet`:
|
||||
Deletes a pet.
|
||||
|
||||
- `GET` to `/pet/findByStatus`, OperationId: `FindPetsByStatus`:
|
||||
|
||||
- `GET` to `/pet/findByStatus`, OperationId: `findPetsByStatus`:
|
||||
Finds Pets by status.
|
||||
Multiple status values can be provided with comma separated strings
|
||||
|
||||
- `GET` to `/pet/findByTags`, OperationId: `FindPetsByTags`:
|
||||
- `GET` to `/pet/findByTags`, OperationId: `findPetsByTags`:
|
||||
Finds Pets by tags.
|
||||
Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
||||
|
||||
- `GET` to `/pet/:petId`, OperationId: `GetPetById`:
|
||||
- `GET` to `/pet/:petId`, OperationId: `getPetById`:
|
||||
Find pet by ID.
|
||||
Returns a single pet
|
||||
|
||||
- `PUT` to `/pet`, OperationId: `UpdatePet`:
|
||||
- `PUT` to `/pet`, OperationId: `updatePet`:
|
||||
Update an existing pet.
|
||||
|
||||
- `POST` to `/pet/:petId`, OperationId: `UpdatePetWithForm`:
|
||||
|
||||
- `POST` to `/pet/:petId`, OperationId: `updatePetWithForm`:
|
||||
Updates a pet in the store with form data.
|
||||
|
||||
- `POST` to `/pet/:petId/uploadImage`, OperationId: `UploadFile`:
|
||||
|
||||
- `POST` to `/pet/:petId/uploadImage`, OperationId: `uploadFile`:
|
||||
uploads an image.
|
||||
|
||||
|
||||
""".
|
||||
|
||||
-behaviour(cowboy_rest).
|
||||
@ -44,8 +52,23 @@ uploads an image.
|
||||
|
||||
-ignore_xref([handle_type_accepted/2, handle_type_provided/2]).
|
||||
|
||||
-export_type([class/0, operation_id/0]).
|
||||
|
||||
-type class() :: 'pet'.
|
||||
|
||||
-type operation_id() ::
|
||||
'addPet' %% Add a new pet to the store
|
||||
| 'deletePet' %% Deletes a pet
|
||||
| 'findPetsByStatus' %% Finds Pets by status
|
||||
| 'findPetsByTags' %% Finds Pets by tags
|
||||
| 'getPetById' %% Find pet by ID
|
||||
| 'updatePet' %% Update an existing pet
|
||||
| 'updatePetWithForm' %% Updates a pet in the store with form data
|
||||
| 'uploadFile'. %% uploads an image
|
||||
|
||||
|
||||
-record(state,
|
||||
{operation_id :: openapi_api:operation_id(),
|
||||
{operation_id :: operation_id(),
|
||||
accept_callback :: openapi_logic_handler:accept_callback(),
|
||||
provide_callback :: openapi_logic_handler:provide_callback(),
|
||||
api_key_handler :: openapi_logic_handler:api_key_callback(),
|
||||
@ -69,21 +92,21 @@ init(Req, {Operations, Module}) ->
|
||||
|
||||
-spec allowed_methods(cowboy_req:req(), state()) ->
|
||||
{[binary()], cowboy_req:req(), state()}.
|
||||
allowed_methods(Req, #state{operation_id = 'AddPet'} = State) ->
|
||||
allowed_methods(Req, #state{operation_id = 'addPet'} = State) ->
|
||||
{[<<"POST">>], Req, State};
|
||||
allowed_methods(Req, #state{operation_id = 'DeletePet'} = State) ->
|
||||
allowed_methods(Req, #state{operation_id = 'deletePet'} = State) ->
|
||||
{[<<"DELETE">>], Req, State};
|
||||
allowed_methods(Req, #state{operation_id = 'FindPetsByStatus'} = State) ->
|
||||
allowed_methods(Req, #state{operation_id = 'findPetsByStatus'} = State) ->
|
||||
{[<<"GET">>], Req, State};
|
||||
allowed_methods(Req, #state{operation_id = 'FindPetsByTags'} = State) ->
|
||||
allowed_methods(Req, #state{operation_id = 'findPetsByTags'} = State) ->
|
||||
{[<<"GET">>], Req, State};
|
||||
allowed_methods(Req, #state{operation_id = 'GetPetById'} = State) ->
|
||||
allowed_methods(Req, #state{operation_id = 'getPetById'} = State) ->
|
||||
{[<<"GET">>], Req, State};
|
||||
allowed_methods(Req, #state{operation_id = 'UpdatePet'} = State) ->
|
||||
allowed_methods(Req, #state{operation_id = 'updatePet'} = State) ->
|
||||
{[<<"PUT">>], Req, State};
|
||||
allowed_methods(Req, #state{operation_id = 'UpdatePetWithForm'} = State) ->
|
||||
allowed_methods(Req, #state{operation_id = 'updatePetWithForm'} = State) ->
|
||||
{[<<"POST">>], Req, State};
|
||||
allowed_methods(Req, #state{operation_id = 'UploadFile'} = State) ->
|
||||
allowed_methods(Req, #state{operation_id = 'uploadFile'} = State) ->
|
||||
{[<<"POST">>], Req, State};
|
||||
allowed_methods(Req, State) ->
|
||||
{[], Req, State}.
|
||||
@ -91,7 +114,7 @@ allowed_methods(Req, State) ->
|
||||
-spec is_authorized(cowboy_req:req(), state()) ->
|
||||
{true | {false, iodata()}, cowboy_req:req(), state()}.
|
||||
is_authorized(Req0,
|
||||
#state{operation_id = 'AddPet' = OperationID,
|
||||
#state{operation_id = 'addPet' = OperationID,
|
||||
api_key_handler = Handler} = State) ->
|
||||
case openapi_auth:authorize_api_key(Handler, OperationID, header, "authorization", Req0) of
|
||||
{true, Context, Req} ->
|
||||
@ -100,7 +123,7 @@ is_authorized(Req0,
|
||||
{{false, AuthHeader}, Req, State}
|
||||
end;
|
||||
is_authorized(Req0,
|
||||
#state{operation_id = 'DeletePet' = OperationID,
|
||||
#state{operation_id = 'deletePet' = OperationID,
|
||||
api_key_handler = Handler} = State) ->
|
||||
case openapi_auth:authorize_api_key(Handler, OperationID, header, "authorization", Req0) of
|
||||
{true, Context, Req} ->
|
||||
@ -109,7 +132,7 @@ is_authorized(Req0,
|
||||
{{false, AuthHeader}, Req, State}
|
||||
end;
|
||||
is_authorized(Req0,
|
||||
#state{operation_id = 'FindPetsByStatus' = OperationID,
|
||||
#state{operation_id = 'findPetsByStatus' = OperationID,
|
||||
api_key_handler = Handler} = State) ->
|
||||
case openapi_auth:authorize_api_key(Handler, OperationID, header, "authorization", Req0) of
|
||||
{true, Context, Req} ->
|
||||
@ -118,7 +141,7 @@ is_authorized(Req0,
|
||||
{{false, AuthHeader}, Req, State}
|
||||
end;
|
||||
is_authorized(Req0,
|
||||
#state{operation_id = 'FindPetsByTags' = OperationID,
|
||||
#state{operation_id = 'findPetsByTags' = OperationID,
|
||||
api_key_handler = Handler} = State) ->
|
||||
case openapi_auth:authorize_api_key(Handler, OperationID, header, "authorization", Req0) of
|
||||
{true, Context, Req} ->
|
||||
@ -127,7 +150,7 @@ is_authorized(Req0,
|
||||
{{false, AuthHeader}, Req, State}
|
||||
end;
|
||||
is_authorized(Req0,
|
||||
#state{operation_id = 'GetPetById' = OperationID,
|
||||
#state{operation_id = 'getPetById' = OperationID,
|
||||
api_key_handler = Handler} = State) ->
|
||||
case openapi_auth:authorize_api_key(Handler, OperationID, header, "authorization", Req0) of
|
||||
{true, Context, Req} ->
|
||||
@ -136,7 +159,7 @@ is_authorized(Req0,
|
||||
{{false, AuthHeader}, Req, State}
|
||||
end;
|
||||
is_authorized(Req0,
|
||||
#state{operation_id = 'UpdatePet' = OperationID,
|
||||
#state{operation_id = 'updatePet' = OperationID,
|
||||
api_key_handler = Handler} = State) ->
|
||||
case openapi_auth:authorize_api_key(Handler, OperationID, header, "authorization", Req0) of
|
||||
{true, Context, Req} ->
|
||||
@ -145,7 +168,7 @@ is_authorized(Req0,
|
||||
{{false, AuthHeader}, Req, State}
|
||||
end;
|
||||
is_authorized(Req0,
|
||||
#state{operation_id = 'UpdatePetWithForm' = OperationID,
|
||||
#state{operation_id = 'updatePetWithForm' = OperationID,
|
||||
api_key_handler = Handler} = State) ->
|
||||
case openapi_auth:authorize_api_key(Handler, OperationID, header, "authorization", Req0) of
|
||||
{true, Context, Req} ->
|
||||
@ -154,7 +177,7 @@ is_authorized(Req0,
|
||||
{{false, AuthHeader}, Req, State}
|
||||
end;
|
||||
is_authorized(Req0,
|
||||
#state{operation_id = 'UploadFile' = OperationID,
|
||||
#state{operation_id = 'uploadFile' = OperationID,
|
||||
api_key_handler = Handler} = State) ->
|
||||
case openapi_auth:authorize_api_key(Handler, OperationID, header, "authorization", Req0) of
|
||||
{true, Context, Req} ->
|
||||
@ -167,29 +190,29 @@ is_authorized(Req, State) ->
|
||||
|
||||
-spec content_types_accepted(cowboy_req:req(), state()) ->
|
||||
{[{binary(), atom()}], cowboy_req:req(), state()}.
|
||||
content_types_accepted(Req, #state{operation_id = 'AddPet'} = State) ->
|
||||
content_types_accepted(Req, #state{operation_id = 'addPet'} = State) ->
|
||||
{[
|
||||
{<<"application/json">>, handle_type_accepted},
|
||||
{<<"application/xml">>, handle_type_accepted}
|
||||
], Req, State};
|
||||
content_types_accepted(Req, #state{operation_id = 'DeletePet'} = State) ->
|
||||
content_types_accepted(Req, #state{operation_id = 'deletePet'} = State) ->
|
||||
{[], Req, State};
|
||||
content_types_accepted(Req, #state{operation_id = 'FindPetsByStatus'} = State) ->
|
||||
content_types_accepted(Req, #state{operation_id = 'findPetsByStatus'} = State) ->
|
||||
{[], Req, State};
|
||||
content_types_accepted(Req, #state{operation_id = 'FindPetsByTags'} = State) ->
|
||||
content_types_accepted(Req, #state{operation_id = 'findPetsByTags'} = State) ->
|
||||
{[], Req, State};
|
||||
content_types_accepted(Req, #state{operation_id = 'GetPetById'} = State) ->
|
||||
content_types_accepted(Req, #state{operation_id = 'getPetById'} = State) ->
|
||||
{[], Req, State};
|
||||
content_types_accepted(Req, #state{operation_id = 'UpdatePet'} = State) ->
|
||||
content_types_accepted(Req, #state{operation_id = 'updatePet'} = State) ->
|
||||
{[
|
||||
{<<"application/json">>, handle_type_accepted},
|
||||
{<<"application/xml">>, handle_type_accepted}
|
||||
], Req, State};
|
||||
content_types_accepted(Req, #state{operation_id = 'UpdatePetWithForm'} = State) ->
|
||||
content_types_accepted(Req, #state{operation_id = 'updatePetWithForm'} = State) ->
|
||||
{[
|
||||
{<<"application/x-www-form-urlencoded">>, handle_type_accepted}
|
||||
], Req, State};
|
||||
content_types_accepted(Req, #state{operation_id = 'UploadFile'} = State) ->
|
||||
content_types_accepted(Req, #state{operation_id = 'uploadFile'} = State) ->
|
||||
{[
|
||||
{<<"multipart/form-data">>, handle_type_accepted}
|
||||
], Req, State};
|
||||
@ -198,57 +221,57 @@ content_types_accepted(Req, State) ->
|
||||
|
||||
-spec valid_content_headers(cowboy_req:req(), state()) ->
|
||||
{boolean(), cowboy_req:req(), state()}.
|
||||
valid_content_headers(Req, #state{operation_id = 'AddPet'} = State) ->
|
||||
valid_content_headers(Req, #state{operation_id = 'addPet'} = State) ->
|
||||
{true, Req, State};
|
||||
valid_content_headers(Req, #state{operation_id = 'DeletePet'} = State) ->
|
||||
valid_content_headers(Req, #state{operation_id = 'deletePet'} = State) ->
|
||||
{true, Req, State};
|
||||
valid_content_headers(Req, #state{operation_id = 'FindPetsByStatus'} = State) ->
|
||||
valid_content_headers(Req, #state{operation_id = 'findPetsByStatus'} = State) ->
|
||||
{true, Req, State};
|
||||
valid_content_headers(Req, #state{operation_id = 'FindPetsByTags'} = State) ->
|
||||
valid_content_headers(Req, #state{operation_id = 'findPetsByTags'} = State) ->
|
||||
{true, Req, State};
|
||||
valid_content_headers(Req, #state{operation_id = 'GetPetById'} = State) ->
|
||||
valid_content_headers(Req, #state{operation_id = 'getPetById'} = State) ->
|
||||
{true, Req, State};
|
||||
valid_content_headers(Req, #state{operation_id = 'UpdatePet'} = State) ->
|
||||
valid_content_headers(Req, #state{operation_id = 'updatePet'} = State) ->
|
||||
{true, Req, State};
|
||||
valid_content_headers(Req, #state{operation_id = 'UpdatePetWithForm'} = State) ->
|
||||
valid_content_headers(Req, #state{operation_id = 'updatePetWithForm'} = State) ->
|
||||
{true, Req, State};
|
||||
valid_content_headers(Req, #state{operation_id = 'UploadFile'} = State) ->
|
||||
valid_content_headers(Req, #state{operation_id = 'uploadFile'} = State) ->
|
||||
{true, Req, State};
|
||||
valid_content_headers(Req, State) ->
|
||||
{false, Req, State}.
|
||||
|
||||
-spec content_types_provided(cowboy_req:req(), state()) ->
|
||||
{[{binary(), atom()}], cowboy_req:req(), state()}.
|
||||
content_types_provided(Req, #state{operation_id = 'AddPet'} = State) ->
|
||||
content_types_provided(Req, #state{operation_id = 'addPet'} = State) ->
|
||||
{[
|
||||
{<<"application/xml">>, handle_type_provided},
|
||||
{<<"application/json">>, handle_type_provided}
|
||||
], Req, State};
|
||||
content_types_provided(Req, #state{operation_id = 'DeletePet'} = State) ->
|
||||
content_types_provided(Req, #state{operation_id = 'deletePet'} = State) ->
|
||||
{[], Req, State};
|
||||
content_types_provided(Req, #state{operation_id = 'FindPetsByStatus'} = State) ->
|
||||
content_types_provided(Req, #state{operation_id = 'findPetsByStatus'} = State) ->
|
||||
{[
|
||||
{<<"application/xml">>, handle_type_provided},
|
||||
{<<"application/json">>, handle_type_provided}
|
||||
], Req, State};
|
||||
content_types_provided(Req, #state{operation_id = 'FindPetsByTags'} = State) ->
|
||||
content_types_provided(Req, #state{operation_id = 'findPetsByTags'} = State) ->
|
||||
{[
|
||||
{<<"application/xml">>, handle_type_provided},
|
||||
{<<"application/json">>, handle_type_provided}
|
||||
], Req, State};
|
||||
content_types_provided(Req, #state{operation_id = 'GetPetById'} = State) ->
|
||||
content_types_provided(Req, #state{operation_id = 'getPetById'} = State) ->
|
||||
{[
|
||||
{<<"application/xml">>, handle_type_provided},
|
||||
{<<"application/json">>, handle_type_provided}
|
||||
], Req, State};
|
||||
content_types_provided(Req, #state{operation_id = 'UpdatePet'} = State) ->
|
||||
content_types_provided(Req, #state{operation_id = 'updatePet'} = State) ->
|
||||
{[
|
||||
{<<"application/xml">>, handle_type_provided},
|
||||
{<<"application/json">>, handle_type_provided}
|
||||
], Req, State};
|
||||
content_types_provided(Req, #state{operation_id = 'UpdatePetWithForm'} = State) ->
|
||||
content_types_provided(Req, #state{operation_id = 'updatePetWithForm'} = State) ->
|
||||
{[], Req, State};
|
||||
content_types_provided(Req, #state{operation_id = 'UploadFile'} = State) ->
|
||||
content_types_provided(Req, #state{operation_id = 'uploadFile'} = State) ->
|
||||
{[
|
||||
{<<"application/json">>, handle_type_provided}
|
||||
], Req, State};
|
||||
@ -258,8 +281,8 @@ content_types_provided(Req, State) ->
|
||||
-spec delete_resource(cowboy_req:req(), state()) ->
|
||||
{boolean(), cowboy_req:req(), state()}.
|
||||
delete_resource(Req, State) ->
|
||||
{Res, Req1, State} = handle_type_accepted(Req, State),
|
||||
{true =:= Res, Req1, State}.
|
||||
{Res, Req1, State1} = handle_type_accepted(Req, State),
|
||||
{true =:= Res, Req1, State1}.
|
||||
|
||||
-spec handle_type_accepted(cowboy_req:req(), state()) ->
|
||||
{ openapi_logic_handler:accept_callback_return(), cowboy_req:req(), state()}.
|
||||
|
@ -47,140 +47,140 @@ merge_paths(FullPaths, OperationID, Method, Handler, Acc) ->
|
||||
|
||||
get_operations() ->
|
||||
#{
|
||||
'AddPet' => #{
|
||||
'addPet' => #{
|
||||
servers => [],
|
||||
base_path => "/v2",
|
||||
path => "/pet",
|
||||
method => <<"POST">>,
|
||||
handler => 'openapi_pet_handler'
|
||||
},
|
||||
'DeletePet' => #{
|
||||
'deletePet' => #{
|
||||
servers => [],
|
||||
base_path => "/v2",
|
||||
path => "/pet/:petId",
|
||||
method => <<"DELETE">>,
|
||||
handler => 'openapi_pet_handler'
|
||||
},
|
||||
'FindPetsByStatus' => #{
|
||||
'findPetsByStatus' => #{
|
||||
servers => [],
|
||||
base_path => "/v2",
|
||||
path => "/pet/findByStatus",
|
||||
method => <<"GET">>,
|
||||
handler => 'openapi_pet_handler'
|
||||
},
|
||||
'FindPetsByTags' => #{
|
||||
'findPetsByTags' => #{
|
||||
servers => [],
|
||||
base_path => "/v2",
|
||||
path => "/pet/findByTags",
|
||||
method => <<"GET">>,
|
||||
handler => 'openapi_pet_handler'
|
||||
},
|
||||
'GetPetById' => #{
|
||||
'getPetById' => #{
|
||||
servers => [],
|
||||
base_path => "/v2",
|
||||
path => "/pet/:petId",
|
||||
method => <<"GET">>,
|
||||
handler => 'openapi_pet_handler'
|
||||
},
|
||||
'UpdatePet' => #{
|
||||
'updatePet' => #{
|
||||
servers => [],
|
||||
base_path => "/v2",
|
||||
path => "/pet",
|
||||
method => <<"PUT">>,
|
||||
handler => 'openapi_pet_handler'
|
||||
},
|
||||
'UpdatePetWithForm' => #{
|
||||
'updatePetWithForm' => #{
|
||||
servers => [],
|
||||
base_path => "/v2",
|
||||
path => "/pet/:petId",
|
||||
method => <<"POST">>,
|
||||
handler => 'openapi_pet_handler'
|
||||
},
|
||||
'UploadFile' => #{
|
||||
'uploadFile' => #{
|
||||
servers => [],
|
||||
base_path => "/v2",
|
||||
path => "/pet/:petId/uploadImage",
|
||||
method => <<"POST">>,
|
||||
handler => 'openapi_pet_handler'
|
||||
},
|
||||
'DeleteOrder' => #{
|
||||
'deleteOrder' => #{
|
||||
servers => [],
|
||||
base_path => "/v2",
|
||||
path => "/store/order/:orderId",
|
||||
method => <<"DELETE">>,
|
||||
handler => 'openapi_store_handler'
|
||||
},
|
||||
'GetInventory' => #{
|
||||
'getInventory' => #{
|
||||
servers => [],
|
||||
base_path => "/v2",
|
||||
path => "/store/inventory",
|
||||
method => <<"GET">>,
|
||||
handler => 'openapi_store_handler'
|
||||
},
|
||||
'GetOrderById' => #{
|
||||
'getOrderById' => #{
|
||||
servers => [],
|
||||
base_path => "/v2",
|
||||
path => "/store/order/:orderId",
|
||||
method => <<"GET">>,
|
||||
handler => 'openapi_store_handler'
|
||||
},
|
||||
'PlaceOrder' => #{
|
||||
'placeOrder' => #{
|
||||
servers => [],
|
||||
base_path => "/v2",
|
||||
path => "/store/order",
|
||||
method => <<"POST">>,
|
||||
handler => 'openapi_store_handler'
|
||||
},
|
||||
'CreateUser' => #{
|
||||
'createUser' => #{
|
||||
servers => [],
|
||||
base_path => "/v2",
|
||||
path => "/user",
|
||||
method => <<"POST">>,
|
||||
handler => 'openapi_user_handler'
|
||||
},
|
||||
'CreateUsersWithArrayInput' => #{
|
||||
'createUsersWithArrayInput' => #{
|
||||
servers => [],
|
||||
base_path => "/v2",
|
||||
path => "/user/createWithArray",
|
||||
method => <<"POST">>,
|
||||
handler => 'openapi_user_handler'
|
||||
},
|
||||
'CreateUsersWithListInput' => #{
|
||||
'createUsersWithListInput' => #{
|
||||
servers => [],
|
||||
base_path => "/v2",
|
||||
path => "/user/createWithList",
|
||||
method => <<"POST">>,
|
||||
handler => 'openapi_user_handler'
|
||||
},
|
||||
'DeleteUser' => #{
|
||||
'deleteUser' => #{
|
||||
servers => [],
|
||||
base_path => "/v2",
|
||||
path => "/user/:username",
|
||||
method => <<"DELETE">>,
|
||||
handler => 'openapi_user_handler'
|
||||
},
|
||||
'GetUserByName' => #{
|
||||
'getUserByName' => #{
|
||||
servers => [],
|
||||
base_path => "/v2",
|
||||
path => "/user/:username",
|
||||
method => <<"GET">>,
|
||||
handler => 'openapi_user_handler'
|
||||
},
|
||||
'LoginUser' => #{
|
||||
'loginUser' => #{
|
||||
servers => [],
|
||||
base_path => "/v2",
|
||||
path => "/user/login",
|
||||
method => <<"GET">>,
|
||||
handler => 'openapi_user_handler'
|
||||
},
|
||||
'LogoutUser' => #{
|
||||
'logoutUser' => #{
|
||||
servers => [],
|
||||
base_path => "/v2",
|
||||
path => "/user/logout",
|
||||
method => <<"GET">>,
|
||||
handler => 'openapi_user_handler'
|
||||
},
|
||||
'UpdateUser' => #{
|
||||
'updateUser' => #{
|
||||
servers => [],
|
||||
base_path => "/v2",
|
||||
path => "/user/:username",
|
||||
|
@ -2,18 +2,22 @@
|
||||
-moduledoc """
|
||||
Exposes the following operation IDs:
|
||||
|
||||
- `DELETE` to `/store/order/:orderId`, OperationId: `DeleteOrder`:
|
||||
- `DELETE` to `/store/order/:orderId`, OperationId: `deleteOrder`:
|
||||
Delete purchase order by ID.
|
||||
For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
||||
|
||||
- `GET` to `/store/inventory`, OperationId: `GetInventory`:
|
||||
- `GET` to `/store/inventory`, OperationId: `getInventory`:
|
||||
Returns pet inventories by status.
|
||||
Returns a map of status codes to quantities
|
||||
|
||||
- `GET` to `/store/order/:orderId`, OperationId: `GetOrderById`:
|
||||
- `GET` to `/store/order/:orderId`, OperationId: `getOrderById`:
|
||||
Find purchase order by ID.
|
||||
For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions
|
||||
|
||||
- `POST` to `/store/order`, OperationId: `PlaceOrder`:
|
||||
- `POST` to `/store/order`, OperationId: `placeOrder`:
|
||||
Place an order for a pet.
|
||||
|
||||
|
||||
""".
|
||||
|
||||
-behaviour(cowboy_rest).
|
||||
@ -32,8 +36,19 @@ Place an order for a pet.
|
||||
|
||||
-ignore_xref([handle_type_accepted/2, handle_type_provided/2]).
|
||||
|
||||
-export_type([class/0, operation_id/0]).
|
||||
|
||||
-type class() :: 'store'.
|
||||
|
||||
-type operation_id() ::
|
||||
'deleteOrder' %% Delete purchase order by ID
|
||||
| 'getInventory' %% Returns pet inventories by status
|
||||
| 'getOrderById' %% Find purchase order by ID
|
||||
| 'placeOrder'. %% Place an order for a pet
|
||||
|
||||
|
||||
-record(state,
|
||||
{operation_id :: openapi_api:operation_id(),
|
||||
{operation_id :: operation_id(),
|
||||
accept_callback :: openapi_logic_handler:accept_callback(),
|
||||
provide_callback :: openapi_logic_handler:provide_callback(),
|
||||
api_key_handler :: openapi_logic_handler:api_key_callback(),
|
||||
@ -57,13 +72,13 @@ init(Req, {Operations, Module}) ->
|
||||
|
||||
-spec allowed_methods(cowboy_req:req(), state()) ->
|
||||
{[binary()], cowboy_req:req(), state()}.
|
||||
allowed_methods(Req, #state{operation_id = 'DeleteOrder'} = State) ->
|
||||
allowed_methods(Req, #state{operation_id = 'deleteOrder'} = State) ->
|
||||
{[<<"DELETE">>], Req, State};
|
||||
allowed_methods(Req, #state{operation_id = 'GetInventory'} = State) ->
|
||||
allowed_methods(Req, #state{operation_id = 'getInventory'} = State) ->
|
||||
{[<<"GET">>], Req, State};
|
||||
allowed_methods(Req, #state{operation_id = 'GetOrderById'} = State) ->
|
||||
allowed_methods(Req, #state{operation_id = 'getOrderById'} = State) ->
|
||||
{[<<"GET">>], Req, State};
|
||||
allowed_methods(Req, #state{operation_id = 'PlaceOrder'} = State) ->
|
||||
allowed_methods(Req, #state{operation_id = 'placeOrder'} = State) ->
|
||||
{[<<"POST">>], Req, State};
|
||||
allowed_methods(Req, State) ->
|
||||
{[], Req, State}.
|
||||
@ -71,7 +86,7 @@ allowed_methods(Req, State) ->
|
||||
-spec is_authorized(cowboy_req:req(), state()) ->
|
||||
{true | {false, iodata()}, cowboy_req:req(), state()}.
|
||||
is_authorized(Req0,
|
||||
#state{operation_id = 'GetInventory' = OperationID,
|
||||
#state{operation_id = 'getInventory' = OperationID,
|
||||
api_key_handler = Handler} = State) ->
|
||||
case openapi_auth:authorize_api_key(Handler, OperationID, header, "authorization", Req0) of
|
||||
{true, Context, Req} ->
|
||||
@ -84,13 +99,13 @@ is_authorized(Req, State) ->
|
||||
|
||||
-spec content_types_accepted(cowboy_req:req(), state()) ->
|
||||
{[{binary(), atom()}], cowboy_req:req(), state()}.
|
||||
content_types_accepted(Req, #state{operation_id = 'DeleteOrder'} = State) ->
|
||||
content_types_accepted(Req, #state{operation_id = 'deleteOrder'} = State) ->
|
||||
{[], Req, State};
|
||||
content_types_accepted(Req, #state{operation_id = 'GetInventory'} = State) ->
|
||||
content_types_accepted(Req, #state{operation_id = 'getInventory'} = State) ->
|
||||
{[], Req, State};
|
||||
content_types_accepted(Req, #state{operation_id = 'GetOrderById'} = State) ->
|
||||
content_types_accepted(Req, #state{operation_id = 'getOrderById'} = State) ->
|
||||
{[], Req, State};
|
||||
content_types_accepted(Req, #state{operation_id = 'PlaceOrder'} = State) ->
|
||||
content_types_accepted(Req, #state{operation_id = 'placeOrder'} = State) ->
|
||||
{[
|
||||
{<<"application/json">>, handle_type_accepted}
|
||||
], Req, State};
|
||||
@ -99,31 +114,31 @@ content_types_accepted(Req, State) ->
|
||||
|
||||
-spec valid_content_headers(cowboy_req:req(), state()) ->
|
||||
{boolean(), cowboy_req:req(), state()}.
|
||||
valid_content_headers(Req, #state{operation_id = 'DeleteOrder'} = State) ->
|
||||
valid_content_headers(Req, #state{operation_id = 'deleteOrder'} = State) ->
|
||||
{true, Req, State};
|
||||
valid_content_headers(Req, #state{operation_id = 'GetInventory'} = State) ->
|
||||
valid_content_headers(Req, #state{operation_id = 'getInventory'} = State) ->
|
||||
{true, Req, State};
|
||||
valid_content_headers(Req, #state{operation_id = 'GetOrderById'} = State) ->
|
||||
valid_content_headers(Req, #state{operation_id = 'getOrderById'} = State) ->
|
||||
{true, Req, State};
|
||||
valid_content_headers(Req, #state{operation_id = 'PlaceOrder'} = State) ->
|
||||
valid_content_headers(Req, #state{operation_id = 'placeOrder'} = State) ->
|
||||
{true, Req, State};
|
||||
valid_content_headers(Req, State) ->
|
||||
{false, Req, State}.
|
||||
|
||||
-spec content_types_provided(cowboy_req:req(), state()) ->
|
||||
{[{binary(), atom()}], cowboy_req:req(), state()}.
|
||||
content_types_provided(Req, #state{operation_id = 'DeleteOrder'} = State) ->
|
||||
content_types_provided(Req, #state{operation_id = 'deleteOrder'} = State) ->
|
||||
{[], Req, State};
|
||||
content_types_provided(Req, #state{operation_id = 'GetInventory'} = State) ->
|
||||
content_types_provided(Req, #state{operation_id = 'getInventory'} = State) ->
|
||||
{[
|
||||
{<<"application/json">>, handle_type_provided}
|
||||
], Req, State};
|
||||
content_types_provided(Req, #state{operation_id = 'GetOrderById'} = State) ->
|
||||
content_types_provided(Req, #state{operation_id = 'getOrderById'} = State) ->
|
||||
{[
|
||||
{<<"application/xml">>, handle_type_provided},
|
||||
{<<"application/json">>, handle_type_provided}
|
||||
], Req, State};
|
||||
content_types_provided(Req, #state{operation_id = 'PlaceOrder'} = State) ->
|
||||
content_types_provided(Req, #state{operation_id = 'placeOrder'} = State) ->
|
||||
{[
|
||||
{<<"application/xml">>, handle_type_provided},
|
||||
{<<"application/json">>, handle_type_provided}
|
||||
@ -134,8 +149,8 @@ content_types_provided(Req, State) ->
|
||||
-spec delete_resource(cowboy_req:req(), state()) ->
|
||||
{boolean(), cowboy_req:req(), state()}.
|
||||
delete_resource(Req, State) ->
|
||||
{Res, Req1, State} = handle_type_accepted(Req, State),
|
||||
{true =:= Res, Req1, State}.
|
||||
{Res, Req1, State1} = handle_type_accepted(Req, State),
|
||||
{true =:= Res, Req1, State1}.
|
||||
|
||||
-spec handle_type_accepted(cowboy_req:req(), state()) ->
|
||||
{ openapi_logic_handler:accept_callback_return(), cowboy_req:req(), state()}.
|
||||
|
@ -2,29 +2,37 @@
|
||||
-moduledoc """
|
||||
Exposes the following operation IDs:
|
||||
|
||||
- `POST` to `/user`, OperationId: `CreateUser`:
|
||||
- `POST` to `/user`, OperationId: `createUser`:
|
||||
Create user.
|
||||
This can only be done by the logged in user.
|
||||
|
||||
- `POST` to `/user/createWithArray`, OperationId: `CreateUsersWithArrayInput`:
|
||||
- `POST` to `/user/createWithArray`, OperationId: `createUsersWithArrayInput`:
|
||||
Creates list of users with given input array.
|
||||
|
||||
- `POST` to `/user/createWithList`, OperationId: `CreateUsersWithListInput`:
|
||||
|
||||
- `POST` to `/user/createWithList`, OperationId: `createUsersWithListInput`:
|
||||
Creates list of users with given input array.
|
||||
|
||||
- `DELETE` to `/user/:username`, OperationId: `DeleteUser`:
|
||||
|
||||
- `DELETE` to `/user/:username`, OperationId: `deleteUser`:
|
||||
Delete user.
|
||||
This can only be done by the logged in user.
|
||||
|
||||
- `GET` to `/user/:username`, OperationId: `GetUserByName`:
|
||||
- `GET` to `/user/:username`, OperationId: `getUserByName`:
|
||||
Get user by user name.
|
||||
|
||||
- `GET` to `/user/login`, OperationId: `LoginUser`:
|
||||
|
||||
- `GET` to `/user/login`, OperationId: `loginUser`:
|
||||
Logs user into the system.
|
||||
|
||||
- `GET` to `/user/logout`, OperationId: `LogoutUser`:
|
||||
|
||||
- `GET` to `/user/logout`, OperationId: `logoutUser`:
|
||||
Logs out current logged in user session.
|
||||
|
||||
- `PUT` to `/user/:username`, OperationId: `UpdateUser`:
|
||||
|
||||
- `PUT` to `/user/:username`, OperationId: `updateUser`:
|
||||
Updated user.
|
||||
This can only be done by the logged in user.
|
||||
|
||||
""".
|
||||
|
||||
@ -44,8 +52,23 @@ Updated user.
|
||||
|
||||
-ignore_xref([handle_type_accepted/2, handle_type_provided/2]).
|
||||
|
||||
-export_type([class/0, operation_id/0]).
|
||||
|
||||
-type class() :: 'user'.
|
||||
|
||||
-type operation_id() ::
|
||||
'createUser' %% Create user
|
||||
| 'createUsersWithArrayInput' %% Creates list of users with given input array
|
||||
| 'createUsersWithListInput' %% Creates list of users with given input array
|
||||
| 'deleteUser' %% Delete user
|
||||
| 'getUserByName' %% Get user by user name
|
||||
| 'loginUser' %% Logs user into the system
|
||||
| 'logoutUser' %% Logs out current logged in user session
|
||||
| 'updateUser'. %% Updated user
|
||||
|
||||
|
||||
-record(state,
|
||||
{operation_id :: openapi_api:operation_id(),
|
||||
{operation_id :: operation_id(),
|
||||
accept_callback :: openapi_logic_handler:accept_callback(),
|
||||
provide_callback :: openapi_logic_handler:provide_callback(),
|
||||
api_key_handler :: openapi_logic_handler:api_key_callback(),
|
||||
@ -69,21 +92,21 @@ init(Req, {Operations, Module}) ->
|
||||
|
||||
-spec allowed_methods(cowboy_req:req(), state()) ->
|
||||
{[binary()], cowboy_req:req(), state()}.
|
||||
allowed_methods(Req, #state{operation_id = 'CreateUser'} = State) ->
|
||||
allowed_methods(Req, #state{operation_id = 'createUser'} = State) ->
|
||||
{[<<"POST">>], Req, State};
|
||||
allowed_methods(Req, #state{operation_id = 'CreateUsersWithArrayInput'} = State) ->
|
||||
allowed_methods(Req, #state{operation_id = 'createUsersWithArrayInput'} = State) ->
|
||||
{[<<"POST">>], Req, State};
|
||||
allowed_methods(Req, #state{operation_id = 'CreateUsersWithListInput'} = State) ->
|
||||
allowed_methods(Req, #state{operation_id = 'createUsersWithListInput'} = State) ->
|
||||
{[<<"POST">>], Req, State};
|
||||
allowed_methods(Req, #state{operation_id = 'DeleteUser'} = State) ->
|
||||
allowed_methods(Req, #state{operation_id = 'deleteUser'} = State) ->
|
||||
{[<<"DELETE">>], Req, State};
|
||||
allowed_methods(Req, #state{operation_id = 'GetUserByName'} = State) ->
|
||||
allowed_methods(Req, #state{operation_id = 'getUserByName'} = State) ->
|
||||
{[<<"GET">>], Req, State};
|
||||
allowed_methods(Req, #state{operation_id = 'LoginUser'} = State) ->
|
||||
allowed_methods(Req, #state{operation_id = 'loginUser'} = State) ->
|
||||
{[<<"GET">>], Req, State};
|
||||
allowed_methods(Req, #state{operation_id = 'LogoutUser'} = State) ->
|
||||
allowed_methods(Req, #state{operation_id = 'logoutUser'} = State) ->
|
||||
{[<<"GET">>], Req, State};
|
||||
allowed_methods(Req, #state{operation_id = 'UpdateUser'} = State) ->
|
||||
allowed_methods(Req, #state{operation_id = 'updateUser'} = State) ->
|
||||
{[<<"PUT">>], Req, State};
|
||||
allowed_methods(Req, State) ->
|
||||
{[], Req, State}.
|
||||
@ -91,7 +114,7 @@ allowed_methods(Req, State) ->
|
||||
-spec is_authorized(cowboy_req:req(), state()) ->
|
||||
{true | {false, iodata()}, cowboy_req:req(), state()}.
|
||||
is_authorized(Req0,
|
||||
#state{operation_id = 'CreateUser' = OperationID,
|
||||
#state{operation_id = 'createUser' = OperationID,
|
||||
api_key_handler = Handler} = State) ->
|
||||
case openapi_auth:authorize_api_key(Handler, OperationID, header, "authorization", Req0) of
|
||||
{true, Context, Req} ->
|
||||
@ -100,7 +123,7 @@ is_authorized(Req0,
|
||||
{{false, AuthHeader}, Req, State}
|
||||
end;
|
||||
is_authorized(Req0,
|
||||
#state{operation_id = 'CreateUsersWithArrayInput' = OperationID,
|
||||
#state{operation_id = 'createUsersWithArrayInput' = OperationID,
|
||||
api_key_handler = Handler} = State) ->
|
||||
case openapi_auth:authorize_api_key(Handler, OperationID, header, "authorization", Req0) of
|
||||
{true, Context, Req} ->
|
||||
@ -109,7 +132,7 @@ is_authorized(Req0,
|
||||
{{false, AuthHeader}, Req, State}
|
||||
end;
|
||||
is_authorized(Req0,
|
||||
#state{operation_id = 'CreateUsersWithListInput' = OperationID,
|
||||
#state{operation_id = 'createUsersWithListInput' = OperationID,
|
||||
api_key_handler = Handler} = State) ->
|
||||
case openapi_auth:authorize_api_key(Handler, OperationID, header, "authorization", Req0) of
|
||||
{true, Context, Req} ->
|
||||
@ -118,7 +141,7 @@ is_authorized(Req0,
|
||||
{{false, AuthHeader}, Req, State}
|
||||
end;
|
||||
is_authorized(Req0,
|
||||
#state{operation_id = 'DeleteUser' = OperationID,
|
||||
#state{operation_id = 'deleteUser' = OperationID,
|
||||
api_key_handler = Handler} = State) ->
|
||||
case openapi_auth:authorize_api_key(Handler, OperationID, header, "authorization", Req0) of
|
||||
{true, Context, Req} ->
|
||||
@ -127,7 +150,7 @@ is_authorized(Req0,
|
||||
{{false, AuthHeader}, Req, State}
|
||||
end;
|
||||
is_authorized(Req0,
|
||||
#state{operation_id = 'LogoutUser' = OperationID,
|
||||
#state{operation_id = 'logoutUser' = OperationID,
|
||||
api_key_handler = Handler} = State) ->
|
||||
case openapi_auth:authorize_api_key(Handler, OperationID, header, "authorization", Req0) of
|
||||
{true, Context, Req} ->
|
||||
@ -136,7 +159,7 @@ is_authorized(Req0,
|
||||
{{false, AuthHeader}, Req, State}
|
||||
end;
|
||||
is_authorized(Req0,
|
||||
#state{operation_id = 'UpdateUser' = OperationID,
|
||||
#state{operation_id = 'updateUser' = OperationID,
|
||||
api_key_handler = Handler} = State) ->
|
||||
case openapi_auth:authorize_api_key(Handler, OperationID, header, "authorization", Req0) of
|
||||
{true, Context, Req} ->
|
||||
@ -149,27 +172,27 @@ is_authorized(Req, State) ->
|
||||
|
||||
-spec content_types_accepted(cowboy_req:req(), state()) ->
|
||||
{[{binary(), atom()}], cowboy_req:req(), state()}.
|
||||
content_types_accepted(Req, #state{operation_id = 'CreateUser'} = State) ->
|
||||
content_types_accepted(Req, #state{operation_id = 'createUser'} = State) ->
|
||||
{[
|
||||
{<<"application/json">>, handle_type_accepted}
|
||||
], Req, State};
|
||||
content_types_accepted(Req, #state{operation_id = 'CreateUsersWithArrayInput'} = State) ->
|
||||
content_types_accepted(Req, #state{operation_id = 'createUsersWithArrayInput'} = State) ->
|
||||
{[
|
||||
{<<"application/json">>, handle_type_accepted}
|
||||
], Req, State};
|
||||
content_types_accepted(Req, #state{operation_id = 'CreateUsersWithListInput'} = State) ->
|
||||
content_types_accepted(Req, #state{operation_id = 'createUsersWithListInput'} = State) ->
|
||||
{[
|
||||
{<<"application/json">>, handle_type_accepted}
|
||||
], Req, State};
|
||||
content_types_accepted(Req, #state{operation_id = 'DeleteUser'} = State) ->
|
||||
content_types_accepted(Req, #state{operation_id = 'deleteUser'} = State) ->
|
||||
{[], Req, State};
|
||||
content_types_accepted(Req, #state{operation_id = 'GetUserByName'} = State) ->
|
||||
content_types_accepted(Req, #state{operation_id = 'getUserByName'} = State) ->
|
||||
{[], Req, State};
|
||||
content_types_accepted(Req, #state{operation_id = 'LoginUser'} = State) ->
|
||||
content_types_accepted(Req, #state{operation_id = 'loginUser'} = State) ->
|
||||
{[], Req, State};
|
||||
content_types_accepted(Req, #state{operation_id = 'LogoutUser'} = State) ->
|
||||
content_types_accepted(Req, #state{operation_id = 'logoutUser'} = State) ->
|
||||
{[], Req, State};
|
||||
content_types_accepted(Req, #state{operation_id = 'UpdateUser'} = State) ->
|
||||
content_types_accepted(Req, #state{operation_id = 'updateUser'} = State) ->
|
||||
{[
|
||||
{<<"application/json">>, handle_type_accepted}
|
||||
], Req, State};
|
||||
@ -178,48 +201,48 @@ content_types_accepted(Req, State) ->
|
||||
|
||||
-spec valid_content_headers(cowboy_req:req(), state()) ->
|
||||
{boolean(), cowboy_req:req(), state()}.
|
||||
valid_content_headers(Req, #state{operation_id = 'CreateUser'} = State) ->
|
||||
valid_content_headers(Req, #state{operation_id = 'createUser'} = State) ->
|
||||
{true, Req, State};
|
||||
valid_content_headers(Req, #state{operation_id = 'CreateUsersWithArrayInput'} = State) ->
|
||||
valid_content_headers(Req, #state{operation_id = 'createUsersWithArrayInput'} = State) ->
|
||||
{true, Req, State};
|
||||
valid_content_headers(Req, #state{operation_id = 'CreateUsersWithListInput'} = State) ->
|
||||
valid_content_headers(Req, #state{operation_id = 'createUsersWithListInput'} = State) ->
|
||||
{true, Req, State};
|
||||
valid_content_headers(Req, #state{operation_id = 'DeleteUser'} = State) ->
|
||||
valid_content_headers(Req, #state{operation_id = 'deleteUser'} = State) ->
|
||||
{true, Req, State};
|
||||
valid_content_headers(Req, #state{operation_id = 'GetUserByName'} = State) ->
|
||||
valid_content_headers(Req, #state{operation_id = 'getUserByName'} = State) ->
|
||||
{true, Req, State};
|
||||
valid_content_headers(Req, #state{operation_id = 'LoginUser'} = State) ->
|
||||
valid_content_headers(Req, #state{operation_id = 'loginUser'} = State) ->
|
||||
{true, Req, State};
|
||||
valid_content_headers(Req, #state{operation_id = 'LogoutUser'} = State) ->
|
||||
valid_content_headers(Req, #state{operation_id = 'logoutUser'} = State) ->
|
||||
{true, Req, State};
|
||||
valid_content_headers(Req, #state{operation_id = 'UpdateUser'} = State) ->
|
||||
valid_content_headers(Req, #state{operation_id = 'updateUser'} = State) ->
|
||||
{true, Req, State};
|
||||
valid_content_headers(Req, State) ->
|
||||
{false, Req, State}.
|
||||
|
||||
-spec content_types_provided(cowboy_req:req(), state()) ->
|
||||
{[{binary(), atom()}], cowboy_req:req(), state()}.
|
||||
content_types_provided(Req, #state{operation_id = 'CreateUser'} = State) ->
|
||||
content_types_provided(Req, #state{operation_id = 'createUser'} = State) ->
|
||||
{[], Req, State};
|
||||
content_types_provided(Req, #state{operation_id = 'CreateUsersWithArrayInput'} = State) ->
|
||||
content_types_provided(Req, #state{operation_id = 'createUsersWithArrayInput'} = State) ->
|
||||
{[], Req, State};
|
||||
content_types_provided(Req, #state{operation_id = 'CreateUsersWithListInput'} = State) ->
|
||||
content_types_provided(Req, #state{operation_id = 'createUsersWithListInput'} = State) ->
|
||||
{[], Req, State};
|
||||
content_types_provided(Req, #state{operation_id = 'DeleteUser'} = State) ->
|
||||
content_types_provided(Req, #state{operation_id = 'deleteUser'} = State) ->
|
||||
{[], Req, State};
|
||||
content_types_provided(Req, #state{operation_id = 'GetUserByName'} = State) ->
|
||||
content_types_provided(Req, #state{operation_id = 'getUserByName'} = State) ->
|
||||
{[
|
||||
{<<"application/xml">>, handle_type_provided},
|
||||
{<<"application/json">>, handle_type_provided}
|
||||
], Req, State};
|
||||
content_types_provided(Req, #state{operation_id = 'LoginUser'} = State) ->
|
||||
content_types_provided(Req, #state{operation_id = 'loginUser'} = State) ->
|
||||
{[
|
||||
{<<"application/xml">>, handle_type_provided},
|
||||
{<<"application/json">>, handle_type_provided}
|
||||
], Req, State};
|
||||
content_types_provided(Req, #state{operation_id = 'LogoutUser'} = State) ->
|
||||
content_types_provided(Req, #state{operation_id = 'logoutUser'} = State) ->
|
||||
{[], Req, State};
|
||||
content_types_provided(Req, #state{operation_id = 'UpdateUser'} = State) ->
|
||||
content_types_provided(Req, #state{operation_id = 'updateUser'} = State) ->
|
||||
{[], Req, State};
|
||||
content_types_provided(Req, State) ->
|
||||
{[], Req, State}.
|
||||
@ -227,8 +250,8 @@ content_types_provided(Req, State) ->
|
||||
-spec delete_resource(cowboy_req:req(), state()) ->
|
||||
{boolean(), cowboy_req:req(), state()}.
|
||||
delete_resource(Req, State) ->
|
||||
{Res, Req1, State} = handle_type_accepted(Req, State),
|
||||
{true =:= Res, Req1, State}.
|
||||
{Res, Req1, State1} = handle_type_accepted(Req, State),
|
||||
{true =:= Res, Req1, State1}.
|
||||
|
||||
-spec handle_type_accepted(cowboy_req:req(), state()) ->
|
||||
{ openapi_logic_handler:accept_callback_return(), cowboy_req:req(), state()}.
|
||||
|
Loading…
x
Reference in New Issue
Block a user