Skip to content

Commit cdb4461

Browse files
lucacortiLuca Corti
and
Luca Corti
authored
Improve CI pipeline (open-api-spex#377)
* Improve test matrix * Run Dialyzer in CI * Run in CI * Only enforce formatting on latest elixir version Co-authored-by: Luca Corti <[email protected]> Co-authored-by: Luca Corti <[email protected]>
1 parent fa684e9 commit cdb4461

Some content is hidden

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

55 files changed

+305
-253
lines changed

.credo.exs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
%{
2+
configs: [
3+
%{
4+
name: "default",
5+
files: %{
6+
included: ["lib/"],
7+
excluded: []
8+
},
9+
plugins: [],
10+
requires: [],
11+
strict: true,
12+
parse_timeout: 5000,
13+
color: true,
14+
checks: [
15+
{Credo.Check.Consistency.ParameterPatternMatching, false}
16+
]
17+
}
18+
]
19+
}

.github/workflows/elixir.yml

+48-24
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,59 @@ on:
77
branches: [master]
88

99
jobs:
10-
build:
11-
name: Build and test
12-
runs-on: ubuntu-18.04
10+
lint:
11+
name: Lint (OTP ${{matrix.otp}} / Elixir ${{matrix.elixir}})
12+
runs-on: ubuntu-latest
1313
strategy:
1414
matrix:
15-
elixir: [1.9, 1.12]
16-
otp: [23.0]
17-
15+
otp: ['25']
16+
elixir: ['1.13']
1817
steps:
1918
- uses: actions/checkout@v2
20-
- name: Set up Elixir
21-
uses: actions/setup-elixir@v1
19+
- uses: erlef/setup-beam@v1
20+
id: beam
2221
with:
23-
elixir-version: ${{ matrix.elixir }} # Define the elixir version [required]
24-
otp-version: ${{ matrix.otp }} # Define the OTP version [required]
25-
- name: Restore dependencies cache
22+
otp-version: ${{matrix.otp}}
23+
elixir-version: ${{matrix.elixir}}
24+
- name: PLT cache
2625
uses: actions/cache@v2
2726
with:
27+
key: |
28+
${{ runner.os }}-${{ steps.beam.outputs.elixir-version }}-${{ steps.beam.outputs.otp-version }}-plt
29+
restore-keys: |
30+
${{ runner.os }}-${{ steps.beam.outputs.elixir-version }}-${{ steps.beam.outputs.otp-version }}-plt
31+
path: |
32+
priv/plts
33+
- run: mix deps.get
34+
- run: mix compile --warnings-as-errors
35+
- run: mix format --check-formatted
36+
- run: mix credo --strict --all
37+
- run: mix dialyzer
38+
test:
39+
runs-on: ubuntu-latest
40+
name: Test (OTP ${{matrix.otp}} / Elixir ${{matrix.elixir}})
41+
strategy:
42+
matrix:
43+
otp: ['22', '23', '24', '25']
44+
elixir: ['1.10', '1.11', '1.12', '1.13']
45+
exclude:
46+
- {otp: '24', elixir: '1.10'}
47+
- {otp: '25', elixir: '1.10'}
48+
- {otp: '25', elixir: '1.11'}
49+
- {otp: '25', elixir: '1.12'}
50+
steps:
51+
- uses: actions/checkout@v2
52+
- uses: erlef/setup-beam@v1
53+
with:
54+
otp-version: ${{matrix.otp}}
55+
elixir-version: ${{matrix.elixir}}
56+
- uses: actions/cache@v2
57+
with:
58+
key: |
59+
${{ runner.os }}-${{ steps.beam.outputs.elixir-version }}-${{ steps.beam.outputs.otp-version }}-build
60+
restore-keys: |
61+
${{ runner.os }}-${{ steps.beam.outputs.elixir-version }}-${{ steps.beam.outputs.otp-version }}-build
2862
path: |
29-
deps
30-
_build/test
31-
key: ${{ runner.os }}-deps-${{ hashFiles('**/mix.lock', '**/config/*.exs') }}
32-
restore-keys: ${{ runner.os }}-deps-
33-
- name: Install and compile dependencies
34-
run: MIX_ENV=test mix do deps.get, deps.compile
35-
- name: Compile application
36-
run: MIX_ENV=test mix compile --warnings-as-errors
37-
- name: Check formatting
38-
if: ${{ matrix.elixir == '1.12' }}
39-
run: mix format --check-formatted
40-
- name: Run tests
41-
run: mix test
63+
_build
64+
- run: mix deps.get
65+
- run: mix test

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,5 @@ open_api_spex-*.tar
3030
.vscode/
3131
.idea
3232
*.iml
33+
34+
/priv/plts

.travis.yml

-32
This file was deleted.

config/config.exs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This file is responsible for configuring your application
22
# and its dependencies with the aid of the Mix.Config module.
3-
use Mix.Config
3+
import Config
44

55
# This configuration is loaded before any dependency and is restricted
66
# to this project. If another project depends on this project, this

config/test.exs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
use Mix.Config
1+
import Config
22

33
config :logger, level: :info

examples/phoenix_app/mix.exs

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ defmodule PhoenixApp.Mixfile do
4242
[
4343
{:open_api_spex, path: "../../"},
4444
{:ecto, "~> 2.2"},
45+
{:httpoison, "~> 1.7"},
4546
{:sqlite_ecto2, "~> 2.4"},
4647
{:phoenix, "~> 1.4"},
4748
{:plug_cowboy, "~> 2.0"},
4849
{:jason, "~> 1.0"},
49-
{:httpoison, "~> 1.7"},
5050
{:dialyxir, "1.0.0-rc.6", only: [:dev], runtime: false}
5151
]
5252
end

lib/open_api_spex.ex

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ defmodule OpenApiSpex do
1010
Operation2,
1111
Reference,
1212
Schema,
13+
SchemaConsistency,
1314
SchemaException,
14-
SchemaResolver,
15-
SchemaConsistency
15+
SchemaResolver
1616
}
1717

