Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
9d534a2
feat: add rswag gem
sean-dickinson Jul 29, 2023
7bda61c
feat: run rswag:api:install
sean-dickinson Jul 29, 2023
e8db575
feat: run rswag:ui:install
sean-dickinson Jul 29, 2023
768ad72
feat: run rswag:specs:install
sean-dickinson Jul 29, 2023
25328d6
feat: working rswag test
sean-dickinson Jul 29, 2023
67ef985
fix: remove generated tests
sean-dickinson Jul 29, 2023
a64754f
Add localhost default
johnpaulashenfelter Jul 29, 2023
d692cdb
lint
sean-dickinson Jul 29, 2023
d46b641
Hardcode localhost as host for now
johnpaulashenfelter Jul 29, 2023
ef089df
Add swagger for api/v1/countries
johnpaulashenfelter Jul 29, 2023
3d072cb
feat: disable dry run for swagger generation
sean-dickinson Jul 29, 2023
10f9285
fix: countries swagger spec with real id
sean-dickinson Jul 29, 2023
5efb2c0
Add swagger request specs for controllers and regenerate swagger file
johnpaulashenfelter Jul 29, 2023
20d3678
Add request specs for all API controllers with auth
johnpaulashenfelter Jul 29, 2023
b106ad0
feat: only load swagger engine in dev
sean-dickinson Jul 29, 2023
6df149d
Merge branch 'add-rswag' of github.com:rubyforgood/Flaredown into add…
sean-dickinson Jul 29, 2023
b2f1681
Move mandatory API authentication to swagger_helper
johnpaulashenfelter Jul 29, 2023
9a1df45
fix: functional users patch
sean-dickinson Jul 29, 2023
662709d
fix: simplify users swagger spec
sean-dickinson Jul 29, 2023
5d1d748
fix: remove unneeded auth in users spec
sean-dickinson Jul 30, 2023
6805edb
feat: add rswag gem
sean-dickinson Jul 29, 2023
73ca67f
feat: run rswag:api:install
sean-dickinson Jul 29, 2023
a517ad7
feat: run rswag:ui:install
sean-dickinson Jul 29, 2023
95e0b06
feat: run rswag:specs:install
sean-dickinson Jul 29, 2023
05ee623
feat: working rswag test
sean-dickinson Jul 29, 2023
39f72cb
fix: remove generated tests
sean-dickinson Jul 29, 2023
57cab67
Add localhost default
johnpaulashenfelter Jul 29, 2023
63bd7a2
lint
sean-dickinson Jul 29, 2023
01a2fda
Hardcode localhost as host for now
johnpaulashenfelter Jul 29, 2023
cbbf8f8
Add swagger for api/v1/countries
johnpaulashenfelter Jul 29, 2023
c6973f2
feat: disable dry run for swagger generation
sean-dickinson Jul 29, 2023
f029156
fix: countries swagger spec with real id
sean-dickinson Jul 29, 2023
d414da8
feat: only load swagger engine in dev
sean-dickinson Jul 29, 2023
9bac441
Add swagger request specs for controllers and regenerate swagger file
johnpaulashenfelter Jul 29, 2023
6d20b4d
Add request specs for all API controllers with auth
johnpaulashenfelter Jul 29, 2023
6dc1251
Move mandatory API authentication to swagger_helper
johnpaulashenfelter Jul 29, 2023
88cc5bd
fix: functional users patch
sean-dickinson Jul 29, 2023
da06219
fix: simplify users swagger spec
sean-dickinson Jul 29, 2023
2188a62
fix: remove unneeded auth in users spec
sean-dickinson Jul 30, 2023
c814986
merge: upstream changes
sean-dickinson Jul 30, 2023
3d3eb88
fix: Gemfile.lock
sean-dickinson Jul 30, 2023
0b70655
feat: mark weathers_spec as pending
sean-dickinson Jul 30, 2023
9e7aff6
feat: skip all request tests
sean-dickinson Jul 30, 2023
dcf9b87
lint
sean-dickinson Jul 30, 2023
3da5770
fix: remove excess metadata on treatments
sean-dickinson Jul 30, 2023
92b52f1
docs: update readme
sean-dickinson Jul 30, 2023
c22b3c9
docs: update readme
sean-dickinson Jul 30, 2023
9db72dd
feat: functional ethnities swagger spec
sean-dickinson Jul 30, 2023
911fdec
feat: regenerate rswag
sean-dickinson Jul 30, 2023
5c8d05d
feat: functional sexes_spec
sean-dickinson Jul 30, 2023
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,6 +65,10 @@ rake run

