Skip to content
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

Create GitHub Actions workflow #85

Merged
merged 3 commits into from
Oct 18, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
55 changes: 55 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: CI

on:
- push
- pull_request

permissions:
contents: read

jobs:
build:
name: OTP ${{ matrix.otp }} / Elixir ${{ matrix.elixir }}
runs-on: ubuntu-20.04
strategy:
matrix:
include:
- elixir: 1.12.0
otp: 22.3
- elixir: 1.15.2
otp: 25.3
env:
MIX_ENV: test
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Set up Elixir
uses: erlef/setup-beam@v1
with:
otp-version: ${{ matrix.otp }}
elixir-version: ${{ matrix.elixir }}
- name: Restore dependencies cache
uses: actions/cache@v3
with:
path: deps
key: deps-${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-${{ hashFiles('**/mix.lock') }}
restore-keys: deps-${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-
- name: Restore build cache
uses: actions/cache@v3
with:
path: _build/test
key: build-${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-${{ hashFiles('**/mix.lock') }}
restore-keys: build-${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-
- name: Install dependencies
run: mix deps.get
- name: Compile dependencies
run: mix deps.compile
- name: Compile
run: mix compile --warnings-as-errors
- name: Dialyzer
run: mix dialyzer --halt-exit-status
- name: Run tests
run: mix coveralls.github
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
44 changes: 0 additions & 44 deletions .travis.yml

This file was deleted.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Elixir JSON Schema Validator

[![Build Status](https://app.travis-ci.com/jonasschmidt/ex_json_schema.svg?branch=master)](https://app.travis-ci.com/github/jonasschmidt/ex_json_schema)
[![Build Status](https://github.com/jonasschmidt/ex_json_schema/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/jonasschmidt/ex_json_schema/actions/workflows/ci.yml)
[![Coverage Status](https://coveralls.io/repos/github/jonasschmidt/ex_json_schema/badge.svg?branch=master)](https://coveralls.io/github/jonasschmidt/ex_json_schema?branch=master)
[![Module Version](https://img.shields.io/hexpm/v/ex_json_schema.svg)](https://hex.pm/packages/ex_json_schema)
[![Hex Docs](https://img.shields.io/badge/hex-docs-lightgreen.svg)](https://hexdocs.pm/ex_json_schema/)
Expand Down Expand Up @@ -35,7 +35,7 @@ If you have remote schemata that need to be fetched at runtime, you have to regi
```elixir
config :ex_json_schema,
:remote_schema_resolver,
fn url -> HTTPoison.get!(url).body |> Poison.decode! end
fn url -> HTTPoison.get!(url).body |> Jason.decode! end
```

Alternatively, you can specify a module and function name for situations where using anonymous functions is not possible (i.e. working with Erlang releases):
Expand Down
9 changes: 7 additions & 2 deletions config/test.exs
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
use Mix.Config

Check warning on line 1 in config/test.exs

View workflow job for this annotation

GitHub Actions / OTP 25.3 / Elixir 1.15.2

use Mix.Config is deprecated. Use the Config module instead

Check warning on line 1 in config/test.exs

View workflow job for this annotation

GitHub Actions / OTP 25.3 / Elixir 1.15.2

use Mix.Config is deprecated. Use the Config module instead

Check warning on line 1 in config/test.exs

View workflow job for this annotation

GitHub Actions / OTP 25.3 / Elixir 1.15.2

use Mix.Config is deprecated. Use the Config module instead

Check warning on line 1 in config/test.exs

View workflow job for this annotation

GitHub Actions / OTP 25.3 / Elixir 1.15.2

use Mix.Config is deprecated. Use the Config module instead

Check warning on line 1 in config/test.exs

View workflow job for this annotation

GitHub Actions / OTP 25.3 / Elixir 1.15.2

use Mix.Config is deprecated. Use the Config module instead

Check warning on line 1 in config/test.exs

View workflow job for this annotation

GitHub Actions / OTP 25.3 / Elixir 1.15.2

use Mix.Config is deprecated. Use the Config module instead

Check warning on line 1 in config/test.exs

View workflow job for this annotation

GitHub Actions / OTP 25.3 / Elixir 1.15.2

use Mix.Config is deprecated. Use the Config module instead

Check warning on line 1 in config/test.exs

View workflow job for this annotation

GitHub Actions / OTP 25.3 / Elixir 1.15.2

use Mix.Config is deprecated. Use the Config module instead

Check warning on line 1 in config/test.exs

View workflow job for this annotation

GitHub Actions / OTP 25.3 / Elixir 1.15.2

use Mix.Config is deprecated. Use the Config module instead

Check warning on line 1 in config/test.exs

View workflow job for this annotation

GitHub Actions / OTP 25.3 / Elixir 1.15.2

use Mix.Config is deprecated. Use the Config module instead

Check warning on line 1 in config/test.exs

View workflow job for this annotation

GitHub Actions / OTP 25.3 / Elixir 1.15.2

use Mix.Config is deprecated. Use the Config module instead

Check warning on line 1 in config/test.exs

View workflow job for this annotation

GitHub Actions / OTP 25.3 / Elixir 1.15.2

use Mix.Config is deprecated. Use the Config module instead

Check warning on line 1 in config/test.exs

View workflow job for this annotation

GitHub Actions / OTP 25.3 / Elixir 1.15.2

use Mix.Config is deprecated. Use the Config module instead

Check warning on line 1 in config/test.exs

View workflow job for this annotation

GitHub Actions / OTP 25.3 / Elixir 1.15.2

use Mix.Config is deprecated. Use the Config module instead

defmodule CustomFormatValidator do
def validate(_format, _data), do: true
end

config :ex_json_schema,

Check warning on line 7 in config/test.exs

View workflow job for this annotation

GitHub Actions / OTP 25.3 / Elixir 1.15.2

Mix.Config.config/2 is deprecated. Use the Config module instead

Check warning on line 7 in config/test.exs

View workflow job for this annotation

GitHub Actions / OTP 25.3 / Elixir 1.15.2

Mix.Config.config/2 is deprecated. Use the Config module instead

Check warning on line 7 in config/test.exs

View workflow job for this annotation

GitHub Actions / OTP 25.3 / Elixir 1.15.2

Mix.Config.config/2 is deprecated. Use the Config module instead

Check warning on line 7 in config/test.exs

View workflow job for this annotation

GitHub Actions / OTP 25.3 / Elixir 1.15.2

Mix.Config.config/2 is deprecated. Use the Config module instead

Check warning on line 7 in config/test.exs

View workflow job for this annotation

GitHub Actions / OTP 25.3 / Elixir 1.15.2

Mix.Config.config/2 is deprecated. Use the Config module instead

Check warning on line 7 in config/test.exs

View workflow job for this annotation

GitHub Actions / OTP 25.3 / Elixir 1.15.2

Mix.Config.config/2 is deprecated. Use the Config module instead

Check warning on line 7 in config/test.exs

View workflow job for this annotation

GitHub Actions / OTP 25.3 / Elixir 1.15.2

Mix.Config.config/2 is deprecated. Use the Config module instead

Check warning on line 7 in config/test.exs

View workflow job for this annotation

GitHub Actions / OTP 25.3 / Elixir 1.15.2

Mix.Config.config/2 is deprecated. Use the Config module instead

Check warning on line 7 in config/test.exs

View workflow job for this annotation

GitHub Actions / OTP 25.3 / Elixir 1.15.2

Mix.Config.config/2 is deprecated. Use the Config module instead

Check warning on line 7 in config/test.exs

View workflow job for this annotation

GitHub Actions / OTP 25.3 / Elixir 1.15.2

Mix.Config.config/2 is deprecated. Use the Config module instead

Check warning on line 7 in config/test.exs

View workflow job for this annotation

GitHub Actions / OTP 25.3 / Elixir 1.15.2

Mix.Config.config/2 is deprecated. Use the Config module instead

Check warning on line 7 in config/test.exs

View workflow job for this annotation

GitHub Actions / OTP 25.3 / Elixir 1.15.2

Mix.Config.config/2 is deprecated. Use the Config module instead

Check warning on line 7 in config/test.exs

View workflow job for this annotation

GitHub Actions / OTP 25.3 / Elixir 1.15.2

Mix.Config.config/2 is deprecated. Use the Config module instead

Check warning on line 7 in config/test.exs

View workflow job for this annotation

GitHub Actions / OTP 25.3 / Elixir 1.15.2

Mix.Config.config/2 is deprecated. Use the Config module instead
decode_json: fn json -> Poison.decode(json) end,
remote_schema_resolver: fn url -> HTTPoison.get!(url).body |> Poison.decode!() end,
decode_json: fn json -> Jason.decode(json) end,
remote_schema_resolver: fn url -> HTTPoison.get!(url).body |> Jason.decode!() end,
custom_format_validator: {CustomFormatValidator, :validate}

config :ex_json_schema, SamplePhoenix.Endpoint,

Check warning on line 12 in config/test.exs

View workflow job for this annotation

GitHub Actions / OTP 25.3 / Elixir 1.15.2

Mix.Config.config/3 is deprecated. Use the Config module instead

Check warning on line 12 in config/test.exs

View workflow job for this annotation

GitHub Actions / OTP 25.3 / Elixir 1.15.2

Mix.Config.config/3 is deprecated. Use the Config module instead

Check warning on line 12 in config/test.exs

View workflow job for this annotation

GitHub Actions / OTP 25.3 / Elixir 1.15.2

Mix.Config.config/3 is deprecated. Use the Config module instead

Check warning on line 12 in config/test.exs

View workflow job for this annotation

GitHub Actions / OTP 25.3 / Elixir 1.15.2

Mix.Config.config/3 is deprecated. Use the Config module instead

Check warning on line 12 in config/test.exs

View workflow job for this annotation

GitHub Actions / OTP 25.3 / Elixir 1.15.2

Mix.Config.config/3 is deprecated. Use the Config module instead

Check warning on line 12 in config/test.exs

View workflow job for this annotation

GitHub Actions / OTP 25.3 / Elixir 1.15.2

Mix.Config.config/3 is deprecated. Use the Config module instead

Check warning on line 12 in config/test.exs

View workflow job for this annotation

GitHub Actions / OTP 25.3 / Elixir 1.15.2

Mix.Config.config/3 is deprecated. Use the Config module instead

Check warning on line 12 in config/test.exs

View workflow job for this annotation

GitHub Actions / OTP 25.3 / Elixir 1.15.2

Mix.Config.config/3 is deprecated. Use the Config module instead

Check warning on line 12 in config/test.exs

View workflow job for this annotation

GitHub Actions / OTP 25.3 / Elixir 1.15.2

Mix.Config.config/3 is deprecated. Use the Config module instead

Check warning on line 12 in config/test.exs

View workflow job for this annotation

GitHub Actions / OTP 25.3 / Elixir 1.15.2

Mix.Config.config/3 is deprecated. Use the Config module instead

Check warning on line 12 in config/test.exs

View workflow job for this annotation

GitHub Actions / OTP 25.3 / Elixir 1.15.2

Mix.Config.config/3 is deprecated. Use the Config module instead

Check warning on line 12 in config/test.exs

View workflow job for this annotation

GitHub Actions / OTP 25.3 / Elixir 1.15.2

Mix.Config.config/3 is deprecated. Use the Config module instead

Check warning on line 12 in config/test.exs

View workflow job for this annotation

GitHub Actions / OTP 25.3 / Elixir 1.15.2

Mix.Config.config/3 is deprecated. Use the Config module instead

Check warning on line 12 in config/test.exs

View workflow job for this annotation

GitHub Actions / OTP 25.3 / Elixir 1.15.2

Mix.Config.config/3 is deprecated. Use the Config module instead
http: [ip: {127, 0, 0, 1}, port: 1234],
server: true,
secret_key_base: String.duplicate("a", 64)
6 changes: 4 additions & 2 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ defmodule ExJsonSchema.Mixfile do
preferred_cli_env: [coveralls: :test, dialyzer: :test],
dialyzer: [
plt_add_apps: [:ex_unit],
plt_core_path: ".",
plt_core_path: "_build/#{Mix.env()}",
plt_add_deps: :transitive
]
]
Expand All @@ -39,7 +39,9 @@ defmodule ExJsonSchema.Mixfile do
{:excoveralls, "~> 0.14", only: :test},
{:httpoison, "~> 1.8", only: :test},
{:mix_test_watch, "~> 0.7", only: [:dev, :test]},
{:poison, "~> 5.0", only: :test}
{:jason, "~> 1.4", only: :test},
{:plug_cowboy, "~> 2.5", only: :test},
{:phoenix, "~> 1.6", only: :test}
]
end

Expand Down
12 changes: 6 additions & 6 deletions test/ex_json_schema/schema_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ defmodule ExJsonSchema.SchemaTest do
schema = %{"properties" => "foo"}

assert_raise ExJsonSchema.Schema.InvalidSchemaError,
~s(schema did not pass validation against its meta-schema: [%ExJsonSchema.Validator.Error{error: %ExJsonSchema.Validator.Error.Type{expected: ["object"], actual: "string"}, path: "#/properties"}]),
~r/schema did not pass validation against its meta-schema: \[%ExJsonSchema.Validator.Error{error: %ExJsonSchema.Validator.Error.Type{/,
fn -> resolve(schema) end

assert_raise ExJsonSchema.Schema.InvalidSchemaError,
Expand Down Expand Up @@ -132,19 +132,19 @@ defmodule ExJsonSchema.SchemaTest do
test "fetching a ref schema with a path" do
schema =
resolve(%{
"properties" => %{"foo" => %{"$ref" => "http://localhost:8000/subschema.json#/foo"}}
"properties" => %{"foo" => %{"$ref" => "http://localhost:1234/subschema.json#/foo"}}
})

assert get_fragment!(schema, "#/properties/foo") == %{
"$ref" => ["http://localhost:8000/subschema.json", "foo"]
"$ref" => ["http://localhost:1234/subschema.json", "foo"]
}
end

test "fetching a ref schema with a URL" do
schema = resolve(%{"$ref" => "http://localhost:8000/subschema.json#/foo"})
schema = resolve(%{"$ref" => "http://localhost:1234/subschema.json#/foo"})

assert get_fragment!(schema, "http://localhost:8000/subschema.json#/foo") == %{
"$ref" => ["http://localhost:8000/subsubschema.json", "foo"]
assert get_fragment!(schema, "http://localhost:1234/subschema.json#/foo") == %{
"$ref" => ["http://localhost:1234/subsubschema.json", "foo"]
}
end
end
4 changes: 2 additions & 2 deletions test/ex_json_schema/validator_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defmodule ExJsonSchema.ValidatorTest do

@schema_with_ref Schema.resolve(%{
"properties" => %{
"foo" => %{"$ref" => "http://localhost:8000/subschema.json#/foo"}
"foo" => %{"$ref" => "http://localhost:1234/subschema.json#/foo"}
}
})

Expand Down Expand Up @@ -66,7 +66,7 @@ defmodule ExJsonSchema.ValidatorTest do

test "validation errors with a remote reference within a remote reference" do
assert_validation_errors(
%{"$ref" => "http://localhost:8000/subschema.json#/foo"},
%{"$ref" => "http://localhost:1234/subschema.json#/foo"},
"foo",
[{"Type mismatch. Expected Integer but got String.", "#"}],
[%Error{error: %Error.Type{expected: ["integer"], actual: "string"}, path: "#"}]
Expand Down
34 changes: 34 additions & 0 deletions test/support/remote_schema_server.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
defmodule SamplePhoenix.SampleController do
use Phoenix.Controller

def show(conn, %{"path" => path}) do
test_path = Path.join(__DIR__, "..") |> Path.expand()

json =
case File.read(Path.join([test_path, "support/schemata"] ++ path)) do
{:ok, json} -> json
_ -> File.read!(Path.join([test_path, "JSON-Schema-Test-Suite/remotes"] ++ path))
end

conn |> put_resp_content_type("application/json") |> send_resp(200, json)
end
end

defmodule Router do
use Phoenix.Router

pipeline :api do
plug(:accepts, ["json"])
end

scope "/", SamplePhoenix, log: false do
pipe_through(:api)

get("/*path", SampleController, :show)
end
end

defmodule SamplePhoenix.Endpoint do
use Phoenix.Endpoint, otp_app: :ex_json_schema
plug(Router)
end
2 changes: 1 addition & 1 deletion test/support/schemata/subschema.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"foo": {
"$ref": "http://localhost:8000/subsubschema.json#/foo"
"$ref": "http://localhost:1234/subsubschema.json#/foo"
}
}
2 changes: 1 addition & 1 deletion test/support/test_helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ defmodule ExJsonSchema.Test.Support.TestHelpers do
schema_tests_path
|> Path.join(name <> ".json")
|> File.read!()
|> Poison.decode!()
|> Jason.decode!()
end
end
16 changes: 1 addition & 15 deletions test/test_helper.exs
Original file line number Diff line number Diff line change
@@ -1,18 +1,4 @@
ExUnit.start()
HTTPoison.start()

{:ok, _} =
:inets.start(:httpd,
server_name: 'test 1',
document_root: './test/JSON-Schema-Test-Suite/remotes',
server_root: '.',
port: 1234
)

{:ok, _} =
:inets.start(:httpd,
server_name: 'test 2',
document_root: './test/support/schemata',
server_root: '.',
port: 8000
)
{:ok, _} = Supervisor.start_link([SamplePhoenix.Endpoint], strategy: :one_for_one)