Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## Unreleased
* match `additionalOperations` method names case-sensitively ([OpenAPI 3.2](https://spec.openapis.org/oas/v3.2.0.html#path-item-object), [RFC 9110 §9.1](https://www.rfc-editor.org/rfc/rfc9110.html#section-9.1)). Standard methods still match their fixed fields in any case
* check the keywords next to `allOf`, `anyOf` and `oneOf` (OpenAPI 3.0 and 3.1), such as `{ allOf: [...], required: [a] }`, and all of these keywords when a schema has more than one. They were ignored before, so a value that passed may now fail. In particular, `additionalProperties: false` next to `allOf` now rejects the properties defined only in `allOf`, as in JSON Schema
* return the coerced value from `allOf` and `oneOf` when `coerce_value` is on. They returned the original value before
* support the `dependentRequired` keyword (OpenAPI 3.1): an object that has a property but not the properties it depends on now fails with `NotExistDependentRequiredKey`. It was ignored before, so a value that passed may now fail
Expand Down
9 changes: 3 additions & 6 deletions lib/openapi_parser/schemas/path_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,10 @@ def set_path_item_to_operation

private

# additionalOperations keys are method names as sent on the wire
# (conventionally uppercase); prefer an exact match, else ignore case
# additionalOperations keys use the method's case as sent on the wire,
# and method names are case-sensitive (RFC 9110 §9.1)
def additional_operation(name)
operations = additional_operations
return nil unless operations

operations.fetch(name) { operations.find { |key, _| key.casecmp?(name) }&.last }
additional_operations&.[](name)
end
end
end
24 changes: 22 additions & 2 deletions spec/openapi_parser/schemas/path_item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,30 @@
it 'parses entries as Operations and finds them via #operation' do
copy = path_item.operation('COPY')
expect(copy.class).to eq OpenAPIParser::Schemas::Operation
expect(path_item.operation(:copy)).to eq copy
expect(path_item.operation('Copy')).to eq copy
expect(path_item.operation('LINK')).to eq nil
end

it 'matches method names case-sensitively' do
expect(path_item.operation(:copy)).to eq nil
expect(path_item.operation('Copy')).to eq nil
end

context 'with entries that differ only in case' do
let(:root) do
operation = ->(summary) { { 'summary' => summary, 'responses' => { '200' => { 'description' => 'OK' } } } }
OpenAPIParser.parse({
'openapi' => '3.2.0',
'info' => { 'title' => 'Pet API', 'version' => '1.0' },
'paths' => { '/pets' => { 'additionalOperations' => { 'PURGE' => operation.('upper'), 'purge' => operation.('lower') } } },
}, {})
end

it 'finds each by its exact name' do
expect(path_item.operation('PURGE').summary).to eq 'upper'
expect(path_item.operation('purge').summary).to eq 'lower'
expect(path_item.operation('Purge')).to eq nil
end
end
end

it 'returns nil for non-operation path item fields' do
Expand Down
Loading