Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ jobs:
- name: Compile
run: make compile

- name: Compile example
run: rebar3 as test compile
Comment thread
andreashasse marked this conversation as resolved.

- name: Run tests
run: make test

Expand Down
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ ElliOpts = [
{ok, Pid} = elli:start_link(ElliOpts).
```

See `src/elli_openapi_demo.erl` for example handler implementations.
See the `example/` directory for a runnable example application with handler implementations.

## Handler Functions

Expand Down Expand Up @@ -73,13 +73,20 @@ To return different status codes from the same handler, use union types in your
| {404, Headers3, NotFoundBody}.
```

For complete handler examples, see `src/elli_openapi_demo.erl`.
For complete handler examples, see `example/src/elli_openapi_demo.erl`.

## Demo
## Example Application

To try out the demo application:
The `example/` directory contains a runnable demo application showcasing multiple handler implementations including user management, echo, status updates, and item updates with conflict detection.

To run the example:

```bash
rebar3 compile
cd example
rebar3 shell
```

The demo starts on port 3000. Access the API documentation at:
- Swagger UI: http://localhost:3000/swagger
- ReDoc: http://localhost:3000/redoc
- OpenAPI JSON: http://localhost:3000/api-docs
27 changes: 0 additions & 27 deletions demo.escript

This file was deleted.

31 changes: 31 additions & 0 deletions example/demo.escript
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env escript
%% -*- erlang -*-
%%! -pa _build/default/lib/*/ebin

main(_) ->
Routes = [
{<<"POST">>, <<"/api/users">>, fun elli_openapi_demo:create_user/4},
{<<"GET">>, <<"/api/users/{userId}">>, fun elli_openapi_demo:get_user/4},
{<<"POST">>, <<"/api/echo">>, fun elli_openapi_demo:echo_text/4},
{<<"POST">>, <<"/api/status">>, fun elli_openapi_demo:update_status/4},
{<<"PUT">>, <<"/api/items/{itemId}">>, fun elli_openapi_demo:update_item/4},
{<<"GET">>, <<"/api/users">>, fun elli_openapi_demo:list_users/4},
{<<"GET">>, <<"/api/search">>, fun elli_openapi_demo:search_users/4}
],
Port = 3000,
ElliOpts = [
{callback, elli_openapi_handler},
{callback_args, Routes},
{port, Port}
],

%% Start Elli
case elli:start_link(ElliOpts) of
{ok, _Pid} ->
io:format(
"Elli openapi is started. Access the API documentation at: http://localhost:~p/swagger~n",
[Port]
);
{error, Reason} ->
io:format("Failed to start Elli server: ~p~n~n", [Reason])
end.
10 changes: 10 additions & 0 deletions example/rebar.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{erl_opts, [debug_info]}.

{deps, [
{elli_openapi, {path, ".."}}
]}.

{shell, [
{apps, [demo]},
{script_file, "demo.escript"}
]}.
5 changes: 5 additions & 0 deletions example/src/demo.app.src
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{application, demo, [
{description, "elli_openapi example application"},
{vsn, "0.1.0"},
{applications, [kernel, stdlib, elli, elli_openapi]}
]}.
File renamed without changes.
File renamed without changes.
8 changes: 2 additions & 6 deletions rebar.config
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
{erl_opts, [debug_info, warn_unused_import, warnings_as_errors]}.

{shell, [
{apps, [elli_openapi]},
{script_file, "demo.escript"}
]}.

{profiles, [
{test, [
{erl_opts, [nowarn_missing_spec]},
{extra_src_dirs, ["example/src"]},
{deps, [
{eqwalizer_support,
{git_subdir, "https://github.com/whatsapp/eqwalizer.git", {branch, "main"},
Expand All @@ -22,7 +18,7 @@
]}.

{hank, [
{ignore, ["test/*.erl"]}
{ignore, ["test/*.erl", "example/src/*.erl"]}
]}.

{project_plugins, [erlfmt, rebar3_hank, rebar3_lint, rebar3_ex_doc, rebar3_check_app_calls]}.
Expand Down
Loading