Skip to content

Commit 1047c32

Browse files
luisgabrielroldanthbarCowagianluca-nittiGianluca Nitti
authored
Sync with upstream open_api_spex (through v3.22.3) (#4)
* Fix deprecation warning on Elixir 1.15, require Elixir 1.11, adapt CI (open-api-spex#550) * Fix deprecation warning on Elixir 1.15 * Stop testing against Elixir 1.10 * Require Elixir 1.11+ now * Update CHANGELOG.md * Add `--quiet` option for spec generation (open-api-spex#557) * Fix casting non-objects against discriminator open-api-spex#551 (open-api-spex#552) Co-authored-by: Gianluca Nitti <gianluca.nitti@voismart.it> * Bump credo version to 1.7.0 * Bump dialyxir to 1.3.0 * feat: add assert_operation_response, assert_raw_schema (open-api-spex#545) * feat: add assert_operation_response, assert_raw_schema * make assert_operation_response pipeable * fix return type * automagically infer operationId in assertion * don't need to resolve a %Schema{} * ignore 204s * use OpenApiSpex.OpenApi.json_encoder() * rename test to match fn * reorganize json_encoder check per feedback * update json_encoder message for :jason or :poison * use a regex to match json content types in validate_operation_response * 💅 feedback - types, error message, module attrib for regex * add doc for content_type_from_header * remove no_return from spec * Release version 3.18.0 * Document the spec export task `--filename` option * Docstest Operation.parameter/5 * Cast discriminator when no title present (open-api-spex#574) Co-authored-by: Alberto Sartori <alberto.sartori@hpe.com> * Exclude empty paths from spec (open-api-spex#583) * Exclude empty paths from spec * fix: assert_operation_response header lookup (open-api-spex#584) * fix: assert_operation_response header lookup * Release version 3.18.1 * Fix 'AllOf cast returns a map, but I expected a struct' (open-api-spex#592) * Add failing test * Cast result of AllOf cast into a struct * Shorter module name * Add missing NoneCache test * Release version 3.18.2 * Relax dependency constraint on ymlr to allow version ~> 5.0 (open-api-spex#586) * relax dependency on ymlr, and fix some tests * test with more elixir versions * Update Elixir version test matrix (open-api-spex#602) * Update Elixir version test matrix * Fix map key order dependent test * Release version 3.18.3 * Support response code ranges See: https://swagger.io/docs/specification/describing-responses/ * Release version 3.19.0 * Add notice that body params are not merged into Conn.params whne using cast and validate plug (open-api-spex#589) * Set nonces on <script> and <style> elements if configured (open-api-spex#593) * Allow script and style nonces * Allow nonces on the SwaggerUIOAuth2Redirect plug as well * fix: ensure operation_id is always set on conn.private (open-api-spex#606) * fix: ensure operation_id is always set on conn.private when an operation is known * Fix grammer (open-api-spex#607) * Release version 3.19.1 * Respect minLength when generating string examples (open-api-spex#608) * sets read_write_scope from opts, this will permit to comply to readOnly (open-api-spex#572) * Allow Poison v6 to be used (open-api-spex#616) * chore: Drop build matrix support for elixir 1.11, 1.12, 1.13 and OTP 22 (open-api-spex#619) * improvement: use struct spec to avoid double `%` in struct inspect (open-api-spex#613) * improvement: use struct spec to avoid double `%` in struct inspect currently, inspecting an `OpenApiSpex.Schema` looks like this: `%OpenApiSpex.Schema%{type: :object}` with the new change, it looks like this: `%OpenApiSpex.Schema{type: :object}` which allows copy/pasting the struct * Feat: add --check option in Mix tasks to compare generated spec w/ file (open-api-spex#618) Add a --check option to run Mix tasks and compare the generated spec with a previously generated file. This is useful for scenarios where a CI check is desirable to catch unwanted drifts from a validated OpenAPI spec: e.g. the OpenAPI spec is committed and reviewed, and should not change without additional review. Fixes open-api-spex#617 Signed-off-by: Davide Briani <davide@briani.dev> * fix: cast numbers as floats (open-api-spex#611) * Release version 3.20.0 * Update Elixir version in release action * Set otp-version to 25 in release.yml * Support custom error messages in custom validators (open-api-spex#621) * Add custom message for custom validators * Update Schema.example/2 typespec to allow references * Release version 3.20.1 * Update dev dependencies and example apps (open-api-spex#624) * Support casting decimals (open-api-spex#634) * Update decode.ex to support servers in operations (open-api-spex#635) Fix typo * Update spec fixture to test open-api-spex#635 * Release version 3.21.0 * Fix schema inspect argument error in IEx * Release version 3.21.1 * Upgrade SwaggerUI to version 5.17.14 and allow assets URLs to be configured via Plug options (open-api-spex#628) * fix: Exporting to YAML preserves nil values in examples * Release version 3.21.2 * Fix cast x-validate when decoded schema (open-api-spex#647) * Fix cast x-validate when decoded schema * fix credo complain when using apply/3 --------- Co-authored-by: Giorgio Torres <giorgio.torres@hpe.com> * Bump CI dependencies (open-api-spex#655) * Add examples property to Schema (open-api-spex#654) Fixes open-api-spex#653 * Document schema resolver duplicate titles behaviour (open-api-spex#656) * Add spec.yaml tasks to example applications (open-api-spex#657) * Add mix spec.yaml tasks in example applications * Update example application dependencies * Fix 1.18 compilation warnings (open-api-spex#665) * Fix Elixir 1.18 compilation warnings * Test against 1.18 * Check for ex_doc warnings in CI and bump devtest deps (open-api-spex#666) * Test array query params in example phoenix app (open-api-spex#667) * Release 3.21.3 * Fix OTP-28 support (open-api-spex#672) * Refactor: Update default parsers and schema pattern definitions This commit introduces changes to `OpenApiSpex.CastParameters` and `OpenApiSpexTest.Schemas`. - Moved `@default_parsers` to a private function `default_parsers/0` in `OpenApiSpex.CastParameters` to ensure it's evaluated at runtime, preventing potential compilation issues with `OpenApi.json_encoder()`. - Updated the `pattern` definition in `OpenApiSpexTest.Schemas` to use a string literal instead of a regex literal for consistency and to avoid potential issues with regex compilation. Fix: Adjust string pattern test assertion Following the refactoring, a test in `OpenApiSpex.CastStringTest` failed due to a change in how regex patterns were handled. This fix corrects the assertion for string pattern matching to compare the `source` of the regex instead of the regex struct directly, resolving the test failure. * Fix formatting --------- Co-authored-by: Dimitris Zorbas <dimitrisplusplus@gmail.com> * Release version 3.21.4 * Fix assert_operation_response/2 references (open-api-spex#673) * Support references in assert_operation_response/2 * fixup! Support references in assert_operation_response/2 * Release version 3.21.5 * Support multiple apps in Plug.SwaggerUI (open-api-spex#676) * Validate keys given to operation/2 macro (open-api-spex#675) * Release version 3.22.0 * Fix elixir 1.19 support (open-api-spex#685) * Release version 3.22.1 * fix: type warnings Elixir 1.19 (open-api-spex#693) Thanks @davydog187 ! * Release version 3.22.2 * chore: removed unused require(s) (open-api-spex#700) * Relax decimal requirement (open-api-spex#702) A new release will be out soon, this will allow users to migrate if desired. The new version is compatible with OpenAPISpex. * Release version 3.22.3 --------- Signed-off-by: Davide Briani <davide@briani.dev> Co-authored-by: Thibaut Barrère <thibaut.barrere@gmail.com> Co-authored-by: Brice Thomas <brice.p.thomas@gmail.com> Co-authored-by: Gianluca Nitti <gianluca.nitti96@gmail.com> Co-authored-by: Gianluca Nitti <gianluca.nitti@voismart.it> Co-authored-by: Dimitris Zorbas <dimitrisplusplus@gmail.com> Co-authored-by: Matt Sutkowski <msutkowski@gmail.com> Co-authored-by: Alberto Sartori <alberto.sartori@athonet.com> Co-authored-by: Alberto Sartori <alberto.sartori@hpe.com> Co-authored-by: Alisina Bahadori <alisina.bm@gmail.com> Co-authored-by: Angelika Tyborska <angelikatyborska@fastmail.com> Co-authored-by: Aleksandr Lossenko <aleksandr.lossenko@memsource.com> Co-authored-by: Amir Hasanbasic <43892661+hamir-suspect@users.noreply.github.com> Co-authored-by: Nathan Alderson <me@nathanalderson.com> Co-authored-by: E. Sambo <news@emmanuelsambo.com> Co-authored-by: Alberto Sartori <alberto.sartori.as@gmail.com> Co-authored-by: Hans Krutzer <git@pixelspaceships.com> Co-authored-by: Mike Buhot <m.buhot@gmail.com> Co-authored-by: Zach Daniel <zachary.s.daniel@gmail.com> Co-authored-by: Davide Briani <60540759+davidebriani@users.noreply.github.com> Co-authored-by: David-Klemenc <44705886+David-Klemenc@users.noreply.github.com> Co-authored-by: GregorGrasselli <GregorGrasselli@users.noreply.github.com> Co-authored-by: Sergey Loguntsov <loguntsov@list.ru> Co-authored-by: Jarmo Pertman <jarmo@jarmopertman.com> Co-authored-by: Giorgio Primola <torres.giorgio@icloud.com> Co-authored-by: Giorgio Torres <giorgio.torres@hpe.com> Co-authored-by: Georges Dubus <georges.dubus@gmail.com> Co-authored-by: Sergey Moiseev <moiseev.sergey@gmail.com> Co-authored-by: David Pavlík <pavlik.d@seznam.cz> Co-authored-by: Adam C. Stephens <2071575+adamcstephens@users.noreply.github.com> Co-authored-by: Dave Lucia <dave@tvlabs.ai> Co-authored-by: José Valim <jose.valim@gmail.com>
1 parent d60b6a5 commit 1047c32

83 files changed

Lines changed: 1845 additions & 568 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/elixir.yml

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ jobs:
1212
runs-on: ubuntu-latest
1313
strategy:
1414
matrix:
15-
otp: ['25']
16-
elixir: ['1.13']
15+
otp: ["26"]
16+
elixir: ["1.16"]
1717
steps:
1818
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
1919
- uses: erlef/setup-beam@v1
@@ -34,7 +34,8 @@ jobs:
3434
- run: mix compile --warnings-as-errors
3535
- run: mix format --check-formatted
3636
- run: mix credo --strict --all
37-
- run: mix dialyzer
37+
- run: mix dialyzer --format github
38+
- run: mix docs --warnings-as-errors
3839

3940
test_examples:
4041
runs-on: ubuntu-latest
@@ -44,9 +45,10 @@ jobs:
4445
steps:
4546
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
4647
- uses: erlef/setup-beam@v1
48+
id: beam
4749
with:
48-
otp-version: 24
49-
elixir-version: 1.13
50+
otp-version: 26
51+
elixir-version: 1.16
5052
- uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
5153
with:
5254
key: |
@@ -61,20 +63,24 @@ jobs:
6163
run: mix do deps.get, test
6264

6365
test:
64-
runs-on: ubuntu-20.04
66+
runs-on: ubuntu-24.04
6567
name: Test (OTP ${{matrix.otp}} / Elixir ${{matrix.elixir}})
6668
strategy:
6769
matrix:
68-
otp: ['22', '23', '24', '25']
69-
elixir: ['1.10', '1.11', '1.12', '1.13']
70+
otp: ["24", "25", "26"]
71+
elixir: ["1.14", "1.15", "1.16", "1.18"]
72+
# Test each elixir version with lowest and highest compatible OTP version, exclude others
73+
# See https://hexdocs.pm/elixir/compatibility-and-deprecations.html#between-elixir-and-erlang-otp
7074
exclude:
71-
- {otp: '24', elixir: '1.10'}
72-
- {otp: '25', elixir: '1.10'}
73-
- {otp: '25', elixir: '1.11'}
74-
- {otp: '25', elixir: '1.12'}
75+
- { otp: "24", elixir: "1.14" }
76+
- { otp: "24", elixir: "1.18" }
77+
- { otp: "25", elixir: "1.14" }
78+
- { otp: "25", elixir: "1.15" }
79+
- { otp: "25", elixir: "1.16" }
7580
steps:
7681
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
7782
- uses: erlef/setup-beam@v1
83+
id: beam
7884
with:
7985
otp-version: ${{matrix.otp}}
8086
elixir-version: ${{matrix.elixir}}

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
id: beam
1717
with:
1818
otp-version: 25
19-
elixir-version: 1.13
19+
elixir-version: 1.14
2020

2121
- id: deps
2222
name: Fetch and compile dependencies

CHANGELOG.md

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,103 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## v3.22.3 - 2026-05-05
9+
10+
* chore: removed unused require(s) by @David-Klemenc in https://github.com/open-api-spex/open_api_spex/pull/700
11+
* Relax decimal requirement by @josevalim in https://github.com/open-api-spex/open_api_spex/pull/702
12+
13+
## v3.22.2 - 2026-01-08
14+
15+
* fix: type warnings Elixir 1.19 by @davydog187 in https://github.com/open-api-spex/open_api_spex/pull/693
16+
17+
## v3.22.1 - 2025-11-21
18+
19+
* Fix elixir 1.19 support by @adamcstephens in https://github.com/open-api-spex/open_api_spex/pull/685
20+
21+
## v3.22.0 - 2025-08-05
22+
23+
* Support multiple apps in Plug.SwaggerUI by @zorbash in https://github.com/open-api-spex/open_api_spex/pull/676
24+
* Validate keys given to operation/2 macro by @xxdavid in https://github.com/open-api-spex/open_api_spex/pull/675
25+
26+
## v3.21.5 - 2025-07-08
27+
28+
* Fix assert_operation_response/2 references by @zorbash in https://github.com/open-api-spex/open_api_spex/pull/673
29+
30+
## v3.21.4 - 2025-07-01
31+
32+
* Fix OTP-28 support by @bopm in https://github.com/open-api-spex/open_api_spex/pull/672
33+
34+
## v3.21.3 - 2025-06-25
35+
36+
* Fix cast x-validate when decoded schema by @GPrimola in https://github.com/open-api-spex/open_api_spex/pull/647
37+
* Add examples property to Schema by @madjar in https://github.com/open-api-spex/open_api_spex/pull/654
38+
* Document schema resolver duplicate titles behaviour by @zorbash in https://github.com/open-api-spex/open_api_spex/pull/656
39+
* Fix 1.18 compilation warnings by @zorbash in https://github.com/open-api-spex/open_api_spex/pull/665
40+
41+
## v3.21.2 - 2024-10-02
42+
43+
* Use latest version of SwaggerUI by default, but allow it to be configured by @jarmo in https://github.com/open-api-spex/open_api_spex/pull/628
44+
* Exporting to YAML preserves nil values in examples by @zorbash in f3cd32bee2a
45+
46+
## v3.21.1 - 2024-09-17
47+
48+
* Fix schema inspection argument error by @zorbash. https://github.com/open-api-spex/open_api_spex/issues/636
49+
50+
## v3.21.0 - 2024-09-12
51+
52+
* Update dev dependencies and example apps by @zorbash in https://github.com/open-api-spex/open_api_spex/pull/624
53+
* Support casting decimals by @zorbash in https://github.com/open-api-spex/open_api_spex/pull/634
54+
* Support decoding operations with :servers. by @loguntsov in https://github.com/open-api-spex/open_api_spex/pull/635
55+
56+
## v3.20.1 - 2024-07-31
57+
58+
* Support custom error messages in custom validators by @GregorGrasselli in https://github.com/open-api-spex/open_api_spex/pull/621
59+
* Update Schema.example/2 typespec to allow references by @zorbash in 5ec452f
60+
61+
## v3.20.0 - 2024-07-10
62+
63+
* Respect minLength when generating string examples by @zorbash in https://github.com/open-api-spex/open_api_spex/pull/608
64+
* Accept read_write_scope from opts when calling cast functions directly by @albertored in https://github.com/open-api-spex/open_api_spex/pull/572
65+
* Allow Poison v6 to be used by @hkrutzer in https://github.com/open-api-spex/open_api_spex/pull/616
66+
* chore: Drop build matrix support for elixir 1.11, 1.12, 1.13 and OTP 22 by @mbuhot in https://github.com/open-api-spex/open_api_spex/pull/619
67+
* improvement: use struct spec to avoid double `%` in struct inspect by @zachdaniel in https://github.com/open-api-spex/open_api_spex/pull/613
68+
* Feat: add `--check` option in Mix tasks to compare the generated spec with a previously generated file by @davidebriani in https://github.com/open-api-spex/open_api_spex/pull/618
69+
* fix: cast numbers as floats by @David-Klemenc in https://github.com/open-api-spex/open_api_spex/pull/611
70+
71+
## v3.19.1 - 2024-05-17
72+
73+
* Add notice that body params are not merged into Conn.params whne using cast and validate plug by @hamir-suspect in #589
74+
* Set nonces on `<script>` and `<style>` elements if configured by @nathanalderson in #593
75+
* Ensure operation_id is always set on conn.private by @msutkowski in #606
76+
77+
## v3.19.0 - 2024-04-30
78+
79+
* Support response code ranges by @zorbash in 8898859da1
80+
81+
## v3.18.3 - 2024-03-15
82+
83+
* Relax dependency constraint on ymlr to allow version ~> 5.0 by @egze in https://github.com/open-api-spex/open_api_spex/pull/586
84+
85+
## v3.18.2 - 2024-01-26
86+
87+
* Fix 'AllOf cast returns a map, but I expected a struct' by @angelikatyborska in https://github.com/open-api-spex/open_api_spex/pull/592
88+
89+
## v3.18.1 - 2023-12-19
90+
91+
* Fix `assert_operation_response/2` header lookup by @msutkowski in https://github.com/open-api-spex/open_api_spex/pull/584
92+
* Exclude empty paths (`operation false`) from generated spec by @alisinabh in https://github.com/open-api-spex/open_api_spex/pull/583
93+
* Cast discriminator when no title present (#574) by @albertored in https://github.com/open-api-spex/open_api_spex/pull/574
94+
* Docstest Operation.parameter/5 by @zorbash
95+
* Document the spec export task `--filename` option by @zorbash
96+
97+
## v3.18.0 - 2023-08-23
98+
99+
* Relax dependency constraint on ymlr to allow version ~> 4.0 by @arcanemachine in https://github.com/open-api-spex/open_api_spex/pull/544
100+
* Fix deprecation warning on Elixir 1.15, require Elixir 1.11, adapt CI by @thbar in https://github.com/open-api-spex/open_api_spex/pull/550
101+
* Add `--quiet` option for spec generation by @Cowa in https://github.com/open-api-spex/open_api_spex/pull/557
102+
* Fix casting non-objects against discriminator #551 by @gianluca-nitti in https://github.com/open-api-spex/open_api_spex/pull/552
103+
* feat: add assert_operation_response, assert_raw_schema by @msutkowski in https://github.com/open-api-spex/open_api_spex/pull/545
104+
8105
## v3.17.3 - 2023-05-30
9106

10107
* Raise meaningful error message when `SchemaResolver.resolve_schema_modules_from_schema` failed to pattern match by @yuchunc in https://github.com/open-api-spex/open_api_spex/pull/541

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ The package can be installed by adding `:open_api_spex` to your list of dependen
2424
```elixir
2525
def deps do
2626
[
27-
{:open_api_spex, "~> 3.16"}
27+
{:open_api_spex, "~> 3.21"}
2828
]
2929
end
3030
```
@@ -282,7 +282,7 @@ mix openapi.spec.yaml --spec MyAppWeb.ApiSpec
282282
Invoking this task starts the application by default. This can be
283283
disabled with the `--start-app=false` option.
284284

285-
Please make to replace any calls to [OpenApiSpex.Server.from_endpoint](https://hexdocs.pm/open_api_spex/OpenApiSpex.Server.html#from_endpoint/1) with a `%OpenApiSpex.Server{}` struct like below:
285+
Please replace any calls to [OpenApiSpex.Server.from_endpoint](https://hexdocs.pm/open_api_spex/OpenApiSpex.Server.html#from_endpoint/1) with a `%OpenApiSpex.Server{}` struct like below:
286286

287287
```elixir
288288
%OpenApi{

examples/phoenix_app/config/dev.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ config :logger, :console, format: "[$level] $message\n"
1010
config :phoenix, :stacktrace_depth, 20
1111

1212
config :phoenix_app, PhoenixApp.Repo,
13-
adapter: Sqlite.Ecto2,
13+
adapter: Ecto.Adapters.SQLite3,
1414
database: "priv/repo/phoenix_app_dev.db"

examples/phoenix_app/config/test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ config :phoenix_app, PhoenixAppWeb.Endpoint,
44
http: [port: 4001],
55
server: false
66

7-
config :logger, level: :warn
7+
config :logger, level: :warning
88

99
config :phoenix_app, PhoenixApp.Repo, pool: Ecto.Adapters.SQL.Sandbox
1010

1111
config :phoenix_app, PhoenixApp.Repo,
12-
adapter: Sqlite.Ecto2,
12+
adapter: Ecto.Adapters.SQLite3,
1313
database: "priv/repo/phoenix_app_test.db"

examples/phoenix_app/lib/phoenix_app/accounts/accounts.ex

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,19 @@ defmodule PhoenixApp.Accounts do
22
alias PhoenixApp.Accounts.User
33
alias PhoenixApp.Repo
44

5-
def list_users() do
6-
Repo.all(User)
5+
import Ecto.Query
6+
7+
def list_users(filters) do
8+
query = from(u in User, order_by: [asc: u.id])
9+
10+
query =
11+
if filters[:ids] do
12+
from(u in query, where: u.id in ^filters[:ids])
13+
else
14+
query
15+
end
16+
17+
Repo.all(query)
718
end
819

920
def get_user!(id) do
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
defmodule PhoenixApp.Repo do
2-
use Ecto.Repo, otp_app: :phoenix_app, adapter: Sqlite.Ecto2
2+
use Ecto.Repo, otp_app: :phoenix_app, adapter: Ecto.Adapters.SQLite3
33
end

examples/phoenix_app/lib/phoenix_app_web/controllers/user_controller.ex

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,22 @@ defmodule PhoenixAppWeb.UserController do
2121
operation :index,
2222
summary: "List users",
2323
description: "List all users",
24+
parameters: [
25+
OpenApiSpex.Operation.parameter(
26+
:ids,
27+
:query,
28+
%Schema{type: :array, items: %Schema{type: :integer}},
29+
"Filter by user ids"
30+
)
31+
],
2432
responses: [
2533
ok: {"User List Response", "application/json", Schemas.UsersResponse},
2634
unprocessable_entity: %Reference{"$ref": "#/components/responses/unprocessable_entity"}
2735
]
2836

29-
def index(conn, _params) do
30-
users = Accounts.list_users()
37+
def index(conn, params) do
38+
users = Accounts.list_users(params)
39+
3140
render(conn, "index.json", users: users)
3241
end
3342

@@ -37,8 +46,7 @@ defmodule PhoenixAppWeb.UserController do
3746
parameters: [
3847
group_id: [in: :path, type: :integer, description: "Group ID", example: 1]
3948
],
40-
request_body:
41-
{"The user attributes", "application/json", Schemas.UserRequest, required: true},
49+
request_body: {"The user attributes", "application/json", Schemas.UserRequest, required: true},
4250
responses: [
4351
created: {"User", "application/json", Schemas.UserResponse}
4452
]
@@ -88,8 +96,7 @@ defmodule PhoenixAppWeb.UserController do
8896
required: true
8997
]
9098
],
91-
request_body:
92-
{"The user attributes", "application/json", Schemas.UserRequest, required: true},
99+
request_body: {"The user attributes", "application/json", Schemas.UserRequest, required: true},
93100
responses: [
94101
ok: {"User", "application/json", Schemas.UserResponse}
95102
]

examples/phoenix_app/lib/phoenix_app_web/controllers/user_controller_with_struct_specs.ex

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ defmodule PhoenixAppWeb.UserControllerWithStructSpecs do
44
of using the ExDoc-based operation specs.
55
"""
66
use PhoenixAppWeb, :controller
7+
78
import OpenApiSpex.Operation, only: [parameter: 5, request_body: 4, response: 3]
8-
alias OpenApiSpex.{Operation, Reference}
9+
10+
alias OpenApiSpex.{Operation, Reference, Schema}
911
alias PhoenixApp.{Accounts, Accounts.User}
1012
alias PhoenixAppWeb.Schemas
1113

@@ -34,15 +36,24 @@ defmodule PhoenixAppWeb.UserControllerWithStructSpecs do
3436
summary: "List users",
3537
description: "List all useres",
3638
operationId: "UserController.index",
39+
parameters: [
40+
OpenApiSpex.Operation.parameter(
41+
:ids,
42+
:query,
43+
%Schema{type: :array, items: %Schema{type: :integer}},
44+
"Filter by user ids"
45+
)
46+
],
3747
responses: %{
3848
200 => response("User List Response", "application/json", Schemas.UsersResponse),
3949
422 => %Reference{"$ref": "#/components/responses/unprocessable_entity"}
4050
}
4151
}
4252
end
4353

44-
def index(conn, _params) do
45-
users = Accounts.list_users()
54+
def index(conn, params) do
55+
users = Accounts.list_users(params)
56+
4657
render(conn, "index.json", users: users)
4758
end
4859

@@ -56,9 +67,7 @@ defmodule PhoenixAppWeb.UserControllerWithStructSpecs do
5667
Operation.parameter(:group_id, :path, :integer, "Group ID", example: 1)
5768
],
5869
requestBody:
59-
request_body("The user attributes", "application/json", Schemas.UserRequest,
60-
required: true
61-
),
70+
request_body("The user attributes", "application/json", Schemas.UserRequest, required: true),
6271
responses: %{
6372
201 => response("User", "application/json", Schemas.UserResponse)
6473
}

0 commit comments

Comments
 (0)