Skip to content
This repository was archived by the owner on Dec 21, 2025. It is now read-only.

Commit 20902da

Browse files
committed
134 WIP, but merge for now and park
1 parent 4e3ad88 commit 20902da

File tree

10 files changed

+251
-22
lines changed

10 files changed

+251
-22
lines changed

.github/FUNDING.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
github: EventideSystems
2-
buy_me_a_coffee: eventidesystems
1+
github: EventideSystems

Gemfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ gem 'pagy'
4646
gem 'mailjet'
4747

4848
gem 'net-http' # Silence spurious warnings, see https://github.com/ruby/net-protocol/issues/10
49-
# gem 'rswag'
49+
50+
# API documentation
51+
gem 'rswag-api'
52+
gem 'rswag-ui'
5053

5154
gem 'csv'
5255

@@ -66,6 +69,7 @@ group :development, :test do
6669
# gem 'pry-coolline'
6770
gem 'pry-stack_explorer'
6871
gem 'rspec-rails'
72+
gem 'rswag-specs'
6973
gem 'rubocop-performance'
7074
gem 'rubocop-rails'
7175
gem 'rubocop-rspec'

Gemfile.lock

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ GEM
7272
securerandom (>= 0.3)
7373
tzinfo (~> 2.0, >= 2.0.5)
7474
uri (>= 0.13.1)
75+
addressable (2.8.7)
76+
public_suffix (>= 2.0.2, < 7.0)
7577
api-pagination (6.0.0)
7678
ast (2.4.3)
7779
base64 (0.2.0)
@@ -147,6 +149,9 @@ GEM
147149
actionview (>= 5.0.0)
148150
activesupport (>= 5.0.0)
149151
json (2.12.0)
152+
json-schema (5.1.1)
153+
addressable (~> 2.8)
154+
bigdecimal (~> 3.1)
150155
language_server-protocol (3.17.0.5)
151156
lint_roller (1.1.0)
152157
listen (3.0.8)
@@ -210,6 +215,7 @@ GEM
210215
psych (5.2.6)
211216
date
212217
stringio
218+
public_suffix (6.0.2)
213219
puma (6.6.0)
214220
nio4r (~> 2.0)
215221
racc (1.8.1)
@@ -288,6 +294,17 @@ GEM
288294
rspec-mocks (~> 3.13)
289295
rspec-support (~> 3.13)
290296
rspec-support (3.13.3)
297+
rswag-api (2.16.0)
298+
activesupport (>= 5.2, < 8.1)
299+
railties (>= 5.2, < 8.1)
300+
rswag-specs (2.16.0)
301+
activesupport (>= 5.2, < 8.1)
302+
json-schema (>= 2.2, < 6.0)
303+
railties (>= 5.2, < 8.1)
304+
rspec-core (>= 2.14)
305+
rswag-ui (2.16.0)
306+
actionpack (>= 5.2, < 8.1)
307+
railties (>= 5.2, < 8.1)
291308
rubocop (1.75.7)
292309
json (~> 2.3)
293310
language_server-protocol (~> 3.17.0.2)
@@ -393,6 +410,9 @@ DEPENDENCIES
393410
rails-controller-testing
394411
recaptcha
395412
rspec-rails
413+
rswag-api
414+
rswag-specs
415+
rswag-ui
396416
rubocop-performance
397417
rubocop-rails
398418
rubocop-rspec

app/views/home/index.html.erb

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
<h3 class="text-center text-md font-medium text-gray-700 dark:text-orange-400">
2-
Sponsor this Project
3-
</h3>
4-
<p class="mt-4 text-center text-sm font-medium text-gray-700 dark:text-orange-400">
5-
If you find the service useful, please consider supporting the development and hosting of Brocade.io:
6-
</p>
7-
<p class="mt-4 text-center text-sm font-medium text-gray-700 dark:text-orange-400">
8-
<a href="https://github.com/sponsors/EventideSystems" target="_blank" class="underline">Sponsor via Github</a>
9-
or <a href="https://buymeacoffee.com/eventidesystems" target="_blank" class="underline">Buy us a coffee</a>
10-
</p>
111
<main class="mx-auto mt-16 max-w-7xl px-4 sm:mt-24">
122
<div class="grid grid-cols-2 gap-4">
133
<div class="text-center mt-6">

