Skip to content

Commit

Permalink
Merge pull request #79 from E-xyza/1.1.2-bugfix-degeneracy-detection
Browse files Browse the repository at this point in the history
1.1.2 bugfix degeneracy detection
  • Loading branch information
ityonemo authored Oct 13, 2023
2 parents c1590d0 + 43d4ad8 commit f66f95e
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/exonerate/context.ex
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ defmodule Exonerate.Context do

{filters, accessories} =
types
|> List.wrap()
|> MapSet.new()
|> MapSet.intersection(filtered_types)
|> Enum.map(fn type ->
Expand Down
3 changes: 2 additions & 1 deletion lib/exonerate/degeneracy.ex
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,8 @@ defmodule Exonerate.Degeneracy do
def class(false), do: :error

def class(context = %{"type" => t}) do
if Enum.sort(t) == @all_types do
types = List.wrap(t)
if Enum.sort(types) == @all_types do
context
|> Map.delete("type")
|> class()
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Exonerate.MixProject do
def project do
[
app: :exonerate,
version: "1.1.2",
version: "1.1.3",
elixir: "~> 1.14",
start_permanent: Mix.env() == :prod,
deps: deps(),
Expand Down
2 changes: 1 addition & 1 deletion test/regression/general_test.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule ExonerateTest.RegressionTest do
defmodule ExonerateTest.Regression.GeneralTest do
use ExUnit.Case, async: true
require Exonerate

Expand Down
31 changes: 31 additions & 0 deletions test/regression/string_type_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
defmodule ExonerateTest.Regression.NestedStringTypeTest do
use ExUnit.Case, async: true
require Exonerate

# contributed by @ahacking (issue #78). This is due to
# degeneracy testing across jumps in the schema not respecting
# type being a single string instead of an array.

Exonerate.function_from_string(:def, :validate_api, ~S"""
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "JSON validation failure",
"type": "object",
"id": "https://example.com/fail.json",
"definitions": {
"versionType": {
"type": "string",
"enum": [ "1.0", "1.1", "2.0" ]
}
},
"properties": {
"version": { "$ref": "#/definitions/versionType" }
},
"required": [ "version" ]
}
""")

test "regression passes" do
assert :ok = validate_api(%{"version" => "1.1"} )
end
end

0 comments on commit f66f95e

Please sign in to comment.