diff --git a/lib/rspec/openapi/schema_merger.rb b/lib/rspec/openapi/schema_merger.rb index b7b20d27..fa5a729b 100644 --- a/lib/rspec/openapi/schema_merger.rb +++ b/lib/rspec/openapi/schema_merger.rb @@ -35,7 +35,7 @@ def merge_schema!(base, spec) elsif base[key].is_a?(Array) && value.is_a?(Array) # parameters need to be merged as if `name` and `in` were the Hash keys. if key == 'parameters' - base[key] |= value + base[key] = value | base[key] base[key].uniq! { |param| param.slice('name', 'in') } else base[key] = value diff --git a/spec/rails/doc/openapi.json b/spec/rails/doc/openapi.json index a9847448..dc1285ea 100644 --- a/spec/rails/doc/openapi.json +++ b/spec/rails/doc/openapi.json @@ -106,29 +106,19 @@ }, "parameters": [ { - "name": "page", - "in": "query", - "schema": { - "type": "integer" - }, - "example": 1 - }, - { - "name": "per", + "name": "filter[price]", "in": "query", "schema": { - "type": "integer" - }, - "example": 10 - }, - { - "name": "X-Authorization-Token", - "in": "header", - "required": true, - "schema": { - "type": "string" + "type": "object", + "properties": { + "price": { + "type": "string" + } + } }, - "example": "token" + "example": { + "price": "0" + } }, { "name": "filter[name]", @@ -146,19 +136,29 @@ } }, { - "name": "filter[price]", + "name": "page", "in": "query", "schema": { - "type": "object", - "properties": { - "price": { - "type": "string" - } - } + "type": "integer" }, - "example": { - "price": "0" - } + "example": 1 + }, + { + "name": "per", + "in": "query", + "schema": { + "type": "integer" + }, + "example": 10 + }, + { + "name": "X-Authorization-Token", + "in": "header", + "required": true, + "schema": { + "type": "string" + }, + "example": "token" } ] }, @@ -268,7 +268,7 @@ "schema": { "type": "integer" }, - "example": 1 + "example": 2 } ], "responses": { diff --git a/spec/rails/doc/openapi.yaml b/spec/rails/doc/openapi.yaml index 642fee47..d984f334 100644 --- a/spec/rails/doc/openapi.yaml +++ b/spec/rails/doc/openapi.yaml @@ -20,16 +20,15 @@ paths: tags: - Table parameters: - - name: page - in: query - schema: - type: integer - example: 1 - - name: per + - name: filter[price] in: query schema: - type: integer - example: 10 + type: object + properties: + price: + type: string + example: + price: '0' - name: filter[name] in: query schema: @@ -39,15 +38,16 @@ paths: type: string example: name: Example Table - - name: filter[price] + - name: page in: query schema: - type: object - properties: - price: - type: string - example: - price: '0' + type: integer + example: 1 + - name: per + in: query + schema: + type: integer + example: 10 - name: X-Authorization-Token in: header required: true @@ -180,7 +180,7 @@ paths: required: true schema: type: integer - example: 1 + example: 2 responses: '200': description: returns a table diff --git a/spec/rails/doc/smart/expected.yaml b/spec/rails/doc/smart/expected.yaml index 5b68c1fa..66b6fcfa 100644 --- a/spec/rails/doc/smart/expected.yaml +++ b/spec/rails/doc/smart/expected.yaml @@ -24,12 +24,18 @@ paths: in: query schema: type: integer - example: 1 + example: 42 - name: per in: query schema: type: integer example: 10 + - name: X-Authorization-Token + in: header + required: true + schema: + type: string + example: token - name: filter[name] in: query schema: @@ -48,12 +54,6 @@ paths: type: string example: price: '0' - - name: X-Authorization-Token - in: header - required: true - schema: - type: string - example: token responses: '200': description: with flat query parameters diff --git a/spec/requests/rails_smart_merge_spec.rb b/spec/requests/rails_smart_merge_spec.rb index 96b8ba28..a59e8562 100644 --- a/spec/requests/rails_smart_merge_spec.rb +++ b/spec/requests/rails_smart_merge_spec.rb @@ -27,7 +27,8 @@ describe '#index' do context it 'returns a list of tables' do it 'with flat query parameters' do - get '/tables', params: { page: '1', per: '10' }, + # These new params replace them in old spec + get '/tables', params: { page: '42', per: '10' }, headers: { authorization: 'k0kubun', "X-Authorization-Token": 'token' } expect(response.status).to eq(200) end