Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support tag generation #10

Merged
merged 3 commits into from
Oct 22, 2020
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,19 @@ paths:
"/tables":
get:
summary: 'tables #index'
tags:
- tables
parameters:
- name: page
in: query
schema:
type: integer
example: 1
- name: per
in: query
schema:
type: integer
example: 10
responses:
'200':
description: returns a list of tables
Expand Down
1 change: 1 addition & 0 deletions lib/rspec/openapi/record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
:request_params, # @param [Hash] - {:request=>"body"}
:request_content_type, # @param [String] - "application/json"
:summary, # @param [String] - "v1/statuses #show"
:tags, # @param [Array] - ["Status"]
:description, # @param [String] - "returns a status"
:status, # @param [Integer] - 200
:response_body, # @param [Object] - {"status" => "ok"}
Expand Down
2 changes: 2 additions & 0 deletions lib/rspec/openapi/record_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def build(context, example:)
route = find_rails_route(request)
path = route.path.spec.to_s.delete_suffix('(.:format)')
summary = "#{route.requirements[:controller]} ##{route.requirements[:action]}"
tags = [route.requirements[:controller]]
else
path = request.path
summary = "#{request.method} #{request.path}"
Expand All @@ -39,6 +40,7 @@ def build(context, example:)
request_params: raw_request_params(request),
request_content_type: request.content_type,
summary: summary,
tags: tags,
description: RSpec::OpenAPI.description_builder.call(example),
status: response.status,
response_body: response_body,
Expand Down
1 change: 1 addition & 0 deletions lib/rspec/openapi/schema_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def build(record)
normalize_path(record.path) => {
record.method.downcase => {
summary: record.summary,
tags: record.tags,
parameters: build_parameters(record),
requestBody: build_request_body(record),
responses: {
Expand Down
10 changes: 10 additions & 0 deletions spec/rails/doc/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ paths:
"/tables":
get:
summary: 'tables #index'
tags:
- tables
parameters:
- name: page
in: query
Expand Down Expand Up @@ -73,6 +75,8 @@ paths:
message: Unauthorized
post:
summary: 'tables #create'
tags:
- tables
requestBody:
content:
application/json:
Expand Down Expand Up @@ -129,6 +133,8 @@ paths:
"/tables/{id}":
get:
summary: 'tables #show'
tags:
- tables
parameters:
- name: id
in: path
Expand Down Expand Up @@ -197,6 +203,8 @@ paths:
message: not found
patch:
summary: 'tables #update'
tags:
- tables
parameters:
- name: id
in: path
Expand Down Expand Up @@ -243,6 +251,8 @@ paths:
updated_at: '2020-07-17T00:00:00+00:00'
delete:
summary: 'tables #destroy'
tags:
- tables
parameters:
- name: id
in: path
Expand Down