Skip to content

Commit 20249db

Browse files
committed
Match additionalOperations method names case-sensitively
1 parent bca8e2d commit 20249db

3 files changed

Lines changed: 26 additions & 8 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
## Unreleased
2+
* 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
23

34
## 2.6.0 (2026-11-04)
45
* support the `multipleOf` keyword (OpenAPI 3.0 and 3.1): a number that is not a multiple of it now fails with `NotMultipleOf`. Decimals are compared exactly, so `19.99` is a multiple of `0.01`. A `multipleOf` that is not a positive number is still ignored. It was ignored before, so a value that passed may now fail

‎lib/openapi_parser/schemas/path_item.rb‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,10 @@ def set_path_item_to_operation
3636

3737
private
3838

39-
# additionalOperations keys are method names as sent on the wire
40-
# (conventionally uppercase); prefer an exact match, else ignore case
39+
# additionalOperations keys use the method's case as sent on the wire,
40+
# and method names are case-sensitive (RFC 9110 §9.1)
4141
def additional_operation(name)
42-
operations = additional_operations
43-
return nil unless operations
44-
45-
operations.fetch(name) { operations.find { |key, _| key.casecmp?(name) }&.last }
42+
additional_operations&.[](name)
4643
end
4744
end
4845
end

‎spec/openapi_parser/schemas/path_item_spec.rb‎

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,30 @@
8383
it 'parses entries as Operations and finds them via #operation' do
8484
copy = path_item.operation('COPY')
8585
expect(copy.class).to eq OpenAPIParser::Schemas::Operation
86-
expect(path_item.operation(:copy)).to eq copy
87-
expect(path_item.operation('Copy')).to eq copy
8886
expect(path_item.operation('LINK')).to eq nil
8987
end
88+
89+
it 'matches method names case-sensitively' do
90+
expect(path_item.operation(:copy)).to eq nil
91+
expect(path_item.operation('Copy')).to eq nil
92+
end
93+
94+
context 'with entries that differ only in case' do
95+
let(:root) do
96+
operation = ->(summary) { { 'summary' => summary, 'responses' => { '200' => { 'description' => 'OK' } } } }
97+
OpenAPIParser.parse({
98+
'openapi' => '3.2.0',
99+
'info' => { 'title' => 'Pet API', 'version' => '1.0' },
100+
'paths' => { '/pets' => { 'additionalOperations' => { 'PURGE' => operation.('upper'), 'purge' => operation.('lower') } } },
101+
}, {})
102+
end
103+
104+
it 'finds each by its exact name' do
105+
expect(path_item.operation('PURGE').summary).to eq 'upper'
106+
expect(path_item.operation('purge').summary).to eq 'lower'
107+
expect(path_item.operation('Purge')).to eq nil
108+
end
109+
end
90110
end
91111

92112
it 'returns nil for non-operation path item fields' do

0 commit comments

Comments
 (0)