Skip to content

Commit c9054c7

Browse files
author
Sergei Elin
committed
Update samples
1 parent 08fe571 commit c9054c7

13 files changed

+60
-60
lines changed

samples/server/echo_api/erlang-server/src/openapi_api.erl

+1-1
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ populate_request_params(_, [], Req, _, Model) ->
686686
populate_request_params(OperationID, [ReqParamName | T], Req0, ValidatorState, Model0) ->
687687
case populate_request_param(OperationID, ReqParamName, Req0, ValidatorState) of
688688
{ok, V, Req} ->
689-
Model = maps:put(ReqParamName, V, Model0),
689+
Model = Model0#{ReqParamName => V},
690690
populate_request_params(OperationID, T, Req, ValidatorState, Model);
691691
Error ->
692692
Error

samples/server/echo_api/erlang-server/src/openapi_auth_handler.erl

+6-6
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ To test HTTP bearer authentication
4141
{operation_id :: operation_id(),
4242
accept_callback :: openapi_logic_handler:accept_callback(),
4343
provide_callback :: openapi_logic_handler:provide_callback(),
44-
api_key_handler :: openapi_logic_handler:api_key_callback(),
44+
api_key_callback :: openapi_logic_handler:api_key_callback(),
4545
context = #{} :: openapi_logic_handler:context()}).
4646

4747
-type state() :: #state{}.
@@ -57,7 +57,7 @@ init(Req, {Operations, Module}) ->
5757
State = #state{operation_id = OperationID,
5858
accept_callback = fun Module:accept_callback/4,
5959
provide_callback = fun Module:provide_callback/4,
60-
api_key_handler = fun Module:authorize_api_key/2},
60+
api_key_callback = fun Module:api_key_callback/2},
6161
{cowboy_rest, Req, State}.
6262

6363
-spec allowed_methods(cowboy_req:req(), state()) ->
@@ -73,17 +73,17 @@ allowed_methods(Req, State) ->
7373
{true | {false, iodata()}, cowboy_req:req(), state()}.
7474
is_authorized(Req0,
7575
#state{operation_id = 'test/auth/http/basic' = OperationID,
76-
api_key_handler = Handler} = State) ->
77-
case openapi_auth:authorize_api_key(Handler, OperationID, header, "authorization", Req0) of
76+
api_key_callback = Handler} = State) ->
77+
case openapi_auth:authorize_api_key(Handler, OperationID, header, <<"authorization">>, Req0) of
7878
{true, Context, Req} ->
7979
{true, Req, State#state{context = Context}};
8080
{false, AuthHeader, Req} ->
8181
{{false, AuthHeader}, Req, State}
8282
end;
8383
is_authorized(Req0,
8484
#state{operation_id = 'test/auth/http/bearer' = OperationID,
85-
api_key_handler = Handler} = State) ->
86-
case openapi_auth:authorize_api_key(Handler, OperationID, header, "authorization", Req0) of
85+
api_key_callback = Handler} = State) ->
86+
case openapi_auth:authorize_api_key(Handler, OperationID, header, <<"authorization">>, Req0) of
8787
{true, Context, Req} ->
8888
{true, Req, State#state{context = Context}};
8989
{false, AuthHeader, Req} ->

samples/server/echo_api/erlang-server/src/openapi_body_handler.erl

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ Test empty json (request body)
8181
{operation_id :: operation_id(),
8282
accept_callback :: openapi_logic_handler:accept_callback(),
8383
provide_callback :: openapi_logic_handler:provide_callback(),
84-
api_key_handler :: openapi_logic_handler:api_key_callback(),
84+
api_key_callback :: openapi_logic_handler:api_key_callback(),
8585
context = #{} :: openapi_logic_handler:context()}).
8686

8787
-type state() :: #state{}.
@@ -97,7 +97,7 @@ init(Req, {Operations, Module}) ->
9797
State = #state{operation_id = OperationID,
9898
accept_callback = fun Module:accept_callback/4,
9999
provide_callback = fun Module:provide_callback/4,
100-
api_key_handler = fun Module:authorize_api_key/2},
100+
api_key_callback = fun Module:api_key_callback/2},
101101
{cowboy_rest, Req, State}.
102102

103103
-spec allowed_methods(cowboy_req:req(), state()) ->

