-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix(serializer): Account for Required and Enum Properties (#9)
* Fix(serializer): Account for Required and Enum Properties * format * change test
- Loading branch information
1 parent
ae27546
commit 47c49b6
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
defmodule ChannelSpec.SerializerTest do | ||
use ExUnit.Case, async: true | ||
|
||
describe "to_schema/1" do | ||
test "converts an elixir schema to a json schema map" do | ||
schema = %{ | ||
type: :object, | ||
properties: %{ | ||
string: %{type: :string}, | ||
enum: %{type: :string, enum: [:foo, :bar]}, | ||
one_of_array: %{ | ||
type: :array, | ||
items: %{ | ||
one_of: [ | ||
%{type: :string}, | ||
%{type: :number} | ||
] | ||
} | ||
} | ||
} | ||
} | ||
|
||
converted_schema = | ||
schema | ||
|> Serializer.to_schema() | ||
|> Serializer.to_string() | ||
|> Jason.decode!() | ||
|
||
assert converted_schema == %{ | ||
"properties" => %{ | ||
"enum" => %{"enum" => ["foo", "bar"], "type" => "string"}, | ||
"one_of_array" => %{ | ||
"items" => %{"one_of" => [%{"type" => "string"}, %{"type" => "number"}]}, | ||
"type" => "array" | ||
}, | ||
"string" => %{"type" => "string"} | ||
}, | ||
"type" => "object" | ||
} | ||
end | ||
end | ||
end |