Skip to content

Commit

Permalink
Merge pull request #9 from taro-rb/fix_openapi_export_for_same_paths
Browse files Browse the repository at this point in the history
Paths need to be merged, they can include different endpoints per http verb
  • Loading branch information
xijo authored Nov 16, 2024
2 parents 4485f43 + a22b4bd commit 125dac3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/taro/export/open_api_v3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ def call(declarations:, title:, version:)
def export_paths(declarations)
declarations.each_with_object({}) do |declaration, paths|
declaration.routes.each do |route|
paths[route.openapi_path] = export_route(route, declaration)
paths[route.openapi_path] ||= {}
paths[route.openapi_path].merge! export_route(route, declaration)
end
end
end
Expand Down
27 changes: 26 additions & 1 deletion spec/taro/export/open_api_v3_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,17 @@
action_name: 'update',
)

result = described_class.call(declarations: [declaration])
delete_declaration = Taro::Rails::Declaration.new
delete_declaration.add_info 'My endpoint description for DELETE'
delete_declaration.add_param :id, type: 'Integer', null: false
delete_declaration.add_return type: 'Integer', code: 200, null: false, desc: 'okay'
delete_declaration.routes = [Taro::Rails::NormalizedRoute.new(mock_user_route(verb: 'DELETE'))]
delete_declaration.add_openapi_names(
controller_class: stub_const('FooController', Class.new),
action_name: 'destroy',
)

result = described_class.call(declarations: [declaration, delete_declaration])

expect(result.to_yaml).to eq <<~YAML
---
Expand Down Expand Up @@ -53,6 +63,21 @@
application/json:
schema:
"$ref": "#/components/schemas/Foo_update_422_Response"
delete:
summary: My endpoint description for DELETE
parameters:
- name: id
in: path
required: true
schema:
type: integer
responses:
'200':
description: okay
content:
application/json:
schema:
type: integer
components:
schemas:
Foo_update_Input:
Expand Down

0 comments on commit 125dac3

Please sign in to comment.