Visit your app at [http://localhost:4300](http://localhost:4300)

### Open API Documentation
This project is using the [rswag](https://github.com/rswag/rswag) gem to generate interactive api documentation. You can access this documentation locally at [http://localhost:3000/api-docs/index.html](http://localhost:3000/api-docs/index.html).
If you make changes to the api, you will need to run `bundle exec rake rswag` from the backend directory to update the generated examples.

## CI

Several checks are configured to run on all commits using Github Actions, including lint, build and test steps. Definitions can be found in [./github/workflows](./github/workflows). Those checks which always run are required to be successful for PRs to be mergable.
Expand Down
3 changes: 3 additions & 0 deletions backend/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ gem "kaminari-actionview"
gem "kaminari-mongoid"
gem "rack-cors", "1.1.1", require: "rack/cors" # freezing to gemfile.lock version because heroku is not respecting lockfile
gem "simplecov", require: false, group: :test
gem "rswag-api"
gem "rswag-ui"

group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
Expand All @@ -78,6 +80,7 @@ group :development, :test do
gem "pry-rails"
gem "rspec-rails"
gem "standardrb"
gem "rswag-specs"
end

group :development do
Expand Down
15 changes: 15 additions & 0 deletions backend/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ GEM
i18n_data (0.13.0)
json (2.6.3)
json (2.6.3-java)
json-schema (3.0.0)
addressable (>= 2.8)
jwt (2.3.0)
kaminari-actionview (1.2.1)
actionview
Expand Down Expand Up @@ -381,6 +383,16 @@ GEM
rspec-mocks (~> 3.12)
rspec-support (~> 3.12)
rspec-support (3.12.1)
rswag-api (2.10.1)
railties (>= 3.1, < 7.1)
rswag-specs (2.10.1)
activesupport (>= 3.1, < 7.1)
json-schema (>= 2.2, < 4.0)
railties (>= 3.1, < 7.1)
rspec-core (>= 2.14)
rswag-ui (2.10.1)
actionpack (>= 3.1, < 7.1)
railties (>= 3.1, < 7.1)
rubocop (1.52.1)
json (~> 2.3)
parallel (~> 1.10)
Expand Down Expand Up @@ -515,6 +527,9 @@ DEPENDENCIES
rails_12factor
rake
rspec-rails
rswag-api
rswag-specs
rswag-ui
ruby-progressbar
seedbank
shoulda-matchers
Expand Down
9 changes: 9 additions & 0 deletions backend/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,13 @@
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require File.expand_path("../config/application", __FILE__)
require_relative "config/application"

# Workaround for https://github.com/rswag/rswag/issues/359
if defined? RSpec
RSpec.configure do |config|
config.swagger_dry_run = false
end
end

Rails.application.load_tasks
13 changes: 13 additions & 0 deletions backend/config/initializers/rswag_api.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Rswag::Api.configure do |c|
# Specify a root folder where Swagger JSON files are located
# This is used by the Swagger middleware to serve requests for API descriptions
# NOTE: If you're using rswag-specs to generate Swagger, you'll need to ensure
# that it's configured to generate files in the same folder
c.swagger_root = Rails.root.to_s + "/swagger"

# Inject a lambda function to alter the returned Swagger prior to serialization
# The function will have access to the rack env for the current request
# For example, you could leverage this to dynamically assign the "host" property
#
# c.swagger_filter = lambda { |swagger, env| swagger['host'] = env['HTTP_HOST'] }
end
15 changes: 15 additions & 0 deletions backend/config/initializers/rswag_ui.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Rswag::Ui.configure do |c|
# List the Swagger endpoints that you want to be documented through the
# swagger-ui. The first parameter is the path (absolute or relative to the UI
# host) to the corresponding endpoint and the second is a title that will be
# displayed in the document selector.
# NOTE: If you're using rspec-api to expose Swagger files
# (under swagger_root) as JSON or YAML endpoints, then the list below should
# correspond to the relative paths for those endpoints.

c.swagger_endpoint "/api-docs/v1/swagger.yaml", "API V1 Docs"

# Add Basic Auth in case your API is private
# c.basic_auth_enabled = true
# c.basic_auth_credentials 'username', 'password'
end
5 changes: 5 additions & 0 deletions backend/config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# rubocop:disable Metrics/BlockLength

Rails.application.routes.draw do
if Rails.env.development?
mount Rswag::Ui::Engine => "/api-docs"
mount Rswag::Api::Engine => "/api-docs"
end

root "application#root"

# Authentication
Expand Down
86 changes: 86 additions & 0 deletions backend/spec/requests/api/v1/checkins_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
require "swagger_helper"

RSpec.describe "api/v1/checkins", type: :request do
path "/api/checkins" do
get("list checkins") do
response(200, "successful") do
after do |example|
example.metadata[:response][:content] = {
"application/json" => {
example: JSON.parse(response.body, symbolize_names: true)
}
}
end
pending "Not yet implemented, when implemented uncomment the assertion below"
# run_test!
end
end

post("create checkin") do
response(200, "successful") do
after do |example|
example.metadata[:response][:content] = {
"application/json" => {
example: JSON.parse(response.body, symbolize_names: true)
}
}
end
pending "Not yet implemented, when implemented uncomment the assertion below"
# run_test!
end
end
end

path "/api/checkins/{id}" do
# You'll want to customize the parameter types...
parameter name: "id", in: :path, type: :string, description: "id"

get("show checkin") do
response(200, "successful") do
let(:id) { "123" }

after do |example|
example.metadata[:response][:content] = {
"application/json" => {
example: JSON.parse(response.body, symbolize_names: true)
}
}
end
pending "Not yet implemented, when implemented uncomment the assertion below"
# run_test!
end
end

patch("update checkin") do
response(200, "successful") do
let(:id) { "123" }

after do |example|
example.metadata[:response][:content] = {
"application/json" => {
example: JSON.parse(response.body, symbolize_names: true)
}
}
end
pending "Not yet implemented, when implemented uncomment the assertion below"
# run_test!
end
end

put("update checkin") do
response(200, "successful") do
let(:id) { "123" }

after do |example|
example.metadata[:response][:content] = {
"application/json" => {
example: JSON.parse(response.body, symbolize_names: true)
}
}
end
pending "Not yet implemented, when implemented uncomment the assertion below"
# run_test!
end
end
end
end
54 changes: 54 additions & 0 deletions backend/spec/requests/api/v1/conditions_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
require "swagger_helper"

RSpec.describe "api/v1/conditions", type: :request do
path "/api/conditions" do
get("list conditions") do
response(200, "successful") do
after do |example|
example.metadata[:response][:content] = {
"application/json" => {
example: JSON.parse(response.body, symbolize_names: true)
}
}
end
pending "Not yet implemented, when implemented uncomment the assertion below"
# run_test!
end
end

post("create condition") do
response(200, "successful") do
after do |example|
example.metadata[:response][:content] = {
"application/json" => {
example: JSON.parse(response.body, symbolize_names: true)
}
}
end
pending "Not yet implemented, when implemented uncomment the assertion below"
# run_test!
end
end
end

path "/api/conditions/{id}" do
# You'll want to customize the parameter types...
parameter name: "id", in: :path, type: :string, description: "id"

get("show condition") do
response(200, "successful") do
let(:id) { "123" }

after do |example|
example.metadata[:response][:content] = {
"application/json" => {
example: JSON.parse(response.body, symbolize_names: true)
}
}
end
pending "Not yet implemented, when implemented uncomment the assertion below"
# run_test!
end
end
end
end
38 changes: 38 additions & 0 deletions backend/spec/requests/api/v1/countries_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
require "swagger_helper"

RSpec.describe "api/v1/countries", type: :request do
path "/api/countries" do
get("list countries") do
response(200, "successful") do
after do |example|
example.metadata[:response][:content] = {
"application/json" => {
example: JSON.parse(response.body, symbolize_names: true)
}
}
end
run_test!
end
end
end

path "/api/countries/{id}" do
# You'll want to customize the parameter types...
parameter name: "id", in: :path, type: :string, description: "id"

get("show country") do
response(200, "successful") do
let(:id) { "US" }

after do |example|
example.metadata[:response][:content] = {
"application/json" => {
example: JSON.parse(response.body, symbolize_names: true)
}
}
end
run_test!
end
end
end
end
40 changes: 40 additions & 0 deletions backend/spec/requests/api/v1/day_habits_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
require "swagger_helper"

RSpec.describe "api/v1/day_habits", type: :request do
path "/api/day_habits" do
get("list day_habits") do
response(200, "successful") do
after do |example|
example.metadata[:response][:content] = {
"application/json" => {
example: JSON.parse(response.body, symbolize_names: true)
}
}
end
pending "Not yet implemented, when implemented uncomment the assertion below"
# run_test!
end
end
end

path "/api/day_habits/{id}" do
# You'll want to customize the parameter types...
parameter name: "id", in: :path, type: :string, description: "id"

get("show day_habit") do
response(200, "successful") do
let(:id) { "123" }

after do |example|
example.metadata[:response][:content] = {
"application/json" => {
example: JSON.parse(response.body, symbolize_names: true)
}
}
end
pending "Not yet implemented, when implemented uncomment the assertion below"
# run_test!
end
end
end
end
40 changes: 40 additions & 0 deletions backend/spec/requests/api/v1/education_levels_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
require "swagger_helper"

RSpec.describe "api/v1/education_levels", type: :request do
path "/api/education_levels" do
get("list education_levels") do
response(200, "successful") do
after do |example|
example.metadata[:response][:content] = {
"application/json" => {
example: JSON.parse(response.body, symbolize_names: true)
}
}
end
pending "Not yet implemented, when implemented uncomment the assertion below"
# run_test!
end
end
end

path "/api/education_levels/{id}" do
# You'll want to customize the parameter types...
parameter name: "id", in: :path, type: :string, description: "id"

get("show education_level") do
response(200, "successful") do
let(:id) { "123" }

after do |example|
example.metadata[:response][:content] = {
"application/json" => {
example: JSON.parse(response.body, symbolize_names: true)
}
}
end
pending "Not yet implemented, when implemented uncomment the assertion below"
# run_test!
end
end
end
end
Loading