Skip to content

Commit

Permalink
Update samples
Browse files Browse the repository at this point in the history
  • Loading branch information
kpy3 committed Feb 25, 2025
1 parent 8e199e5 commit 9d85a30
Show file tree
Hide file tree
Showing 13 changed files with 60 additions and 60 deletions.
2 changes: 1 addition & 1 deletion samples/server/echo_api/erlang-server/src/openapi_api.erl
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ populate_request_params(_, [], Req, _, Model) ->
populate_request_params(OperationID, [ReqParamName | T], Req0, ValidatorState, Model0) ->
case populate_request_param(OperationID, ReqParamName, Req0, ValidatorState) of
{ok, V, Req} ->
Model = maps:put(ReqParamName, V, Model0),
Model = Model0#{ReqParamName => V},
populate_request_params(OperationID, T, Req, ValidatorState, Model);
Error ->
Error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ To test HTTP bearer authentication
{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(),
api_key_callback :: openapi_logic_handler:api_key_callback(),
context = #{} :: openapi_logic_handler:context()}).

-type state() :: #state{}.
Expand All @@ -57,7 +57,7 @@ init(Req, {Operations, Module}) ->
State = #state{operation_id = OperationID,
accept_callback = fun Module:accept_callback/4,
provide_callback = fun Module:provide_callback/4,
api_key_handler = fun Module:authorize_api_key/2},
api_key_callback = fun Module:api_key_callback/2},
{cowboy_rest, Req, State}.

-spec allowed_methods(cowboy_req:req(), state()) ->
Expand All @@ -73,17 +73,17 @@ allowed_methods(Req, State) ->
{true | {false, iodata()}, cowboy_req:req(), state()}.
is_authorized(Req0,
#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
api_key_callback = Handler} = State) ->
case openapi_auth:authorize_api_key(Handler, OperationID, header, <<"authorization">>, Req0) of
{true, Context, Req} ->
{true, Req, State#state{context = Context}};
{false, AuthHeader, Req} ->
{{false, AuthHeader}, Req, State}
end;
is_authorized(Req0,
#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
api_key_callback = Handler} = State) ->
case openapi_auth:authorize_api_key(Handler, OperationID, header, <<"authorization">>, Req0) of
{true, Context, Req} ->
{true, Req, State#state{context = Context}};
{false, AuthHeader, Req} ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Test empty json (request body)
{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(),
api_key_callback :: openapi_logic_handler:api_key_callback(),
context = #{} :: openapi_logic_handler:context()}).

-type state() :: #state{}.
Expand All @@ -97,7 +97,7 @@ init(Req, {Operations, Module}) ->
State = #state{operation_id = OperationID,
accept_callback = fun Module:accept_callback/4,
provide_callback = fun Module:provide_callback/4,
api_key_handler = fun Module:authorize_api_key/2},
api_key_callback = fun Module:api_key_callback/2},
{cowboy_rest, Req, State}.

-spec allowed_methods(cowboy_req:req(), state()) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Test form parameter(s) for oneOf schema
{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(),
api_key_callback :: openapi_logic_handler:api_key_callback(),
context = #{} :: openapi_logic_handler:context()}).

-type state() :: #state{}.
Expand All @@ -62,7 +62,7 @@ init(Req, {Operations, Module}) ->
State = #state{operation_id = OperationID,
accept_callback = fun Module:accept_callback/4,
provide_callback = fun Module:provide_callback/4,
api_key_handler = fun Module:authorize_api_key/2},
api_key_callback = fun Module:api_key_callback/2},
{cowboy_rest, Req, State}.

-spec allowed_methods(cowboy_req:req(), state()) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Test header parameter(s)
{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(),
api_key_callback :: openapi_logic_handler:api_key_callback(),
context = #{} :: openapi_logic_handler:context()}).

-type state() :: #state{}.
Expand All @@ -52,7 +52,7 @@ init(Req, {Operations, Module}) ->
State = #state{operation_id = OperationID,
accept_callback = fun Module:accept_callback/4,
provide_callback = fun Module:provide_callback/4,
api_key_handler = fun Module:authorize_api_key/2},
api_key_callback = fun Module:api_key_callback/2},
{cowboy_rest, Req, State}.

-spec allowed_methods(cowboy_req:req(), state()) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Test path parameter(s)
{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(),
api_key_callback :: openapi_logic_handler:api_key_callback(),
context = #{} :: openapi_logic_handler:context()}).

-type state() :: #state{}.
Expand All @@ -52,7 +52,7 @@ init(Req, {Operations, Module}) ->
State = #state{operation_id = OperationID,
accept_callback = fun Module:accept_callback/4,
provide_callback = fun Module:provide_callback/4,
api_key_handler = fun Module:authorize_api_key/2},
api_key_callback = fun Module:api_key_callback/2},
{cowboy_rest, Req, State}.