1818
alias OpenApiSpex.Cast.Error

lib/open_api_spex/cast.ex

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
defmodule OpenApiSpex.Cast do
2+
@moduledoc "Cast and validate a value against an OpenApiSpex schema"
3+
24
alias OpenApiSpex.{Reference, Schema}
35
alias OpenApiSpex.Reference
46

lib/open_api_spex/cast/all_of.ex

+9-9
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@ defmodule OpenApiSpex.Cast.AllOf do
1717
{:ok, Enum.concat(acc, value)}
1818

1919
{:error, errors} ->
20-
with {:ok, cleaned_ctx} <- reject_error_values(ctx, errors) do
21-
case Cast.cast(cleaned_ctx) do
22-
{:ok, cleaned_values} ->
23-
new_ctx = put_in(ctx.schema.allOf, remaining)
24-
new_ctx = update_in(new_ctx.value, fn values -> values -- cleaned_ctx.value end)
25-
cast_all_of(new_ctx, Enum.concat(acc, cleaned_values))
26-
end
20+
with {:ok, cleaned_ctx} <- reject_error_values(ctx, errors),
21+
{:ok, cleaned_values} <- Cast.cast(cleaned_ctx) do
22+
new_ctx = put_in(ctx.schema.allOf, remaining)
23+
new_ctx = update_in(new_ctx.value, fn values -> values -- cleaned_ctx.value end)
24+
cast_all_of(new_ctx, Enum.concat(acc, cleaned_values))
2725
else
2826
_ -> Cast.error(ctx, {:all_of, to_string(schema.title || schema.type)})
2927
end
@@ -48,8 +46,10 @@ defmodule OpenApiSpex.Cast.AllOf do
4846
cast_all_of(new_ctx, acc)
4947

5048
{:ok, value} ->
51-
# allOf definitions with primitives are a little bit strange..., we just return the cast for the first Schema,
52-
# but validate the values against every other schema as well, since the value must be compatible with all Schemas
49+
# allOf definitions with primitives are a little bit strange.
50+
# we just return the cast for the first Schema, but validate
51+
# the values against every other schema as well, since the value
52+
# must be compatible with all Schemas
5353
cast_all_of(new_ctx, acc || value)
5454

