-
Notifications
You must be signed in to change notification settings - Fork 0
Upgrade spectra #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,7 @@ | |
|
|
||
| {deps, [ | ||
| {elli, "~> 3.3.0"}, | ||
| {spectra, "~> 0.2.0"} | ||
| {spectra, "~> 0.4.0"} | ||
| ]}. | ||
|
|
||
| {hank, [ | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -21,9 +21,8 @@ handle(#req{path = [~"api-docs"]}, _Args) -> | |||||||||||||||
| handle(ElliRequest, _Args) -> | ||||||||||||||||
| elli_openapi:route_call(ElliRequest). | ||||||||||||||||
|
|
||||||||||||||||
| -spec handle_event(Event, Args, Config) -> ok when | ||||||||||||||||
| -spec handle_event(Event, Args :: term(), Config) -> ok when | ||||||||||||||||
| Event :: elli_handler:event(), | ||||||||||||||||
| Args :: elli_handler:callback_args(), | ||||||||||||||||
| Config :: [tuple()]. | ||||||||||||||||
| handle_event(elli_startup, [], Routes) -> | ||||||||||||||||
| Modules = | ||||||||||||||||
|
|
@@ -37,5 +36,8 @@ handle_event(elli_startup, [], Routes) -> | |||||||||||||||
| lists:foreach(fun code:ensure_loaded/1, lists:usort(Modules)), | ||||||||||||||||
| elli_openapi:setup_routes(Routes), | ||||||||||||||||
| ok; | ||||||||||||||||
| handle_event(_Event, _Args, _Config) -> | ||||||||||||||||
| handle_event(request_complete, [Req, ReturnCode, _, _, _], _Config) -> | ||||||||||||||||
| io:format("Req complete: ~s ~p ~n", [elli_request:raw_path(Req), ReturnCode]), | ||||||||||||||||
|
||||||||||||||||
| io:format("Req complete: ~s ~p ~n", [elli_request:raw_path(Req), ReturnCode]), | |
| case application:get_env(elli_openapi, debug_logging, false) of | |
| true -> | |
| io:format("Req complete: ~s ~p ~n", [elli_request:raw_path(Req), ReturnCode]); | |
| _ -> | |
| ok | |
| end, |
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -0,0 +1,33 @@ | ||||
| -module(user_handler). | ||||
|
|
||||
| -export([get_user/3, create_user/3]). | ||||
|
|
||||
| -record(user, { | ||||
| id :: binary(), | ||||
| name :: binary(), | ||||
| role :: admin | user | guest | ||||
| }). | ||||
|
|
||||
| -ignore_xref([create_user/3, get_user/3]). | ||||
| -hank([{unnecessary_function_arguments, [{get_user, 3}]}]). | ||||
|
|
||||
| -spec get_user(#{userId := binary()}, #{}, binary()) -> | ||||
| {200, #{}, #user{}} | ||||
| | {404, #{}, #{message := binary()}}. | ||||
| get_user(#{userId := Id}, _Hdrs, _Body) -> | ||||
| case find_user(Id) of | ||||
| {ok, User} -> {200, #{}, User}; | ||||
| not_found -> {404, #{}, #{message => ~"User not found"}} | ||||
| end. | ||||
|
|
||||
| -spec create_user(#{}, #{}, #user{}) -> | ||||
| {201, #{'Location' => binary()}, #user{}}. | ||||
| create_user(#{}, #{}, User) -> | ||||
| io:format("Creating user: ~s with role ~p~n", [User#user.name, User#user.role]), | ||||
|
||||
| io:format("Creating user: ~s with role ~p~n", [User#user.name, User#user.role]), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The POST route has a trailing slash in the path which is inconsistent with the rest of the codebase. All other POST routes to /api/users use the path without a trailing slash. For example, in the test file test/elli_openapi_integration_SUITE.erl lines 78, 392, 449, and 534, the path is consistently <<"/api/users">> without a trailing slash.