-spec allowed_methods(cowboy_req:req(), state()) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Test query parameter(s)
{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(),
api_key_callback :: openapi_logic_handler:api_key_callback(),
context = #{} :: openapi_logic_handler:context()}).

-type state() :: #state{}.
Expand All @@ -97,7 +97,7 @@ init(Req, {Operations, Module}) ->
State = #state{operation_id = OperationID,
accept_callback = fun Module:accept_callback/4,
provide_callback = fun Module:provide_callback/4,
api_key_handler = fun Module:authorize_api_key/2},
api_key_callback = fun Module:api_key_callback/2},
{cowboy_rest, Req, State}.

-spec allowed_methods(cowboy_req:req(), state()) ->
Expand Down
6 changes: 3 additions & 3 deletions samples/server/echo_api/erlang-server/src/openapi_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ get_cowboy_config(LogicHandler, ExtraOpts) ->
maps:fold(fun get_cowboy_config/3, DefaultOpts, ExtraOpts).

get_cowboy_config(env, #{dispatch := _Dispatch} = Env, AccIn) ->
maps:put(env, Env, AccIn);
AccIn#{env => Env};
get_cowboy_config(env, NewEnv, #{env := OldEnv} = AccIn) ->
Env = maps:merge(OldEnv, NewEnv),
maps:put(env, Env, AccIn);
AccIn#{env => Env};
get_cowboy_config(Key, Value, AccIn) ->
maps:put(Key, Value, AccIn).
AccIn#{Key => Value}.

get_default_dispatch(LogicHandler) ->
Paths = openapi_router:get_paths(LogicHandler),
Expand Down
2 changes: 1 addition & 1 deletion samples/server/petstore/erlang-server/src/openapi_api.erl
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ populate_request_params(_, [], Req, _, Model) ->
populate_request_params(OperationID, [ReqParamName | T], Req0, ValidatorState, Model0) ->
case populate_request_param(OperationID, ReqParamName, Req0, ValidatorState) of
{ok, V, Req} ->
Model = maps:put(ReqParamName, V, Model0),
Model = Model0#{ReqParamName => V},
populate_request_params(OperationID, T, Req, ValidatorState, Model);
Error ->
Error
Expand Down
36 changes: 18 additions & 18 deletions samples/server/petstore/erlang-server/src/openapi_pet_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ uploads an image.
{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(),
api_key_callback :: openapi_logic_handler:api_key_callback(),
context = #{} :: openapi_logic_handler:context()}).

-type state() :: #state{}.
Expand All @@ -87,7 +87,7 @@ init(Req, {Operations, Module}) ->
State = #state{operation_id = OperationID,
accept_callback = fun Module:accept_callback/4,
provide_callback = fun Module:provide_callback/4,
api_key_handler = fun Module:authorize_api_key/2},
api_key_callback = fun Module:api_key_callback/2},
{cowboy_rest, Req, State}.

-spec allowed_methods(cowboy_req:req(), state()) ->
Expand Down Expand Up @@ -115,71 +115,71 @@ allowed_methods(Req, State) ->
{true | {false, iodata()}, cowboy_req:req(), state()}.
is_authorized(Req0,
#state{operation_id = 'addPet' = OperationID,
api_key_handler = Handler} = State) ->
case openapi_auth:authorize_api_key(Handler, OperationID, header, "authorization", Req0) of
api_key_callback = Handler} = State) ->
case openapi_auth:authorize_api_key(Handler, OperationID, header, <<"authorization">>, Req0) of
{true, Context, Req} ->
{true, Req, State#state{context = Context}};
{false, AuthHeader, Req} ->
{{false, AuthHeader}, Req, State}
end;
is_authorized(Req0,
#state{operation_id = 'deletePet' = OperationID,
api_key_handler = Handler} = State) ->
case openapi_auth:authorize_api_key(Handler, OperationID, header, "authorization", Req0) of
api_key_callback = Handler} = State) ->
case openapi_auth:authorize_api_key(Handler, OperationID, header, <<"authorization">>, Req0) of
{true, Context, Req} ->
{true, Req, State#state{context = Context}};
{false, AuthHeader, Req} ->
{{false, AuthHeader}, Req, State}
end;
is_authorized(Req0,
#state{operation_id = 'findPetsByStatus' = OperationID,
api_key_handler = Handler} = State) ->
case openapi_auth:authorize_api_key(Handler, OperationID, header, "authorization", Req0) of
api_key_callback = Handler} = State) ->
case openapi_auth:authorize_api_key(Handler, OperationID, header, <<"authorization">>, Req0) of
{true, Context, Req} ->
{true, Req, State#state{context = Context}};
{false, AuthHeader, Req} ->
{{false, AuthHeader}, Req, State}
end;
is_authorized(Req0,
#state{operation_id = 'findPetsByTags' = OperationID,
api_key_handler = Handler} = State) ->
case openapi_auth:authorize_api_key(Handler, OperationID, header, "authorization", Req0) of
api_key_callback = Handler} = State) ->
case openapi_auth:authorize_api_key(Handler, OperationID, header, <<"authorization">>, Req0) of
{true, Context, Req} ->
{true, Req, State#state{context = Context}};
{false, AuthHeader, Req} ->
{{false, AuthHeader}, Req, State}
end;
is_authorized(Req0,
#state{operation_id = 'getPetById' = OperationID,
api_key_handler = Handler} = State) ->
case openapi_auth:authorize_api_key(Handler, OperationID, header, "authorization", Req0) of
api_key_callback = Handler} = State) ->
case openapi_auth:authorize_api_key(Handler, OperationID, header, <<"authorization">>, Req0) of
{true, Context, Req} ->
{true, Req, State#state{context = Context}};
{false, AuthHeader, Req} ->
{{false, AuthHeader}, Req, State}
end;
is_authorized(Req0,
#state{operation_id = 'updatePet' = OperationID,
api_key_handler = Handler} = State) ->
case openapi_auth:authorize_api_key(Handler, OperationID, header, "authorization", Req0) of
api_key_callback = Handler} = State) ->
case openapi_auth:authorize_api_key(Handler, OperationID, header, <<"authorization">>, Req0) of
{true, Context, Req} ->
{true, Req, State#state{context = Context}};
{false, AuthHeader, Req} ->
{{false, AuthHeader}, Req, State}
end;
is_authorized(Req0,
#state{operation_id = 'updatePetWithForm' = OperationID,
api_key_handler = Handler} = State) ->
case openapi_auth:authorize_api_key(Handler, OperationID, header, "authorization", Req0) of
api_key_callback = Handler} = State) ->
case openapi_auth:authorize_api_key(Handler, OperationID, header, <<"authorization">>, Req0) of
{true, Context, Req} ->
{true, Req, State#state{context = Context}};
{false, AuthHeader, Req} ->
{{false, AuthHeader}, Req, State}
end;
is_authorized(Req0,
#state{operation_id = 'uploadFile' = OperationID,
api_key_handler = Handler} = State) ->
case openapi_auth:authorize_api_key(Handler, OperationID, header, "authorization", Req0) of
api_key_callback = Handler} = State) ->
case openapi_auth:authorize_api_key(Handler, OperationID, header, <<"authorization">>, Req0) of
{true, Context, Req} ->
{true, Req, State#state{context = Context}};
{false, AuthHeader, Req} ->
Expand Down
6 changes: 3 additions & 3 deletions samples/server/petstore/erlang-server/src/openapi_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ get_cowboy_config(LogicHandler, ExtraOpts) ->
maps:fold(fun get_cowboy_config/3, DefaultOpts, ExtraOpts).

get_cowboy_config(env, #{dispatch := _Dispatch} = Env, AccIn) ->
maps:put(env, Env, AccIn);
AccIn#{env => Env};
get_cowboy_config(env, NewEnv, #{env := OldEnv} = AccIn) ->
Env = maps:merge(OldEnv, NewEnv),
maps:put(env, Env, AccIn);
AccIn#{env => Env};
get_cowboy_config(Key, Value, AccIn) ->
maps:put(Key, Value, AccIn).
AccIn#{Key => Value}.

get_default_dispatch(LogicHandler) ->
Paths = openapi_router:get_paths(LogicHandler),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Place an order for a pet.
{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(),
api_key_callback :: openapi_logic_handler:api_key_callback(),
context = #{} :: openapi_logic_handler:context()}).

-type state() :: #state{}.
Expand All @@ -67,7 +67,7 @@ init(Req, {Operations, Module}) ->
State = #state{operation_id = OperationID,
accept_callback = fun Module:accept_callback/4,
provide_callback = fun Module:provide_callback/4,
api_key_handler = fun Module:authorize_api_key/2},
api_key_callback = fun Module:api_key_callback/2},
{cowboy_rest, Req, State}.

-spec allowed_methods(cowboy_req:req(), state()) ->
Expand All @@ -87,8 +87,8 @@ allowed_methods(Req, State) ->
{true | {false, iodata()}, cowboy_req:req(), state()}.
is_authorized(Req0,
#state{operation_id = 'getInventory' = OperationID,
api_key_handler = Handler} = State) ->
case openapi_auth:authorize_api_key(Handler, OperationID, header, "authorization", Req0) of
api_key_callback = Handler} = State) ->
case openapi_auth:authorize_api_key(Handler, OperationID, header, <<"authorization">>, Req0) of
{true, Context, Req} ->
{true, Req, State#state{context = Context}};
{false, AuthHeader, Req} ->
Expand Down
Loading

0 comments on commit 9d85a30

Please sign in to comment.