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

Implementing few features #1

Open
wants to merge 98 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
ba18332
add more tests
kanishka-linux Nov 12, 2018
c3c6789
modify Jake module
kanishka-linux Nov 12, 2018
0907115
handle type key when merging
kanishka-linux Nov 12, 2018
8334625
modify Array module
kanishka-linux Nov 12, 2018
d7cd346
add separate module for cases when type not present
kanishka-linux Nov 12, 2018
63a16bf
handle multipleOf property
kanishka-linux Nov 12, 2018
7f57601
modify Object module
kanishka-linux Nov 12, 2018
61ab36b
modify String module
kanishka-linux Nov 12, 2018
693fc77
remove files
kanishka-linux Nov 12, 2018
42a1bed
add and modify dependencies
kanishka-linux Nov 12, 2018
57923ba
add comment
kanishka-linux Nov 12, 2018
47485ad
lower order of gen_all for enum
kanishka-linux Nov 14, 2018
5313a2b
modify getmultipleof and get_float_number
kanishka-linux Nov 14, 2018
c464a02
remove usage of bind_filter from stringer
kanishka-linux Nov 14, 2018
e2cf5f7
use deep_merge again in in allOf gen_init
kanishka-linux Nov 15, 2018
d302482
handle map item and list items separately
kanishka-linux Nov 15, 2018
0d61b1e
add separate get_min_max method to fix exclusiveMaximum feature
kanishka-linux Nov 15, 2018
574d7a9
fix test_generator method
kanishka-linux Nov 15, 2018
4d8c737
add rudimentary support for patternProperties
kanishka-linux Nov 15, 2018
9bdc74a
add patternProperties to prop map
kanishka-linux Nov 17, 2018
87fae25
add dependencies support for object
kanishka-linux Nov 17, 2018
6887e97
remove unnecessary line
kanishka-linux Nov 17, 2018
f4abe43
add tests for object dependencies
kanishka-linux Nov 17, 2018
9a4dc7f
add dependencies key to prop map
kanishka-linux Nov 17, 2018
ee27150
handle dependencies when property is null
kanishka-linux Nov 17, 2018
e598f80
handle test cases of dependencies.json
kanishka-linux Nov 17, 2018
da4e3fa
add default.json
kanishka-linux Nov 18, 2018
b3803e9
separate tuple and list generation methods
kanishka-linux Nov 18, 2018
db8a83d
remove get_float_number method
kanishka-linux Nov 18, 2018
2a84eb7
add decide_min_max with error message
kanishka-linux Nov 18, 2018
265ae51
add test cases for oneOf feature
kanishka-linux Nov 18, 2018
9c97664
add support for oneOf feature
kanishka-linux Nov 18, 2018
33f8a68
add not tests
kanishka-linux Nov 19, 2018
2f1f279
allow returning only type name if type is not nil
kanishka-linux Nov 19, 2018
c844aba
check for not feature when refining properties
kanishka-linux Nov 19, 2018
36f9176
add support for not feature
kanishka-linux Nov 19, 2018
b6aaa84
fix generator for patternProperties
kanishka-linux Nov 19, 2018
fa4e0da
experiment with property based testing
kanishka-linux Nov 19, 2018
6c0bbf1
add map parameter to gen_enum
kanishka-linux Nov 19, 2018
ae8e0c0
validate enum values against existing schema
kanishka-linux Nov 19, 2018
1385cb3
add test enum with constraints
kanishka-linux Nov 19, 2018
4d7ccbf
modify gen_init and add gen_init_root
kanishka-linux Nov 19, 2018
ba76b77
add separate Mixed module
kanishka-linux Nov 19, 2018
e90b467
modify gen_enum
kanishka-linux Nov 20, 2018
923a3b5
remove unnecessary code
kanishka-linux Nov 20, 2018
99c4dba
remove type checking from gen_enum
kanishka-linux Nov 20, 2018
48ff9d0
remove type_map and code clean-up
kanishka-linux Nov 20, 2018
ed96a02
remove gen_enum
kanishka-linux Nov 20, 2018
ffca40c
replace gen_number_init with gen_number
kanishka-linux Nov 20, 2018
b7a8427
remove type_list and rearrange code
kanishka-linux Nov 20, 2018
592bdb1
replace stringer with gen_string and remove enum as function parameter
kanishka-linux Nov 20, 2018
445acb9
add support for ref
kanishka-linux Nov 22, 2018
b371e98
add omap parameter to gen_array
kanishka-linux Nov 22, 2018
2608cb3
rearrange code and add omap parameter to gen_mixed
kanishka-linux Nov 22, 2018
ab21124
add omap parameter to gen_notype
kanishka-linux Nov 22, 2018
953499b
add omap parameter to gen_number
kanishka-linux Nov 22, 2018
97be757
modify functions to support ref feature
kanishka-linux Nov 22, 2018
968bc6e
add Ref module
kanishka-linux Nov 22, 2018
3264a8d
add tests for ref feature
kanishka-linux Nov 22, 2018
5d2f500
convert url string to charlist before using it with httpc
kanishka-linux Nov 22, 2018
6c434d2
add complex ref test
kanishka-linux Nov 22, 2018
fdeaa40
add support for recursive ref
kanishka-linux Nov 24, 2018
7a3316b
add recursive ref tests
kanishka-linux Nov 24, 2018
0270d3c
add one more $ref test
kanishka-linux Nov 28, 2018
edef4da
generate empty list when item map is empty
kanishka-linux Nov 28, 2018
1fcb373
resize generator for recursive ref
kanishka-linux Jan 3, 2019
1393cc9
add check_ref parameter to expand_ref
kanishka-linux Jan 3, 2019
17540f4
add size parameter to generator function
kanishka-linux Jan 3, 2019
1c8b801
remove debug info
kanishka-linux Jan 3, 2019
a145b7e
make size double initially
kanishka-linux Jan 4, 2019
8a9a80d
use bind in gen_init
kanishka-linux Jan 4, 2019
a4fd93d
remove debug info
kanishka-linux Jan 4, 2019
7dfcff3
format code
kanishka-linux Jan 4, 2019
def8fde
add separate get_lazy_streamkey function
kanishka-linux Jan 4, 2019
84e40bc
obtain tuple when expanding ref
kanishka-linux Jan 7, 2019
762da75
return whether ref exists or not along with map
kanishka-linux Jan 7, 2019
ec064bf
check ref key if type not present
kanishka-linux Jan 7, 2019
6d3cb88
check whether ref points to root or not
kanishka-linux Jan 7, 2019
622947e
modify get_lazy_streamkey
kanishka-linux Jan 8, 2019
3dfb63d
fix not property
kanishka-linux Jan 8, 2019
75c974c
remove checking ref
kanishka-linux Jan 8, 2019
d31413d
add separate expand_ref for root ref
kanishka-linux Jan 8, 2019
6fa2978
rewrite filter for debugging
kanishka-linux Jan 8, 2019
0068f16
modify complex recursive ref test
kanishka-linux Jan 8, 2019
0ad2def
add few more tests for checking "not" property
kanishka-linux Jan 9, 2019
2dcc315
remove check_ref_string and related functions
kanishka-linux Jan 9, 2019
3383b23
remove check_ref parameter from expand_ref
kanishka-linux Jan 9, 2019
dc103d3
fix typo
kanishka-linux Jan 9, 2019
4acc525
remove unused variables warning
kanishka-linux Jan 9, 2019
4a63d2a
mix format
kanishka-linux Jan 11, 2019
3b5f6f1
remove omap and size parameters from gen_object
kanishka-linux Jan 11, 2019
1ca1c20
remove omap and size parameters from gen_number
kanishka-linux Jan 11, 2019
7a86668
remove size parameter from gen_string
kanishka-linux Jan 11, 2019
b025f98
remove omap and size parameters from gen_array
kanishka-linux Jan 11, 2019
79adbb5
remove omap and size parameters from gen_mixed
kanishka-linux Jan 11, 2019
7baa611
remove omap and size parameters from gen_notype
kanishka-linux Jan 11, 2019
a2fb44a
mix format
kanishka-linux Jan 11, 2019
f8dc911
pass single schema parameter to gen_init
kanishka-linux Jan 11, 2019
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
98 changes: 79 additions & 19 deletions lib/jake.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,91 @@ defmodule Jake do
"string"
]