5555
{:error, _} ->

lib/open_api_spex/cast/discriminator.ex

+9-5
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,15 @@ defmodule OpenApiSpex.Cast.Discriminator do
8181
do: {locate_schemas(schemas, ctx.schemas), Cast.cast(ctx)}
8282

8383
defp find_discriminator_schema(discriminator, mappings = %{}, schemas) do
84-
with {:ok, "#/components/schemas/" <> name} <- Map.fetch(mappings, discriminator) do
85-
find_discriminator_schema(name, nil, schemas)
86-
else
87-
{:ok, name} -> find_discriminator_schema(name, nil, schemas)
88-
:error -> find_discriminator_schema(discriminator, nil, schemas)
84+
case Map.fetch(mappings, discriminator) do
85+
{:ok, "#/components/schemas/" <> name} ->
86+
find_discriminator_schema(name, nil, schemas)
87+
88+
{:ok, name} ->
89+
find_discriminator_schema(name, nil, schemas)
90+
91+
:error ->
92+
find_discriminator_schema(discriminator, nil, schemas)
8993
end
9094
end
9195

lib/open_api_spex/cast/error.ex

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
defmodule OpenApiSpex.Cast.Error do
2+
@moduledoc "OpenApiSpex Cast Error"
3+
24
alias OpenApiSpex.TermType
35

46
@type all_of_error :: {:all_of, [String.t()]}

lib/open_api_spex/cast/number.ex

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ defmodule OpenApiSpex.Cast.Number do
22
@moduledoc false
33
alias OpenApiSpex.Cast
44

5+
# credo:disable-for-next-line
6+
# TODO We need a way to distinguish numbers in (JSON) body vs in request parameters
7+
# so we can reject strings values for properties of `type: :number`
58
@spec cast(ctx :: Cast.t()) :: {:ok, Cast.t()} | Cast.Error.t()
69
def cast(%{value: value} = ctx) when is_number(value) do
710
case cast_number(ctx) do
@@ -10,8 +13,6 @@ defmodule OpenApiSpex.Cast.Number do
1013
end
1114
end
1215

13-
# TODO We need a way to distinguish numbers in (JSON) body vs in request parameters
14-
# so we can reject strings values for properties of `type: :number`
1516
def cast(%{value: value} = ctx) when is_binary(value) do
1617
case Float.parse(value) do
1718
{value, ""} -> cast(%{ctx | value: value})

lib/open_api_spex/cast/string.ex

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ defmodule OpenApiSpex.Cast.String do
5454
?e,
5555
?f
5656
]
57+
# credo:disable-for-next-line
5758
def cast(%{
5859
value:
5960
<<a1, a2, a3, a4, a5, a6, a7, a8, ?-, b1, b2, b3, b4, ?-, c1, c2, c3, c4, ?-, d1, d2, d3,

lib/open_api_spex/cast_parameters.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
defmodule OpenApiSpex.CastParameters do
22
@moduledoc false
3-
alias OpenApiSpex.{Cast, Operation, Parameter, Schema, Reference, Components}
3+
alias OpenApiSpex.{Cast, Components, Operation, Parameter, Reference, Schema}
44
alias OpenApiSpex.Cast.Error
55
alias Plug.Conn
66

lib/open_api_spex/components.ex

+8-8
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ defmodule OpenApiSpex.Components do
33
Defines the `OpenApiSpex.Components.t` type.
44
"""
55
alias OpenApiSpex.{
6-
Schema,
7-
Reference,
8-
Response,
9-
Parameter,
6+
Callback,
7+
Components,
108
Example,
11-
RequestBody,
129
Header,
13-
SecurityScheme,
1410
Link,
15-
Callback,
16-
Components
11+
Parameter,
12+
Reference,
13+
RequestBody,
14+
Response,
15+
Schema,
16+
SecurityScheme
1717
}
1818

1919
defstruct [

0 commit comments

Comments
 (0)