forked from loafle/openapi-generator-original
Erlang-server: fix dialyzer; fix min and max checks (#6752)
This commit is contained in:
parent
f4ac6feae2
commit
ab338f8cb9
@ -4,6 +4,8 @@
|
||||
-export([request_param_info/2]).
|
||||
-export([populate_request/3]).
|
||||
-export([validate_response/4]).
|
||||
%% exported to silence swagger complains
|
||||
-export([get_value/3, validate_response_body/4]).
|
||||
|
||||
-type operation_id() :: atom().
|
||||
-type request_param() :: atom().
|
||||
@ -212,7 +214,7 @@ validate(Rule = {enum, Values}, Name, Value, _ValidatorState) ->
|
||||
end;
|
||||
|
||||
validate(Rule = {max, Max}, Name, Value, _ValidatorState) ->
|
||||
case Value >= Max of
|
||||
case Value =< Max of
|
||||
true -> ok;
|
||||
false -> validation_error(Rule, Name)
|
||||
end;
|
||||
@ -224,7 +226,7 @@ validate(Rule = {exclusive_max, ExclusiveMax}, Name, Value, _ValidatorState) ->
|
||||
end;
|
||||
|
||||
validate(Rule = {min, Min}, Name, Value, _ValidatorState) ->
|
||||
case Value =< Min of
|
||||
case Value >= Min of
|
||||
true -> ok;
|
||||
false -> validation_error(Rule, Name)
|
||||
end;
|
||||
@ -290,6 +292,8 @@ validation_error(ViolatedRule, Name) ->
|
||||
validation_error(ViolatedRule, Name, Info) ->
|
||||
throw({wrong_param, Name, ViolatedRule, Info}).
|
||||
|
||||
-spec get_value(body | qs_val | header | binding, Name :: any(), Req0 :: cowboy_req:req()) ->
|
||||
{Value :: any(), Req :: cowboy_req:req()}.
|
||||
get_value(body, _Name, Req0) ->
|
||||
{ok, Body, Req} = cowboy_req:body(Req0),
|
||||
Value = prepare_body(Body),
|
||||
|
@ -24,8 +24,12 @@ authorize_api_key(LogicHandler, OperationID, From, KeyParam, Req0) ->
|
||||
ApiKey
|
||||
),
|
||||
case Result of
|
||||
{{#authMethods}}
|
||||
{{#isApiKey}}
|
||||
{true, Context} ->
|
||||
{true, Context, Req};
|
||||
{{/isApiKey}}
|
||||
{{/authMethods}}
|
||||
false ->
|
||||
AuthHeader = <<"">>,
|
||||
{false, AuthHeader, Req}
|
||||
|
@ -94,13 +94,15 @@ is_authorized(
|
||||
end;
|
||||
{{/isApiKey}}
|
||||
{{/authMethods}}
|
||||
{{/operation}}{{/operations}}
|
||||
{{^authMethods}}
|
||||
is_authorized(Req, State) ->
|
||||
{true, Req, State};
|
||||
{true, Req, State}.
|
||||
{{/authMethods}}
|
||||
{{/operation}}{{/operations}}
|
||||
{{#authMethods}}
|
||||
is_authorized(Req, State) ->
|
||||
{{false, <<"">>}, Req, State}.
|
||||
{{/authMethods}}
|
||||
|
||||
-spec content_types_accepted(Req :: cowboy_req:req(), State :: state()) ->
|
||||
{
|
||||
|
@ -1,11 +1,7 @@
|
||||
-module({{packageName}}_logic_handler).
|
||||
|
||||
-export([handle_request/4]).
|
||||
{{#authMethods}}
|
||||
{{#isApiKey}}
|
||||
-export([authorize_api_key/3]).
|
||||
{{/isApiKey}}
|
||||
{{/authMethods}}
|
||||
-type context() :: #{binary() => any()}.
|
||||
-type handler_response() ::{
|
||||
Status :: cowboy:http_status(),
|
||||
@ -48,3 +44,9 @@ authorize_api_key(Handler, OperationID, ApiKey) ->
|
||||
Handler:authorize_api_key(OperationID, ApiKey).
|
||||
{{/isApiKey}}
|
||||
{{/authMethods}}
|
||||
{{^authMethods}}
|
||||
-spec authorize_api_key(Handler :: atom(), OperationID :: {{packageName}}_api:operation_id(), ApiKey :: binary()) ->
|
||||
Result :: false.
|
||||
authorize_api_key(_Handler, _OperationID, _ApiKey) ->
|
||||
false.
|
||||
{{/authMethods}}
|
||||
|
@ -9,6 +9,7 @@
|
||||
-spec child_spec( ID :: any(), #{
|
||||
ip => inet:ip_address(),
|
||||
port => inet:port_number(),
|
||||
logic_handler => module(),
|
||||
net_opts => []
|
||||
}) -> supervisor:child_spec().
|
||||
|
||||
|
@ -1 +1 @@
|
||||
2.2.3-SNAPSHOT
|
||||
2.3.0-SNAPSHOT
|
@ -9,7 +9,7 @@
|
||||
"email" : "apiteam@swagger.io"
|
||||
},
|
||||
"license" : {
|
||||
"name" : "Apache 2.0",
|
||||
"name" : "Apache-2.0",
|
||||
"url" : "http://www.apache.org/licenses/LICENSE-2.0.html"
|
||||
}
|
||||
},
|
||||
@ -166,7 +166,8 @@
|
||||
},
|
||||
"security" : [ {
|
||||
"petstore_auth" : [ "write:pets", "read:pets" ]
|
||||
} ]
|
||||
} ],
|
||||
"deprecated" : true
|
||||
}
|
||||
},
|
||||
"/pet/{petId}" : {
|
||||
@ -683,6 +684,14 @@
|
||||
},
|
||||
"title" : "Pet Order",
|
||||
"description" : "An order for a pets from the pet store",
|
||||
"example" : {
|
||||
"petId" : 6,
|
||||
"quantity" : 1,
|
||||
"id" : 0,
|
||||
"shipDate" : "2000-01-23T04:56:07.000+00:00",
|
||||
"complete" : false,
|
||||
"status" : "placed"
|
||||
},
|
||||
"xml" : {
|
||||
"name" : "Order"
|
||||
}
|
||||
@ -700,6 +709,10 @@
|
||||
},
|
||||
"title" : "Pet catehgry",
|
||||
"description" : "A category for a pet",
|
||||
"example" : {
|
||||
"name" : "name",
|
||||
"id" : 6
|
||||
},
|
||||
"xml" : {
|
||||
"name" : "Category"
|
||||
}
|
||||
@ -737,6 +750,16 @@
|
||||
},
|
||||
"title" : "a User",
|
||||
"description" : "A User who is purchasing from the pet store",
|
||||
"example" : {
|
||||
"firstName" : "firstName",
|
||||
"lastName" : "lastName",
|
||||
"password" : "password",
|
||||
"userStatus" : 6,
|
||||
"phone" : "phone",
|
||||
"id" : 0,
|
||||
"email" : "email",
|
||||
"username" : "username"
|
||||
},
|
||||
"xml" : {
|
||||
"name" : "User"
|
||||
}
|
||||
@ -754,6 +777,10 @@
|
||||
},
|
||||
"title" : "Pet Tag",
|
||||
"description" : "A tag for a pet",
|
||||
"example" : {
|
||||
"name" : "name",
|
||||
"id" : 1
|
||||
},
|
||||
"xml" : {
|
||||
"name" : "Tag"
|
||||
}
|
||||
@ -801,6 +828,23 @@
|
||||
},
|
||||
"title" : "a Pet",
|
||||
"description" : "A pet for sale in the pet store",
|
||||
"example" : {
|
||||
"photoUrls" : [ "photoUrls", "photoUrls" ],
|
||||
"name" : "doggie",
|
||||
"id" : 0,
|
||||
"category" : {
|
||||
"name" : "name",
|
||||
"id" : 6
|
||||
},
|
||||
"tags" : [ {
|
||||
"name" : "name",
|
||||
"id" : 1
|
||||
}, {
|
||||
"name" : "name",
|
||||
"id" : 1
|
||||
} ],
|
||||
"status" : "available"
|
||||
},
|
||||
"xml" : {
|
||||
"name" : "Pet"
|
||||
}
|
||||
@ -820,7 +864,12 @@
|
||||
}
|
||||
},
|
||||
"title" : "An uploaded response",
|
||||
"description" : "Describes the result of uploading an image resource"
|
||||
"description" : "Describes the result of uploading an image resource",
|
||||
"example" : {
|
||||
"code" : 0,
|
||||
"type" : "type",
|
||||
"message" : "message"
|
||||
}
|
||||
}
|
||||
},
|
||||
"externalDocs" : {
|
||||
|
@ -14,6 +14,6 @@
|
||||
{env, [
|
||||
]},
|
||||
{modules, []},
|
||||
{licenses, ["Apache 2.0"]},
|
||||
{licenses, ["Apache-2.0"]},
|
||||
{links, []}
|
||||
]}.
|
||||
|
@ -4,6 +4,8 @@
|
||||
-export([request_param_info/2]).
|
||||
-export([populate_request/3]).
|
||||
-export([validate_response/4]).
|
||||
%% exported to silence swagger complains
|
||||
-export([get_value/3, validate_response_body/4]).
|
||||
|
||||
-type operation_id() :: atom().
|
||||
-type request_param() :: atom().
|
||||
@ -599,7 +601,7 @@ validate(Rule = {enum, Values}, Name, Value, _ValidatorState) ->
|
||||
end;
|
||||
|
||||
validate(Rule = {max, Max}, Name, Value, _ValidatorState) ->
|
||||
case Value >= Max of
|
||||
case Value =< Max of
|
||||
true -> ok;
|
||||
false -> validation_error(Rule, Name)
|
||||
end;
|
||||
@ -611,7 +613,7 @@ validate(Rule = {exclusive_max, ExclusiveMax}, Name, Value, _ValidatorState) ->
|
||||
end;
|
||||
|
||||
validate(Rule = {min, Min}, Name, Value, _ValidatorState) ->
|
||||
case Value =< Min of
|
||||
case Value >= Min of
|
||||
true -> ok;
|
||||
false -> validation_error(Rule, Name)
|
||||
end;
|
||||
@ -677,6 +679,8 @@ validation_error(ViolatedRule, Name) ->
|
||||
validation_error(ViolatedRule, Name, Info) ->
|
||||
throw({wrong_param, Name, ViolatedRule, Info}).
|
||||
|
||||
-spec get_value(body | qs_val | header | binding, Name :: any(), Req0 :: cowboy_req:req()) ->
|
||||
{Value :: any(), Req :: cowboy_req:req()}.
|
||||
get_value(body, _Name, Req0) ->
|
||||
{ok, Body, Req} = cowboy_req:body(Req0),
|
||||
Value = prepare_body(Body),
|
||||
|
@ -204,7 +204,7 @@ is_authorized(
|
||||
) ->
|
||||
|
||||
is_authorized(Req, State) ->
|
||||
{{false, <<"">>}, Req, State}.
|
||||
{true, Req, State}.
|
||||
|
||||
-spec content_types_accepted(Req :: cowboy_req:req(), State :: state()) ->
|
||||
{
|
||||
|
@ -9,6 +9,7 @@
|
||||
-spec child_spec( ID :: any(), #{
|
||||
ip => inet:ip_address(),
|
||||
port => inet:port_number(),
|
||||
logic_handler => module(),
|
||||
net_opts => []
|
||||
}) -> supervisor:child_spec().
|
||||
|
||||
|
@ -95,14 +95,6 @@ allowed_methods(Req, State) ->
|
||||
State :: state()
|
||||
}.
|
||||
|
||||
is_authorized(
|
||||
Req0,
|
||||
State = #state{
|
||||
operation_id = 'DeleteOrder' = OperationID,
|
||||
logic_handler = LogicHandler
|
||||
}
|
||||
) ->
|
||||
{true, Req0, State};
|
||||
|
||||
is_authorized(
|
||||
Req0,
|
||||
@ -124,26 +116,10 @@ is_authorized(
|
||||
{false, AuthHeader, Req} -> {{false, AuthHeader}, Req, State}
|
||||
end;
|
||||
|
||||
is_authorized(
|
||||
Req0,
|
||||
State = #state{
|
||||
operation_id = 'GetOrderById' = OperationID,
|
||||
logic_handler = LogicHandler
|
||||
}
|
||||
) ->
|
||||
{true, Req0, State};
|
||||
|
||||
is_authorized(
|
||||
Req0,
|
||||
State = #state{
|
||||
operation_id = 'PlaceOrder' = OperationID,
|
||||
logic_handler = LogicHandler
|
||||
}
|
||||
) ->
|
||||
{true, Req0, State};
|
||||
|
||||
is_authorized(Req, State) ->
|
||||
{{false, <<"">>}, Req, State}.
|
||||
{true, Req, State}.
|
||||
|
||||
-spec content_types_accepted(Req :: cowboy_req:req(), State :: state()) ->
|
||||
{
|
||||
|
@ -127,80 +127,16 @@ allowed_methods(Req, State) ->
|
||||
State :: state()
|
||||
}.
|
||||
|
||||
is_authorized(
|
||||
Req0,
|
||||
State = #state{
|
||||
operation_id = 'CreateUser' = OperationID,
|
||||
logic_handler = LogicHandler
|
||||
}
|
||||
) ->
|
||||
{true, Req0, State};
|
||||
|
||||
is_authorized(
|
||||
Req0,
|
||||
State = #state{
|
||||
operation_id = 'CreateUsersWithArrayInput' = OperationID,
|
||||
logic_handler = LogicHandler
|
||||
}
|
||||
) ->
|
||||
{true, Req0, State};
|
||||
|
||||
is_authorized(
|
||||
Req0,
|
||||
State = #state{
|
||||
operation_id = 'CreateUsersWithListInput' = OperationID,
|
||||
logic_handler = LogicHandler
|
||||
}
|
||||
) ->
|
||||
{true, Req0, State};
|
||||
|
||||
is_authorized(
|
||||
Req0,
|
||||
State = #state{
|
||||
operation_id = 'DeleteUser' = OperationID,
|
||||
logic_handler = LogicHandler
|
||||
}
|
||||
) ->
|
||||
{true, Req0, State};
|
||||
|
||||
is_authorized(
|
||||
Req0,
|
||||
State = #state{
|
||||
operation_id = 'GetUserByName' = OperationID,
|
||||
logic_handler = LogicHandler
|
||||
}
|
||||
) ->
|
||||
{true, Req0, State};
|
||||
|
||||
is_authorized(
|
||||
Req0,
|
||||
State = #state{
|
||||
operation_id = 'LoginUser' = OperationID,
|
||||
logic_handler = LogicHandler
|
||||
}
|
||||
) ->
|
||||
{true, Req0, State};
|
||||
|
||||
is_authorized(
|
||||
Req0,
|
||||
State = #state{
|
||||
operation_id = 'LogoutUser' = OperationID,
|
||||
logic_handler = LogicHandler
|
||||
}
|
||||
) ->
|
||||
{true, Req0, State};
|
||||
|
||||
is_authorized(
|
||||
Req0,
|
||||
State = #state{
|
||||
operation_id = 'UpdateUser' = OperationID,
|
||||
logic_handler = LogicHandler
|
||||
}
|
||||
) ->
|
||||
{true, Req0, State};
|
||||
|
||||
is_authorized(Req, State) ->
|
||||
{{false, <<"">>}, Req, State}.
|
||||
{true, Req, State}.
|
||||
|
||||
-spec content_types_accepted(Req :: cowboy_req:req(), State :: state()) ->
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user