def gen(%{"anyOf" => options} = spec) when is_list(options) do
Enum.map(options, fn option ->
gen(Map.merge(Map.drop(spec, ["anyOf"]), option))
end)
def generator(jschema) do
IO.puts(jschema)
jschema |> Poison.decode!() |> gen_init()
end

def gen_init(%{"anyOf" => options} = map) when is_list(options) do
nmap = Map.drop(map, ["anyOf"])

for(n <- options, is_map(n), do: Jake.gen_init(Map.merge(nmap, n)))
|> StreamData.one_of()
end

def gen(%{"type" => type} = spec) when is_binary(type) do
module = String.to_existing_atom("Elixir.Jake.#{String.capitalize(type)}")
apply(module, :gen, [spec])
def gen_init(%{"allOf" => options} = map) when is_list(options) do
nmap = Map.drop(map, ["allOf"])

Enum.reduce(options, %{}, fn x, acc -> Jake.MapUtil.deep_merge(acc, x) end)
|> Jake.MapUtil.deep_merge(nmap)
|> Jake.gen_init()
end

def gen_init(map) do
gen_all(map, map["enum"], map["type"])
end

def gen(%{"type" => types} = spec) when is_list(types) do
Enum.map(types, fn type ->
gen(%{spec | "type" => type})
end)
|> StreamData.one_of()
def gen_all(map, enum, type) when is_list(type) do
list = for n <- type, do: %{"type" => n}
nmap = Map.drop(map, ["type"])
for(n <- list, is_map(n), do: Map.merge(n, nmap) |> Jake.gen_init()) |> StreamData.one_of()
end