samples/server/echo_api/erlang-server/src/openapi_form_handler.erl

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Test form parameter(s) for oneOf schema
4646
{operation_id :: operation_id(),
4747
accept_callback :: openapi_logic_handler:accept_callback(),
4848
provide_callback :: openapi_logic_handler:provide_callback(),
49-
api_key_handler :: openapi_logic_handler:api_key_callback(),
49+
api_key_callback :: openapi_logic_handler:api_key_callback(),
5050
context = #{} :: openapi_logic_handler:context()}).
5151

5252
-type state() :: #state{}.
@@ -62,7 +62,7 @@ init(Req, {Operations, Module}) ->
6262
State = #state{operation_id = OperationID,
6363
accept_callback = fun Module:accept_callback/4,
6464
provide_callback = fun Module:provide_callback/4,
65-
api_key_handler = fun Module:authorize_api_key/2},
65+
api_key_callback = fun Module:api_key_callback/2},
6666
{cowboy_rest, Req, State}.
6767

6868
-spec allowed_methods(cowboy_req:req(), state()) ->

samples/server/echo_api/erlang-server/src/openapi_header_handler.erl

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Test header parameter(s)
3636
{operation_id :: operation_id(),
3737
accept_callback :: openapi_logic_handler:accept_callback(),
3838
provide_callback :: openapi_logic_handler:provide_callback(),
39-
api_key_handler :: openapi_logic_handler:api_key_callback(),
39+
api_key_callback :: openapi_logic_handler:api_key_callback(),
4040
context = #{} :: openapi_logic_handler:context()}).
4141

4242
-type state() :: #state{}.
@@ -52,7 +52,7 @@ init(Req, {Operations, Module}) ->
5252
State = #state{operation_id = OperationID,
5353
accept_callback = fun Module:accept_callback/4,
5454
provide_callback = fun Module:provide_callback/4,
55-
api_key_handler = fun Module:authorize_api_key/2},
55+
api_key_callback = fun Module:api_key_callback/2},
5656
{cowboy_rest, Req, State}.
5757

5858
-spec allowed_methods(cowboy_req:req(), state()) ->

samples/server/echo_api/erlang-server/src/openapi_path_handler.erl

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Test path parameter(s)
3636
{operation_id :: operation_id(),
3737
accept_callback :: openapi_logic_handler:accept_callback(),
3838
provide_callback :: openapi_logic_handler:provide_callback(),
39-
api_key_handler :: openapi_logic_handler:api_key_callback(),
39+
api_key_callback :: openapi_logic_handler:api_key_callback(),
4040
context = #{} :: openapi_logic_handler:context()}).
4141

4242
-type state() :: #state{}.
@@ -52,7 +52,7 @@ init(Req, {Operations, Module}) ->
5252
State = #state{operation_id = OperationID,
5353
accept_callback = fun Module:accept_callback/4,
5454
provide_callback = fun Module:provide_callback/4,
55-
api_key_handler = fun Module:authorize_api_key/2},
55+
api_key_callback = fun Module:api_key_callback/2},
5656
{cowboy_rest, Req, State}.
5757

5858
-spec allowed_methods(cowboy_req:req(), state()) ->

samples/server/echo_api/erlang-server/src/openapi_query_handler.erl

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ Test query parameter(s)
8181
{operation_id :: operation_id(),
8282
accept_callback :: openapi_logic_handler:accept_callback(),
8383
provide_callback :: openapi_logic_handler:provide_callback(),
84-
api_key_handler :: openapi_logic_handler:api_key_callback(),
84+
api_key_callback :: openapi_logic_handler:api_key_callback(),
8585
context = #{} :: openapi_logic_handler:context()}).
8686

8787
-type state() :: #state{}.
@@ -97,7 +97,7 @@ init(Req, {Operations, Module}) ->
9797
State = #state{operation_id = OperationID,
9898
accept_callback = fun Module:accept_callback/4,
9999
provide_callback = fun Module:provide_callback/4,
100-
api_key_handler = fun Module:authorize_api_key/2},
100+
api_key_callback = fun Module:api_key_callback/2},
101101
{cowboy_rest, Req, State}.
102102

103103
-spec allowed_methods(cowboy_req:req(), state()) ->

samples/server/echo_api/erlang-server/src/openapi_server.erl

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ get_cowboy_config(LogicHandler, ExtraOpts) ->
3131
maps:fold(fun get_cowboy_config/3, DefaultOpts, ExtraOpts).
3232

