Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
63ee100
Fix deprecation warning on Elixir 1.15, require Elixir 1.11, adapt CI…
thbar Jul 25, 2023
5560d0a
Add `--quiet` option for spec generation (#557)
Cowa Aug 18, 2023
3aa4c9d
Fix casting non-objects against discriminator #551 (#552)
gianluca-nitti Aug 18, 2023
37743cf
Bump credo version to 1.7.0
zorbash Aug 18, 2023
6edb86d
Bump dialyxir to 1.3.0
zorbash Aug 18, 2023
7a0309a
feat: add assert_operation_response, assert_raw_schema (#545)
msutkowski Aug 23, 2023
c1dbca1
Release version 3.18.0
zorbash Aug 23, 2023
f90bc11
Document the spec export task `--filename` option
zorbash Sep 4, 2023
7c05fa0
Docstest Operation.parameter/5
zorbash Sep 13, 2023
531607c
Cast discriminator when no title present (#574)
albertored Nov 22, 2023
ae71a1c
Exclude empty paths from spec (#583)
alisinabh Dec 18, 2023
fb02fb7
fix: assert_operation_response header lookup (#584)
msutkowski Dec 18, 2023
e4deef5
Release version 3.18.1
zorbash Dec 19, 2023
0b1396c
Fix 'AllOf cast returns a map, but I expected a struct' (#592)
angelikatyborska Jan 16, 2024
d6d3c89
Add missing NoneCache test
zorbash Jan 17, 2024
d9cfffe
Release version 3.18.2
zorbash Jan 26, 2024
844f24a
Relax dependency constraint on ymlr to allow version ~> 5.0 (#586)
Feb 13, 2024
3bfa049
Update Elixir version test matrix (#602)
zorbash Mar 15, 2024
12dc58f
Release version 3.18.3
zorbash Mar 15, 2024
8898859
Support response code ranges
zorbash Apr 30, 2024
fd0d842
Release version 3.19.0
zorbash Apr 30, 2024
699f876
Add notice that body params are not merged into Conn.params whne usin…
hamir-suspect May 12, 2024
78cf5fd
Set nonces on <script> and <style> elements if configured (#593)
nathanalderson May 12, 2024
3f54e57
fix: ensure operation_id is always set on conn.private (#606)
msutkowski May 15, 2024
012c8ab
Fix grammer (#607)
esambo May 17, 2024
826ce1d
Release version 3.19.1
zorbash May 17, 2024
10042c2
Respect minLength when generating string examples (#608)
zorbash May 23, 2024
e8a3538
sets read_write_scope from opts, this will permit to comply to readOn…
albertored May 24, 2024
5e3b16b
Allow Poison v6 to be used (#616)
hkrutzer Jul 4, 2024
5d3e70f
chore: Drop build matrix support for elixir 1.11, 1.12, 1.13 and OTP …
mbuhot Jul 7, 2024
5a79def
improvement: use struct spec to avoid double `%` in struct inspect (#…
zachdaniel Jul 7, 2024
56dcf23
Feat: add --check option in Mix tasks to compare generated spec w/ fi…
davidebriani Jul 7, 2024
8ec9969
fix: cast numbers as floats (#611)
David-Klemenc Jul 7, 2024
2794db6
Release version 3.20.0
zorbash Jul 10, 2024
b039b71
Update Elixir version in release action
zorbash Jul 10, 2024
c90e46e
Set otp-version to 25 in release.yml
zorbash Jul 10, 2024
19ffc49
Support custom error messages in custom validators (#621)
GregorGrasselli Jul 16, 2024
5ec452f
Update Schema.example/2 typespec to allow references
zorbash Jul 31, 2024
7d388cd
Release version 3.20.1
zorbash Jul 31, 2024
5dfd3f5
Update dev dependencies and example apps (#624)
zorbash Jul 31, 2024
fc79f1d
Support casting decimals (#634)
zorbash Sep 11, 2024
30d34c9
Update decode.ex to support servers in operations (#635)
loguntsov Sep 12, 2024
4b0efd6
Update spec fixture to test #635
zorbash Sep 12, 2024
e73e4fe
Release version 3.21.0
zorbash Sep 12, 2024
6b715a9
Fix schema inspect argument error in IEx
zorbash Sep 17, 2024
3773ece
Release version 3.21.1
zorbash Sep 17, 2024
3ffce33
Upgrade SwaggerUI to version 5.17.14 and allow assets URLs to be conf…
jarmo Sep 21, 2024
f3cd32b
fix: Exporting to YAML preserves nil values in examples
zorbash Oct 2, 2024
1447498
Release version 3.21.2
zorbash Oct 2, 2024
620c57e
Fix cast x-validate when decoded schema (#647)
GPrimola Dec 16, 2024
abe90e3
Bump CI dependencies (#655)
zorbash Mar 3, 2025
4a3f7a3
Add examples property to Schema (#654)
madjar Mar 7, 2025
439fadc
Document schema resolver duplicate titles behaviour (#656)
zorbash Mar 7, 2025
02d8c15
Add spec.yaml tasks to example applications (#657)
zorbash Mar 7, 2025
fa34dd0
Fix 1.18 compilation warnings (#665)
zorbash May 25, 2025
22f46f5
Check for ex_doc warnings in CI and bump devtest deps (#666)
zorbash May 26, 2025
410f3aa
Test array query params in example phoenix app (#667)
zorbash May 26, 2025
dcb1be5
Update Pull Request Template
kellym Jul 24, 2023
3493cab
support tagGroups
stwf Jul 25, 2023
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
37 changes: 37 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
## Description of the change

> Description here

## Type of change
- [ ] Bug fix (non-breaking change that fixes an issue)
- [ ] New feature (non-breaking change that adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] Configuration change
- [ ] Technical Debt
- [ ] Documentation

## Related tickets

> Link to Shortcut/Jira Ticket Goes Here

## Checklists

### Development and Testing

- [ ] Lint rules pass locally.
- [ ] The code changed/added as part of this pull request has been covered with tests, or this PR does not alter production code.
- [ ] All tests related to the changed code pass in development, or tests are not applicable.

### Code Review

- [ ] This pull request has a descriptive title and information useful to a reviewer. There may be a screenshot or screencast attached.
- [ ] At least two engineers have been added as "Reviewers" on the pull request.
- [ ] Changes have been reviewed by at least two other engineers who did not write the code.
- [ ] This branch has been rebased off master to be current.

### Tracking
- [ ] Issue from Shortcut/Jira has a link to this pull request.
- [ ] This PR has a link to the issue in Shortcut.

### QA
- [ ] This branch has been deployed to staging and tested.
42 changes: 24 additions & 18 deletions .github/workflows/elixir.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
otp: ['25']
elixir: ['1.13']
otp: ["26"]
elixir: ["1.16"]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: erlef/setup-beam@v1
id: beam
with:
otp-version: ${{matrix.otp}}
elixir-version: ${{matrix.elixir}}
- name: PLT cache
uses: actions/cache@v2
uses: actions/cache@v4
with:
key: |
${{ runner.os }}-${{ steps.beam.outputs.elixir-version }}-${{ steps.beam.outputs.otp-version }}-plt
Expand All @@ -34,20 +34,22 @@ jobs:
- run: mix compile --warnings-as-errors
- run: mix format --check-formatted
- run: mix credo --strict --all
- run: mix dialyzer
- run: mix dialyzer --format github
- run: mix docs --warnings-as-errors

test_examples:
runs-on: ubuntu-latest
name: Test Sample Applications
env:
MIX_ENV: test
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: erlef/setup-beam@v1
id: beam
with:
otp-version: 24
elixir-version: 1.13
- uses: actions/cache@v2
otp-version: 26
elixir-version: 1.16
- uses: actions/cache@v4
with:
key: |
${{ runner.os }}-${{ steps.beam.outputs.elixir-version }}-${{ steps.beam.outputs.otp-version }}-plug-build
Expand All @@ -61,24 +63,28 @@ jobs:
run: mix do deps.get, test

test:
runs-on: ubuntu-20.04
runs-on: ubuntu-24.04
name: Test (OTP ${{matrix.otp}} / Elixir ${{matrix.elixir}})
strategy:
matrix:
otp: ['22', '23', '24', '25']
elixir: ['1.10', '1.11', '1.12', '1.13']
otp: ["24", "25", "26"]
elixir: ["1.14", "1.15", "1.16", "1.18"]
# Test each elixir version with lowest and highest compatible OTP version, exclude others
# See https://hexdocs.pm/elixir/compatibility-and-deprecations.html#between-elixir-and-erlang-otp
exclude:
- {otp: '24', elixir: '1.10'}
- {otp: '25', elixir: '1.10'}
- {otp: '25', elixir: '1.11'}
- {otp: '25', elixir: '1.12'}
- { otp: "24", elixir: "1.14" }
- { otp: "24", elixir: "1.18" }
- { otp: "25", elixir: "1.14" }
- { otp: "25", elixir: "1.15" }
- { otp: "25", elixir: "1.16" }
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: erlef/setup-beam@v1
id: beam
with:
otp-version: ${{matrix.otp}}
elixir-version: ${{matrix.elixir}}
- uses: actions/cache@v2
- uses: actions/cache@v4
with:
key: |
${{ runner.os }}-${{ steps.beam.outputs.elixir-version }}-${{ steps.beam.outputs.otp-version }}-build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
id: beam
with:
otp-version: 25
elixir-version: 1.13
elixir-version: 1.14

- id: deps
name: Fetch and compile dependencies
Expand Down
65 changes: 65 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,71 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).


## v3.21.2 - 2024-10-02

* 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
* Exporting to YAML preserves nil values in examples by @zorbash in f3cd32bee2a

## v3.21.1 - 2024-09-17

* Fix schema inspection argument error by @zorbash. https://github.com/open-api-spex/open_api_spex/issues/636

## v3.21.0 - 2024-09-12

* Update dev dependencies and example apps by @zorbash in https://github.com/open-api-spex/open_api_spex/pull/624
* Support casting decimals by @zorbash in https://github.com/open-api-spex/open_api_spex/pull/634
* Support decoding operations with :servers. by @loguntsov in https://github.com/open-api-spex/open_api_spex/pull/635

## v3.20.1 - 2024-07-31

* Support custom error messages in custom validators by @GregorGrasselli in https://github.com/open-api-spex/open_api_spex/pull/621
* Update Schema.example/2 typespec to allow references by @zorbash in 5ec452f

## v3.20.0 - 2024-07-10

* Respect minLength when generating string examples by @zorbash in https://github.com/open-api-spex/open_api_spex/pull/608
* 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
* Allow Poison v6 to be used by @hkrutzer in https://github.com/open-api-spex/open_api_spex/pull/616
* 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
* improvement: use struct spec to avoid double `%` in struct inspect by @zachdaniel in https://github.com/open-api-spex/open_api_spex/pull/613
* 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
* fix: cast numbers as floats by @David-Klemenc in https://github.com/open-api-spex/open_api_spex/pull/611

## v3.19.1 - 2024-05-17

* Add notice that body params are not merged into Conn.params whne using cast and validate plug by @hamir-suspect in #589
* Set nonces on `<script>` and `<style>` elements if configured by @nathanalderson in #593
* Ensure operation_id is always set on conn.private by @msutkowski in #606

## v3.19.0 - 2024-04-30

* Support response code ranges by @zorbash in 8898859da1

## v3.18.3 - 2024-03-15

* Relax dependency constraint on ymlr to allow version ~> 5.0 by @egze in https://github.com/open-api-spex/open_api_spex/pull/586

## v3.18.2 - 2024-01-26

* 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

## v3.18.1 - 2023-12-19

* Fix `assert_operation_response/2` header lookup by @msutkowski in https://github.com/open-api-spex/open_api_spex/pull/584
* Exclude empty paths (`operation false`) from generated spec by @alisinabh in https://github.com/open-api-spex/open_api_spex/pull/583
* Cast discriminator when no title present (#574) by @albertored in https://github.com/open-api-spex/open_api_spex/pull/574
* Docstest Operation.parameter/5 by @zorbash
* Document the spec export task `--filename` option by @zorbash

## v3.18.0 - 2023-08-23

* Relax dependency constraint on ymlr to allow version ~> 4.0 by @arcanemachine in https://github.com/open-api-spex/open_api_spex/pull/544
* 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
* Add `--quiet` option for spec generation by @Cowa in https://github.com/open-api-spex/open_api_spex/pull/557
* Fix casting non-objects against discriminator #551 by @gianluca-nitti in https://github.com/open-api-spex/open_api_spex/pull/552
* feat: add assert_operation_response, assert_raw_schema by @msutkowski in https://github.com/open-api-spex/open_api_spex/pull/545

## v3.17.3 - 2023-05-30

* 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
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ The package can be installed by adding `:open_api_spex` to your list of dependen
```elixir
def deps do
[
{:open_api_spex, "~> 3.16"}
{:open_api_spex, "~> 3.21"}
]
end
```
Expand Down Expand Up @@ -282,7 +282,7 @@ mix openapi.spec.yaml --spec MyAppWeb.ApiSpec
Invoking this task starts the application by default. This can be
disabled with the `--start-app=false` option.

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:
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:

```elixir
%OpenApi{
Expand Down
2 changes: 1 addition & 1 deletion examples/phoenix_app/config/dev.exs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ config :logger, :console, format: "[$level] $message\n"
config :phoenix, :stacktrace_depth, 20

config :phoenix_app, PhoenixApp.Repo,
adapter: Sqlite.Ecto2,
adapter: Ecto.Adapters.SQLite3,
database: "priv/repo/phoenix_app_dev.db"
4 changes: 2 additions & 2 deletions examples/phoenix_app/config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ config :phoenix_app, PhoenixAppWeb.Endpoint,
http: [port: 4001],
server: false

config :logger, level: :warn
config :logger, level: :warning

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

config :phoenix_app, PhoenixApp.Repo,
adapter: Sqlite.Ecto2,
adapter: Ecto.Adapters.SQLite3,
database: "priv/repo/phoenix_app_test.db"
15 changes: 13 additions & 2 deletions examples/phoenix_app/lib/phoenix_app/accounts/accounts.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,19 @@ defmodule PhoenixApp.Accounts do
alias PhoenixApp.Accounts.User
alias PhoenixApp.Repo

def list_users() do
Repo.all(User)
import Ecto.Query

def list_users(filters) do
query = from(u in User, order_by: [asc: u.id])

query =
if filters[:ids] do
from(u in query, where: u.id in ^filters[:ids])
else
query
end

Repo.all(query)
end

def get_user!(id) do
Expand Down
2 changes: 1 addition & 1 deletion examples/phoenix_app/lib/phoenix_app/repo.ex
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
defmodule PhoenixApp.Repo do
use Ecto.Repo, otp_app: :phoenix_app, adapter: Sqlite.Ecto2
use Ecto.Repo, otp_app: :phoenix_app, adapter: Ecto.Adapters.SQLite3
end
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,22 @@ defmodule PhoenixAppWeb.UserController do
operation :index,
summary: "List users",
description: "List all users",
parameters: [
OpenApiSpex.Operation.parameter(
:ids,
:query,
%Schema{type: :array, items: %Schema{type: :integer}},
"Filter by user ids"
)
],
responses: [
ok: {"User List Response", "application/json", Schemas.UsersResponse},
unprocessable_entity: %Reference{"$ref": "#/components/responses/unprocessable_entity"}
]

def index(conn, _params) do
users = Accounts.list_users()
def index(conn, params) do
users = Accounts.list_users(params)

render(conn, "index.json", users: users)
end

Expand All @@ -37,8 +46,7 @@ defmodule PhoenixAppWeb.UserController do
parameters: [
group_id: [in: :path, type: :integer, description: "Group ID", example: 1]
],
request_body:
{"The user attributes", "application/json", Schemas.UserRequest, required: true},
request_body: {"The user attributes", "application/json", Schemas.UserRequest, required: true},
responses: [
created: {"User", "application/json", Schemas.UserResponse}
]
Expand Down Expand Up @@ -88,8 +96,7 @@ defmodule PhoenixAppWeb.UserController do
required: true
]
],
request_body:
{"The user attributes", "application/json", Schemas.UserRequest, required: true},
request_body: {"The user attributes", "application/json", Schemas.UserRequest, required: true},
responses: [
ok: {"User", "application/json", Schemas.UserResponse}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ defmodule PhoenixAppWeb.UserControllerWithStructSpecs do
of using the ExDoc-based operation specs.
"""
use PhoenixAppWeb, :controller

import OpenApiSpex.Operation, only: [parameter: 5, request_body: 4, response: 3]
alias OpenApiSpex.{Operation, Reference}

alias OpenApiSpex.{Operation, Reference, Schema}
alias PhoenixApp.{Accounts, Accounts.User}
alias PhoenixAppWeb.Schemas

Expand Down Expand Up @@ -34,15 +36,24 @@ defmodule PhoenixAppWeb.UserControllerWithStructSpecs do
summary: "List users",
description: "List all useres",
operationId: "UserController.index",
parameters: [
OpenApiSpex.Operation.parameter(
:ids,
:query,
%Schema{type: :array, items: %Schema{type: :integer}},
"Filter by user ids"
)
],
responses: %{
200 => response("User List Response", "application/json", Schemas.UsersResponse),
422 => %Reference{"$ref": "#/components/responses/unprocessable_entity"}
}
}
end

def index(conn, _params) do
users = Accounts.list_users()
def index(conn, params) do
users = Accounts.list_users(params)

render(conn, "index.json", users: users)
end

Expand All @@ -56,9 +67,7 @@ defmodule PhoenixAppWeb.UserControllerWithStructSpecs do
Operation.parameter(:group_id, :path, :integer, "Group ID", example: 1)
],
requestBody:
request_body("The user attributes", "application/json", Schemas.UserRequest,
required: true
),
request_body("The user attributes", "application/json", Schemas.UserRequest, required: true),
responses: %{
201 => response("User", "application/json", Schemas.UserResponse)
}
Expand Down
9 changes: 7 additions & 2 deletions examples/phoenix_app/lib/phoenix_app_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ defmodule PhoenixAppWeb.Router do
oauth: [
# client_id: "e2195a7487322a0f19bf"
client_id: "Iv1.d7c611e5607d77b0"
]
],
csp_nonce_assign_key: %{script: :script_src_nonce, style: :style_src_nonce}
]

@oauth_redirect_config [
csp_nonce_assign_key: %{script: :script_src_nonce}
]

def swagger_ui_config, do: @swagger_ui_config
Expand All @@ -28,7 +33,7 @@ defmodule PhoenixAppWeb.Router do

get "/swaggerui", OpenApiSpex.Plug.SwaggerUI, @swagger_ui_config

get "/swaggerui/oauth2-redirect.html", OpenApiSpex.Plug.SwaggerUIOAuth2Redirect, :show
get "/swaggerui/oauth2-redirect.html", OpenApiSpex.Plug.SwaggerUIOAuth2Redirect, @oauth_redirect_config
end

scope "/api" do
Expand Down
Loading