# type not present
def gen(spec) do
Enum.map(@types, fn type ->
Map.put(spec, "type", type)
|> gen()
end)
|> StreamData.one_of()
def gen_all(map, enum, type) when type in @types, do: gen_type(type, map)

def gen_all(map, enum, type) when enum != nil, do: gen_enum(enum, type)

def gen_all(map, enum, type) when type == nil do
Jake.Notype.gen_notype(map, type)
end

def gen_type(type, map) when type == "string" do
Jake.String.gen_string(map)
end

def gen_type(type, map) when type in ["integer", "number"] do
Jake.Number.gen_number(map, type)
end

def gen_type(type, map) when type == "boolean" do
StreamData.boolean()
end

def gen_type(type, map) when type == "null" do
StreamData.constant(nil)
end

def gen_type(type, map) when type == "array" do
Jake.Array.gen_array(map, type)
end

def gen_type(type, map) when type == "object" do
Jake.Object.gen_object(map, type)
end

def gen_enum(list, type) do
nlist =
case type do
x when x == "integer" ->
nlist = for n <- list, is_integer(n), do: n

x when x == "number" ->
for n <- list, is_number(n), do: n

x when x == "string" ->
for n <- list, is_binary(n), do: n

x when x == "array" ->
for n <- list, is_list(n), do: n

x when x == "object" ->
for n <- list, is_map(n), do: n

_ ->
list
end

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we have to do all these? can't we just use member_of, assuming the given schema is valid?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider the case when enum list for type number consists of null or string items along with regular numbers, then if we use only member_of without filtering first, then we may get wrong result, even if it is possible to get correct result.

You can also check out the test integer enum

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had assumed enum value would be always correct, I don't understand why would anybody use invalid values.

But let's say we follow the spec and validate the value against enclosing spec, we only seem to handle the type right? what if it's a complex case which has other constraints like maximum etc? Do you think this could be handled in a simpler way?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had assumed enum value would be always correct

In fact, I had also assumed the same, but later on looked at schema doc, which has mentioned that
the elements in the enum array should also be valid against the enclosing schema:, therefore, I decided to filter the enum list depending on the schema type.

But let's say we follow the spec and validate the value against enclosing spec, we only seem to handle the type right?

yes

what if it's a complex case which has other constraints like maximum etc? Do you think this could be handled in a simpler way?

I also thought about it, but it is difficult and hence handled only simple case. I think, validating particular value against schema is out of scope of this project and is a separate project in itself. For this we can use something like ExJsonSchema.Validator, in the beginning, to filter out valid enum values, which then can feed to StreamData.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is possibly a check on the sanity of the schema itself? It complicates the code here. Probably a separate tool could be used to warn/show error to user, if the schema has wrong enclosing type for enums given. This library could assume that the schema is correct. And only concentrate on generating data for correct schema.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This library could assume that the schema is correct.

It will certainly simplify things.

IO.inspect(nlist)
StreamData.member_of(nlist)
end
end
99 changes: 97 additions & 2 deletions lib/jake/array.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,100 @@
defmodule Jake.Array do
def gen(_) do
StreamData.constant([])
@type_list [
%{"type" => "integer"},
%{"type" => "number"},
%{"type" => "boolean"},
%{"type" => "string"},
%{"type" => "null"},
nil
]