3333
get_cowboy_config(env, #{dispatch := _Dispatch} = Env, AccIn) ->
34-
maps:put(env, Env, AccIn);
34+
AccIn#{env => Env};
3535
get_cowboy_config(env, NewEnv, #{env := OldEnv} = AccIn) ->
3636
Env = maps:merge(OldEnv, NewEnv),
37-
maps:put(env, Env, AccIn);
37+
AccIn#{env => Env};
3838
get_cowboy_config(Key, Value, AccIn) ->
39-
maps:put(Key, Value, AccIn).
39+
AccIn#{Key => Value}.
4040

4141
get_default_dispatch(LogicHandler) ->
4242
Paths = openapi_router:get_paths(LogicHandler),

samples/server/petstore/erlang-server/src/openapi_api.erl

+1-1
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ populate_request_params(_, [], Req, _, Model) ->
525525
populate_request_params(OperationID, [ReqParamName | T], Req0, ValidatorState, Model0) ->
526526
case populate_request_param(OperationID, ReqParamName, Req0, ValidatorState) of
527527
{ok, V, Req} ->
528-
Model = maps:put(ReqParamName, V, Model0),
528+
Model = Model0#{ReqParamName => V},
529529
populate_request_params(OperationID, T, Req, ValidatorState, Model);
530530
Error ->
531531
Error

samples/server/petstore/erlang-server/src/openapi_pet_handler.erl

+18-18
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ uploads an image.
7171
{operation_id :: operation_id(),
7272
accept_callback :: openapi_logic_handler:accept_callback(),
7373
provide_callback :: openapi_logic_handler:provide_callback(),
74-
api_key_handler :: openapi_logic_handler:api_key_callback(),
74+
api_key_callback :: openapi_logic_handler:api_key_callback(),
7575
context = #{} :: openapi_logic_handler:context()}).
7676

7777
-type state() :: #state{}.
@@ -87,7 +87,7 @@ init(Req, {Operations, Module}) ->
8787
State = #state{operation_id = OperationID,
8888
accept_callback = fun Module:accept_callback/4,
8989
provide_callback = fun Module:provide_callback/4,
90-
api_key_handler = fun Module:authorize_api_key/2},
90+
api_key_callback = fun Module:api_key_callback/2},
9191
{cowboy_rest, Req, State}.
9292

9393
-spec allowed_methods(cowboy_req:req(), state()) ->
@@ -115,71 +115,71 @@ allowed_methods(Req, State) ->
115115
{true | {false, iodata()}, cowboy_req:req(), state()}.
116116
is_authorized(Req0,
117117
#state{operation_id = 'addPet' = OperationID,
118-
api_key_handler = Handler} = State) ->
119-
case openapi_auth:authorize_api_key(Handler, OperationID, header, "authorization", Req0) of
118+
api_key_callback = Handler} = State) ->
119+
case openapi_auth:authorize_api_key(Handler, OperationID, header, <<"authorization">>, Req0) of
120120
{true, Context, Req} ->
121121
{true, Req, State#state{context = Context}};
122122
{false, AuthHeader, Req} ->
123123
{{false, AuthHeader}, Req, State}
124124
end;
125125
is_authorized(Req0,
126126
#state{operation_id = 'deletePet' = OperationID,
127-
api_key_handler = Handler} = State) ->
128-
case openapi_auth:authorize_api_key(Handler, OperationID, header, "authorization", Req0) of
127+
api_key_callback = Handler} = State) ->
128+
case openapi_auth:authorize_api_key(Handler, OperationID, header, <<"authorization">>, Req0) of
129129
{true, Context, Req} ->
130130
{true, Req, State#state{context = Context}};
131131
{false, AuthHeader, Req} ->
132132
{{false, AuthHeader}, Req, State}
133133
end;
134134
is_authorized(Req0,
135135
#state{operation_id = 'findPetsByStatus' = OperationID,
136-
api_key_handler = Handler} = State) ->
137-
case openapi_auth:authorize_api_key(Handler, OperationID, header, "authorization", Req0) of
136+
api_key_callback = Handler} = State) ->
137+
case openapi_auth:authorize_api_key(Handler, OperationID, header, <<"authorization">>, Req0) of
138138
{true, Context, Req} ->
139139
{true, Req, State#state{context = Context}};
140140
{false, AuthHeader, Req} ->
141141
{{false, AuthHeader}, Req, State}
142142
end;
143143
is_authorized(Req0,
144144
#state{operation_id = 'findPetsByTags' = OperationID,
145-
api_key_handler = Handler} = State) ->
146-
case openapi_auth:authorize_api_key(Handler, OperationID, header, "authorization", Req0) of
145+
api_key_callback = Handler} = State) ->
146+
case openapi_auth:authorize_api_key(Handler, OperationID, header, <<"authorization">>, Req0) of
147147
{true, Context, Req} ->
148148
{true, Req, State#state{context = Context}};
149149
{false, AuthHeader, Req} ->
150150
{{false, AuthHeader}, Req, State}
151151
end;
152152
is_authorized(Req0,
153153
#state{operation_id = 'getPetById' = OperationID,
154-
api_key_handler = Handler} = State) ->
155-
case openapi_auth:authorize_api_key(Handler, OperationID, header, "authorization", Req0) of
154+
api_key_callback = Handler} = State) ->
155+
case openapi_auth:authorize_api_key(Handler, OperationID, header, <<"authorization">>, Req0) of
156156
{true, Context, Req} ->
157157
{true, Req, State#state{context = Context}};
158158
{false, AuthHeader, Req} ->
159159
{{false, AuthHeader}, Req, State}
160160
end;
161161
is_authorized(Req0,
162162
#state{operation_id = 'updatePet' = OperationID,
163-
api_key_handler = Handler} = State) ->
164-
case openapi_auth:authorize_api_key(Handler, OperationID, header, "authorization", Req0) of
163+
api_key_callback = Handler} = State) ->
164+
case openapi_auth:authorize_api_key(Handler, OperationID, header, <<"authorization">>, Req0) of
165165
{true, Context, Req} ->
166166
{true, Req, State#state{context = Context}};
167167
{false, AuthHeader, Req} ->
168168
{{false, AuthHeader}, Req, State}
169169
end;
170170
is_authorized(Req0,
171171
#state{operation_id = 'updatePetWithForm' = OperationID,
172-
api_key_handler = Handler} = State) ->
173-
case openapi_auth:authorize_api_key(Handler, OperationID, header, "authorization", Req0) of
172+
api_key_callback = Handler} = State) ->
173+
case openapi_auth:authorize_api_key(Handler, OperationID, header, <<"authorization">>, Req0) of
174174
{true, Context, Req} ->
175175
{true, Req, State#state{context = Context}};
176176
{false, AuthHeader, Req} ->
177177
{{false, AuthHeader}, Req, State}
178178
end;
179179
is_authorized(Req0,
180180
#state{operation_id = 'uploadFile' = OperationID,
181-
api_key_handler = Handler} = State) ->
182-
case openapi_auth:authorize_api_key(Handler, OperationID, header, "authorization", Req0) of
181+
api_key_callback = Handler} = State) ->
182+
case openapi_auth:authorize_api_key(Handler, OperationID, header, <<"authorization">>, Req0) of
183183
{true, Context, Req} ->
184184
{true, Req, State#state{context = Context}};
185185
{false, AuthHeader, Req} ->

samples/server/petstore/erlang-server/src/openapi_server.erl

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ get_cowboy_config(LogicHandler, ExtraOpts) ->
3131
maps:fold(fun get_cowboy_config/3, DefaultOpts, ExtraOpts).
3232

3333
get_cowboy_config(env, #{dispatch := _Dispatch} = Env, AccIn) ->
34-
maps:put(env, Env, AccIn);
34+
AccIn#{env => Env};
3535
get_cowboy_config(env, NewEnv, #{env := OldEnv} = AccIn) ->
3636
Env = maps:merge(OldEnv, NewEnv),
37-
maps:put(env, Env, AccIn);
37+
AccIn#{env => Env};
3838
get_cowboy_config(Key, Value, AccIn) ->
39-
maps:put(Key, Value, AccIn).
39+
AccIn#{Key => Value}.
4040

4141
get_default_dispatch(LogicHandler) ->
4242
Paths = openapi_router:get_paths(LogicHandler),

samples/server/petstore/erlang-server/src/openapi_store_handler.erl

+4-4
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Place an order for a pet.
5151
{operation_id :: operation_id(),
5252
accept_callback :: openapi_logic_handler:accept_callback(),
5353
provide_callback :: openapi_logic_handler:provide_callback(),
54-
api_key_handler :: openapi_logic_handler:api_key_callback(),
54+
api_key_callback :: openapi_logic_handler:api_key_callback(),
5555
context = #{} :: openapi_logic_handler:context()}).
5656

5757
-type state() :: #state{}.
@@ -67,7 +67,7 @@ init(Req, {Operations, Module}) ->
6767
State = #state{operation_id = OperationID,
6868
accept_callback = fun Module:accept_callback/4,
6969
provide_callback = fun Module:provide_callback/4,
70-
api_key_handler = fun Module:authorize_api_key/2},
70+
api_key_callback = fun Module:api_key_callback/2},
7171
{cowboy_rest, Req, State}.
7272

7373
-spec allowed_methods(cowboy_req:req(), state()) ->
@@ -87,8 +87,8 @@ allowed_methods(Req, State) ->
8787
{true | {false, iodata()}, cowboy_req:req(), state()}.
8888
is_authorized(Req0,
8989
#state{operation_id = 'getInventory' = OperationID,
90-
api_key_handler = Handler} = State) ->
91-
case openapi_auth:authorize_api_key(Handler, OperationID, header, "authorization", Req0) of
90+
api_key_callback = Handler} = State) ->
91+
case openapi_auth:authorize_api_key(Handler, OperationID, header, <<"authorization">>, Req0) of
9292
{true, Context, Req} ->
9393
{true, Req, State#state{context = Context}};
9494
{false, AuthHeader, Req} ->

0 commit comments

Comments
 (0)