Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #38 from seomoz/fix-37

Fix 37
  • Loading branch information...
commit 7aad75dd9008947343f4cc9fddb7e50601caa25c 2 parents ebe6310 + 54395e8
@myronmarston myronmarston authored
View
3  .travis.yml
@@ -8,4 +8,7 @@ rvm:
- 2.0.0
- jruby-19mode
- rbx-19mode
+matrix:
+ allow_failures:
+ - rvm: rbx-19mode
View
5 lib/interpol/endpoint.rb
@@ -279,7 +279,10 @@ def conditionally_make_nullable(raw_schema)
types = Array(raw_schema['type'])
return if types.none? || types.include?('null')
- raw_schema['type'] = (types << "null")
+ # Mark as non-nullable so it doesn't try to recurse down into it
+ # and make it nullable at that level (since we are taking care of it at this level)
+ sub_schema = raw_schema.merge('nullable' => false)
+ raw_schema.replace('type' => ['null', sub_schema])
end
def should_be_nullable?(raw_schema)
View
26 spec/unit/interpol/endpoint_spec.rb
@@ -420,6 +420,28 @@ def new_with(hash)
expect { subject.validate_data!('foo' => nil) }.not_to raise_error
end
+ it 'works with enums' do
+ schema['properties']['foo'] = {
+ 'type' => 'string',
+ 'enum' => %w[ A B C D F ]
+ }
+
+ expect { subject.validate_data!('foo' => nil) }.not_to raise_error
+ expect { subject.validate_data!('foo' => 'A') }.not_to raise_error
+ expect { subject.validate_data!('foo' => 'F') }.not_to raise_error
+ expect { subject.validate_data!('foo' => 'E') }.to raise_error(ValidationError)
+ end
+
+ it 'allows enums to be non-nullable' do
+ schema['properties']['foo'] = {
+ 'nullable' => false,
+ 'type' => 'string',
+ 'enum' => %w[ A B C D F ]
+ }
+
+ expect { subject.validate_data!('foo' => nil) }.to raise_error(ValidationError)
+ end
+
it 'does not add an extra `null` entry to an existing nullable union type' do
schema['properties']['foo']['type'] = %w[ integer null ]
@@ -820,7 +842,7 @@ def new_with(hash)
ex.data["array"] << 0
end
- modified_example = example.apply_filters([filter], request_env)
+ example.apply_filters([filter], request_env)
expect(example.data).to eq(data_2)
end
@@ -834,7 +856,7 @@ def new_with(hash)
ex.data << 0
end
- modified_example = example.apply_filters([filter], request_env)
+ example.apply_filters([filter], request_env)
expect(example.data).to eq(data_2)
end
Please sign in to comment.
Something went wrong with that request. Please try again.