@min_items 0

@max_items 1000

def gen_array(map, type), do: arraytype(map, map["enum"], map["items"])
Copy link
Member

@ciju ciju Nov 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be we can name things by what they are about. E.g. Array could be about list or typle. The code seems to handle both cases, but probably the cases could be named better?

E.g. Rename arraytype methods to either list_gen or tuple_gen based on the case handled.

def gen_array(%{"items": items}=map, _) do
  cond do
    is_map(items) or items == nil -> list_gen(map, items) # note: not passing map["enum"], as mentioned in previous comment
    is_array(items) -> tuple_gen(map, items)
    _ -> raise error # ?
  end
end
end

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree about naming things properly. It will avoid unnecessary ambiguity .


def arraytype(map, enum, items) when enum != nil, do: Jake.gen_enum(enum, "array")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could this happen? won't the enum get handle at the Jake module?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider schema,
{"type": "integer", "enum": [10,12, null]}
It will first check type and enter into Jake.Number module. If it finds, enum list there then it will be handled by it.

If schema is {"enum": [10,12, null]}, without mentioning type then it will be handled by Jake module.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but the pattern match for enum happens early? so this will never get executed?

  def gen_all(map, enum, type) when enum != nil, do: gen_enum(enum, type)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! I'll move it lower.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw, is it really necessary to handle enum in all type-specific generator? anyway it's going to call the root module? we could instead just remove the enum handling from all the type-specific generators?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was also thinking the same. I'll check it out!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could instead just remove the enum handling from all the type-specific generators?

It won't handle case like {"type":["integer", "string"], "enum": [1,2,3,"hello", null, true]}. Otherwise all other cases will work. In order to accept above case, we'll need to change/override Jake.gen_enum() method to handle list of types.

I'll see, if it can be done without complicating things.


def arraytype(map, enum, items) when is_list(items) do
list = for n <- items, is_map(n), do: Jake.gen_init(n)

{min, max} = get_min_max(map)

case map["additionalItems"] do
x when (is_boolean(x) and x) or is_nil(x) ->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about

      x when is_map(x) ->
        generate_list(list, Jake.gen_init(map), max, min)
      x when x == true or x == nil -> 
        generate_list(list, get_one_of(), max, min)
      _ -> 
        unless length(list) in min..max, do: raise ...
        StreamData.fixed_list(list)

Avoid extra indirection? Otherwise it becomes difficult to understand the code.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is much better. I'll apply necessary changes.

add_additional_items(list, true, max, min)

x when is_map(x) ->
add_additional_items(list, x, max, min)

_ ->
add_additional_items(list, false, max, min)
end
end

def arraytype(map, enum, items) when is_map(items) do
{min, max} = get_min_max(map)
item = Jake.gen_init(items)
decide_min_max(map, item, min, max)
end

def get_min_max(map) do
min = Map.get(map, "minItems", @min_items)
max = Map.get(map, "maxItems", @max_items)
{min, max}
end

def arraytype(map, enum, items) when is_nil(items) and is_nil(enum) do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly could be combined with the previous arraytype definition (Assuming we are handling enum like one of the previous comments).

def list_gen(map, items) when is_nil(items) or is_map(items) do
  item = if is_nil(items), do: get_on_of(), else: Jake.gen_init(items)
  {min, max} = get_min_max(map)
  decide_min_max(map, item, min, max)
end

item = get_one_of()
{min, max} = get_min_max(map)
decide_min_max(map, item, min, max)
end

def decide_min_max(map, item, min, max)
when is_integer(min) and is_integer(max) and min < max do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if this doesn't match? If it should throw error, then being explicit about it might be better.

if map["uniqueItems"] do
StreamData.uniq_list_of(item, min_length: min, max_length: max)
else
StreamData.list_of(item, min_length: min, max_length: max)
end
end

def get_one_of() do
for(n <- @type_list, is_map(n), do: Jake.gen_init(n)) |> StreamData.one_of()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could this reuse the notype generator

Copy link
Author

@kanishka-linux kanishka-linux Nov 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. In notype, a type will be added to the schema depending on the properties.

In get_one_of, it is not needed, since we already know type, here we using it to generate random values from random types, when no information is given about array. I think here, we can also use StreamData.term() . What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StreamData.term() might not generate valid json values, tuple for example. I was assuming notype should handle cases like empty spec {}, and would generate some valid value

