Skip to content
Browse files

Merge pull request #34 from seomoz/fix_optional_attrs_for_multi_versi…

…on_schemas

Don't mutate the input schema when making the schema strict.
  • Loading branch information...
2 parents c67d7ed + 26940cb commit eac50aa24851447259cf08e29fd4ef461f3508d9 @myronmarston myronmarston committed
Showing with 12 additions and 1 deletion.
  1. +1 −1 lib/interpol/endpoint.rb
  2. +11 −0 spec/unit/interpol/endpoint_spec.rb
View
2 lib/interpol/endpoint.rb
@@ -195,7 +195,7 @@ def initialize(endpoint, version, message_type, definition)
@message_type = message_type
@status_codes = StatusCodeMatcher.new(definition['status_codes'])
@version = version
- @schema = fetch_from(definition, 'schema')
+ @schema = Marshal.load(Marshal.dump fetch_from(definition, 'schema'))
@path_params = definition.fetch('path_params', DEFAULT_PARAM_HASH.dup)
@query_params = definition.fetch('query_params', DEFAULT_PARAM_HASH.dup)
@examples = extract_examples_from(definition)
View
11 spec/unit/interpol/endpoint_spec.rb
@@ -311,6 +311,17 @@ def new_with(hash)
end
end
+ it 'does not mutate the given schema when making it strict' do
+ new_basic_schema = lambda { {
+ 'type' => 'object',
+ 'properties' => {'foo' => { 'type' => 'integer' } }
+ } }
+
+ schema = new_basic_schema.call
+ EndpointDefinition.new(endpoint, version, 'response', build_hash('schema' => schema))
+ expect(schema).to eq(new_basic_schema.call)
+ end
+
describe "#validate_data" do
let(:schema) do {
'type' => 'object',

0 comments on commit eac50aa

Please sign in to comment.
Something went wrong with that request. Please try again.