Skip to content

Commit

Permalink
Add support raw path params
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksei committed Apr 10, 2024
1 parent db5fe3d commit ec94086
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/rspec/openapi/extractors/hanami.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,20 @@ def request_attributes(request, example)
security = metadata[:security]
description = metadata[:description] || RSpec::OpenAPI.description_builder.call(example)
deprecated = metadata[:deprecated]
raw_path_params = request.path_parameters
path = request.path

route = Hanami.app.router.recognize(request.path, method: request.method)
# binding.irb unless route.params.empty?
raw_path_params = route.params.filter { |key, value| number_or_nil(value) }

result = InspectorAnalyzer.call(request.method, add_id(path, route))

summary ||= result[:summary]
tags ||= result[:tags]
path = add_openapi_id(path, route)

raw_path_params = raw_path_params.slice(*(raw_path_params.keys - RSpec::OpenAPI.ignored_path_params))

[path, summary, tags, operation_id, required_request_params, raw_path_params, description, security, deprecated]
end

Expand Down
28 changes: 28 additions & 0 deletions spec/apps/hanami/doc/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,13 @@ paths:
summary: show
tags:
- Image
parameters:
- name: id
in: path
required: true
schema:
type: integer
example: 1
responses:
'200':
description: returns a image payload
Expand Down Expand Up @@ -444,6 +451,13 @@ paths:
summary: destroy
tags:
- Table
parameters:
- name: id
in: path
required: true
schema:
type: integer
example: 1
responses:
'200':
description: returns a table
Expand Down Expand Up @@ -513,6 +527,13 @@ paths:
summary: show
tags:
- Table
parameters:
- name: id
in: path
required: true
schema:
type: integer
example: 2
responses:
'200':
description: returns a table
Expand Down Expand Up @@ -596,6 +617,13 @@ paths:
summary: update
tags:
- Table
parameters:
- name: id
in: path
required: true
schema:
type: integer
example: 1
requestBody:
content:
application/x-www-form-urlencoded:
Expand Down

0 comments on commit ec94086

Please sign in to comment.