end

def add_additional_items(list, bool, max, min) when is_boolean(bool) and bool do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this the same as pattern matching bool = true?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it is same as bool == true, but gives much better idea about code, since bool can be map also, which is handled by another overloaded function.

generate_list(list, get_one_of(), max, min)
end

def add_additional_items(list, bool, max, min) when is_boolean(bool) and not bool do
if length(list) in min..max do
StreamData.fixed_list(list)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what will happen on else? could it return nil

Copy link
Author

@kanishka-linux kanishka-linux Nov 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we have list, but additional items are not allowed and length(list) (i.e. total items) do not fit in the range then test will fail.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have seen this pattern in multiple places, my question is why are returning nil when we know it's going to fail anyway. Assuming the expected return type is a generator, returning nil here would cause some random error in some unrelated place?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One way, I look at it is that it is easier to understand what code is doing even after few years.

Assuming the expected return type is a generator, returning nil here would cause some random error in some unrelated place?

Yes, it is possible. May be we can use try..catch block or raise some custom error to make things better. I think, nil can also be used as error code in this case, which means no generator, and this case needs to be handled by caller.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Throwing error would be better. Nil being used as error is an assumption that would have to be remembered. Explicit is better.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Throwing error would be better

I'm also thinking the same.

end
end

def add_additional_items(list, map, max, min) when is_map(map) do
generate_list(list, Jake.gen_init(map), max, min)
end

def generate_list(olist, additional, max, min) do
StreamData.bind(StreamData.fixed_list(olist), fn list ->
StreamData.bind_filter(
StreamData.list_of(additional),
fn
nlist
when (length(list) + length(nlist)) in min..max ->
{:cont, StreamData.constant(list ++ nlist)}

nlist
when length(list) in min..max ->
{:cont, StreamData.constant(list)}

nlist when true ->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
nlist when true ->
_ -> :skip

Won't that be enough?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't that be enough?

certainly

:skip
end
)
end)
end
end
5 changes: 0 additions & 5 deletions lib/jake/boolean.ex

This file was deleted.

7 changes: 0 additions & 7 deletions lib/jake/integer.ex

This file was deleted.

33 changes: 33 additions & 0 deletions lib/jake/map_util.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Ref: https://stackoverflow.com/questions/38864001/elixir-how-to-deep-merge-maps
# Ref: https://github.com/activesphere/jake/blob/master/lib/jake/map_util.ex

defmodule Jake.MapUtil do
def deep_merge(left, right) do
Map.merge(left, right, &deep_resolve/3)
end

defp deep_resolve(_key, left, nil) do
left
end

defp deep_resolve(_key, nil, right) do
right
end

defp deep_resolve(key, left, right) when key == "type" do
case {is_list(left), is_list(right)} do
{x, y} when x and y -> left ++ right
{x, y} when x and not y -> left ++ [right]
{x, y} when not x and y -> [left] ++ right
{x, y} when not x and not y -> [left, right]
end
end

defp deep_resolve(_key, left, right) when is_map(left) do
Map.merge(left, right)
end

defp deep_resolve(_key, left, right) when is_list(left) do
left ++ right
end
end
38 changes: 38 additions & 0 deletions lib/jake/notype.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
defmodule Jake.Notype do
@prop %{
"minLength" => "string",
"maxLength" => "string",
"pattern" => "string",
"multipleOf" => "number",
"minimum" => "number",
"maximum" => "number",
"exclusiveMinimum" => "number",
"exclusiveMaximum" => "number",
"items" => "array",
"additionalItems" => "array",
"minItems" => "array",
"maxItems" => "array",
"uniqueItems" => "array",
"properties" => "object",
"patternProperties" => "object",
"additionalProperties" => "object",
"dependencies" => "object",
"required" => "object",
"minProperties" => "object",
"maxProperties" => "object"
}

def gen_notype(map, type) do
nmap = for {k, v} <- map, into: %{}, do: {k, v}
nlist = for {k, v} <- map, into: [], do: @prop[k]

types =
Enum.reduce(nlist, nil, fn
x, acc when not is_nil(x) -> x
x, acc when is_nil(x) -> acc
end)

nmap = if not is_nil(types), do: Map.put(nmap, "type", types), else: nmap
if nmap["type"], do: Jake.gen_init(nmap)
end
end
5 changes: 0 additions & 5 deletions lib/jake/null.ex

This file was deleted.

Loading