app/views/layouts/_navbar.html.erb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
<%# <%- if user_signed_in? -%>
2525
<%#= desktop_link_to 'Add Product', new_product_path %>
2626
<%#- end -%>
27-
<%= desktop_link_to 'Documentation', documentation_path %>
28-
<%= desktop_link_to 'Github Project', 'https://github.com/EventideSystems/brocade.io', target: :blank %>
27+
<%= desktop_link_to 'API', documentation_path %>
28+
<%= desktop_link_to 'Github', 'https://github.com/EventideSystems/brocade.io', target: :blank %>
2929
</div>
3030
<div class="hidden md:absolute md:inset-y-0 md:right-0 md:flex md:items-center md:justify-end md:space-x-10 dark:text-white">
3131
<%- if user_signed_in? -%>
@@ -50,6 +50,8 @@
5050
)
5151
%>
5252
<% end %>
53+
54+
<a href="https://www.buymeacoffee.com/eventidesystems" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-orange.png" alt="Buy Me A Coffee" class="h-12 w-auto" xstyle="height: 60px !important;width: 217px !important;" ></a>
5355
</span>
5456
</div>
5557
</nav>
@@ -109,6 +111,8 @@
109111
)
110112
%>
111113
<% end %>
114+
<a href="https://www.buymeacoffee.com/eventidesystems" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-orange.png" alt="Buy Me A Coffee" class="h-8 w-auto"></a>
115+
112116
</div>
113117
</div>
114118
</div>

config/initializers/rswag_api.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# frozen_string_literal: true
2+
3+
Rswag::Api.configure do |c|
4+
# Specify a root folder where Swagger JSON files are located
5+
# This is used by the Swagger middleware to serve requests for API descriptions
6+
# NOTE: If you're using rswag-specs to generate Swagger, you'll need to ensure
7+
# that it's configured to generate files in the same folder
8+
c.openapi_root = Rails.root.join('swagger').to_s
9+
10+
# Inject a lambda function to alter the returned Swagger prior to serialization
11+
# The function will have access to the rack env for the current request
12+
# For example, you could leverage this to dynamically assign the "host" property
13+
#
14+
# c.swagger_filter = lambda { |swagger, env| swagger['host'] = env['HTTP_HOST'] }
15+
end

config/initializers/rswag_ui.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# frozen_string_literal: true
2+
3+
Rswag::Ui.configure do |c|
4+
# List the Swagger endpoints that you want to be documented through the
5+
# swagger-ui. The first parameter is the path (absolute or relative to the UI
6+
# host) to the corresponding endpoint and the second is a title that will be
7+
# displayed in the document selector.
8+
# NOTE: If you're using rspec-api to expose Swagger files
9+
# (under openapi_root) as JSON or YAML endpoints, then the list below should
10+
# correspond to the relative paths for those endpoints.
11+
12+
c.swagger_endpoint '/api-docs/v1/swagger.yaml', 'API V1 Docs'
13+
14+
# Add Basic Auth in case your API is private
15+
# c.basic_auth_enabled = true
16+
# c.basic_auth_credentials 'username', 'password'
17+
end

config/routes.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# frozen_string_literal: true
22

33
Rails.application.routes.draw do
4+
mount Rswag::Ui::Engine => '/api-docs'
5+
mount Rswag::Api::Engine => '/api-docs'
46
# mount Rswag::Ui::Engine => '/api-docs'
57
# mount Rswag::Api::Engine => '/api-docs'
68
# use_doorkeeper do

