Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Don't mutate the input schema when making the schema strict. #34

Merged
merged 1 commit into from

2 participants

@myronmarston
Owner

This was causing a problem with an endpoint definition that listed
multiple versions, as the same schema got made strict multiple times.

@myronmarston myronmarston Don't mutate the input schema when making the schema strict.
This was causing a problem with an endpoint definition that listed
multiple versions, as the same schema got made strict multiple times.
26940cb
@koos42
Owner

LGTM.

@myronmarston myronmarston merged commit eac50aa into master

1 check passed

Details default The Travis CI build passed
@myronmarston myronmarston deleted the fix_optional_attrs_for_multi_version_schemas branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 7, 2013
  1. @myronmarston

    Don't mutate the input schema when making the schema strict.

    myronmarston authored
    This was causing a problem with an endpoint definition that listed
    multiple versions, as the same schema got made strict multiple times.
This page is out of date. Refresh to see the latest.
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',
Something went wrong with that request. Please try again.