spec/requests/products_spec.rb

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
# frozen_string_literal: true
2+
3+
require 'swagger_helper'
4+
5+
RSpec.describe 'products', type: :request do # rubocop:disable RSpec/EmptyExampleGroup
6+
path '/api/products' do
7+
get('list products') do
8+
response(200, 'successful') do
9+
after do |example|
10+
example.metadata[:response][:content] = {
11+
'application/json' => {
12+
example: JSON.parse(response.body, symbolize_names: true)
13+
}
14+
}
15+
end
16+
17+
run_test!
18+
end
19+
end
20+
end
21+
22+
path '/api/products/{id}' do
23+
# You'll want to customize the parameter types...
24+
parameter name: 'id', in: :path, type: :string, description: 'id'
25+
26+
get('show product') do
27+
response(200, 'successful') do
28+
let(:id) { '123' }
29+
30+
after do |example|
31+
example.metadata[:response][:content] = {
32+
'application/json' => {
33+
example: JSON.parse(response.body, symbolize_names: true)
34+
}
35+
}
36+
end
37+
38+
run_test!
39+
end
40+
end
41+
end
42+
43+
path '/products' do
44+
get('list products') do
45+
response(200, 'successful') do
46+
after do |example|
47+
example.metadata[:response][:content] = {
48+
'application/json' => {
49+
example: JSON.parse(response.body, symbolize_names: true)
50+
}
51+
}
52+
end
53+
54+
run_test!
55+
end
56+
end
57+
58+
post('create product') do
59+
response(200, 'successful') do
60+
after do |example|
61+
example.metadata[:response][:content] = {
62+
'application/json' => {
63+
example: JSON.parse(response.body, symbolize_names: true)
64+
}
65+
}
66+
end
67+
68+
run_test!
69+
end
70+
end
71+
end
72+
73+
path '/products/new' do
74+
get('new product') do
75+
response(200, 'successful') do
76+
after do |example|
77+
example.metadata[:response][:content] = {
78+
'application/json' => {
79+
example: JSON.parse(response.body, symbolize_names: true)
80+
}
81+
}
82+
end
83+
84+
run_test!
85+
end
86+
end
87+
end
88+
89+
path '/products/{id}/edit' do
90+
# You'll want to customize the parameter types...
91+
parameter name: 'id', in: :path, type: :string, description: 'id'
92+
93+
get('edit product') do
94+
response(200, 'successful') do
95+
let(:id) { '123' }
96+
97+
after do |example|
98+
example.metadata[:response][:content] = {
99+
'application/json' => {
100+
example: JSON.parse(response.body, symbolize_names: true)
101+
}
102+
}
103+
end
104+
105+
run_test!
106+
end
107+
end
108+
end
109+
110+
path '/products/{id}' do
111+
# You'll want to customize the parameter types...
112+
parameter name: 'id', in: :path, type: :string, description: 'id'
113+
114+
get('show product') do
115+
response(200, 'successful') do
116+
let(:id) { '123' }
117+
118+
after do |example|
119+
example.metadata[:response][:content] = {
120+
'application/json' => {
121+
example: JSON.parse(response.body, symbolize_names: true)
122+
}
123+
}
124+
end
125+
126+
run_test!
127+
end
128+
end
129+
130+
patch('update product') do
131+
response(200, 'successful') do
132+
let(:id) { '123' }
133+
134+
after do |example|
135+
example.metadata[:response][:content] = {
136+
'application/json' => {
137+
example: JSON.parse(response.body, symbolize_names: true)
138+
}
139+
}
140+
end
141+
142+
run_test!
143+
end
144+
end
145+
146+
put('update product') do
147+
response(200, 'successful') do
148+
let(:id) { '123' }
149+
150+
after do |example|
151+
example.metadata[:response][:content] = {
152+
'application/json' => {
153+
example: JSON.parse(response.body, symbolize_names: true)
154+
}
155+
}
156+
end
157+
158+
run_test!
159+
end
160+
end
161+
162+
delete('delete product') do
163+
response(200, 'successful') do
164+
let(:id) { '123' }
165+
166+
after do |example|
167+
example.metadata[:response][:content] = {
168+
'application/json' => {
169+
example: JSON.parse(response.body, symbolize_names: true)
170+
}
171+
}
172+
end
173+
174+
run_test!
175+
end
176+
end
177+
end
178+
end

spec/swagger_helper.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
# Specify a root folder where Swagger JSON files are generated
77
# NOTE: If you're using the rswag-api to serve API descriptions, you'll need
88
# to ensure that it's configured to serve Swagger from the same folder
9-
config.swagger_root = Rails.root.join('swagger').to_s
9+
config.openapi_root = Rails.root.join('swagger').to_s
1010

1111
# Define one or more Swagger documents and provide global metadata for each one
1212
# When you run the 'rswag:specs:swaggerize' rake task, the complete Swagger will
13-
# be generated at the provided relative path under swagger_root
13+
# be generated at the provided relative path under openapi_root
1414
# By default, the operations defined in spec files are added to the first
15-
# document below. You can override this behavior by adding a swagger_doc tag to the
16-
# the root example_group in your specs, e.g. describe '...', swagger_doc: 'v2/swagger.json'
17-
config.swagger_docs = {
15+
# document below. You can override this behavior by adding a openapi_spec tag to the
16+
# the root example_group in your specs, e.g. describe '...', openapi_spec: 'v2/swagger.json'
17+
config.openapi_specs = {
1818
'v1/swagger.yaml' => {
1919
openapi: '3.0.1',
2020
info: {
@@ -36,8 +36,8 @@
3636
}
3737

3838
# Specify the format of the output Swagger file when running 'rswag:specs:swaggerize'.
39-
# The swagger_docs configuration option has the filename including format in
39+
# The openapi_specs configuration option has the filename including format in
4040
# the key, this may want to be changed to avoid putting yaml in json files.
4141
# Defaults to json. Accepts ':json' and ':yaml'.
42-
config.swagger_format = :yaml
42+
config.openapi_format = :yaml
4343
end

0 commit comments

Comments
 (0)