Skip to content

Commit 911469a

Browse files
authored
Add rspec-openapi gem and remove outdated rspec_api_documentation gem (#472)
* Revert "Merge pull request #269 from rootstrap/feature/rspec-api-documentation-integration" This reverts commit 84f3dbd, reversing changes made to f01515f. * Move featue-flags spec to /requests/admin * Add rspec-openapi * Initial doc * Using seed 1993 * Freeze test data for docs * Set docs with freezed data * Freeze devise auth token * Rubocop fixes * Create update docs script. Add it to CI to check for missing doc changes * Latest doc version * Do not change password reset token in specs * Fix code smell * Test changes * Make script trim whitespaces * Add docs workflow. Make bin/update-docs parallel * Remove docs from main CI * Set when action runs * Update label name * Setup autolabeler * Set new job for labeler * Set new worflow for labeler * Set condition for PR open * New update doc * Use new ruby script to update doc files * Set rspec-openapi path to handle parallel specs * Use new script and force to run with 8 cores * Use bundle exec to run script * Workflow fixes * Remove trailing whitespace * Run update-docs on push * Update workflow * Set cpu count for load schema * Handle ocassional errors. Clean files always * Fix parallel specs * Clear whitespaces from doc file * Remove update-docs bash file * Update update-docs action * Update README with doc * Fix endpoint in spec * Move CI docs to ci file * Change labeler config * Update labeler * Fix labeler * Move labeler to update docs action * Update docs labeler test * Use target * Use token * Run on merge with main or PR * Fix labeler path * Fix condition * Small fixes * README fixes * Remove unused api blueprint file * Clean up setup * Add comment to initializer * Rename action to check-docs * Sort endpoints alphabetically * Small improvements * Update docs * Make the default be parallelized * Stop freezing time in specs, set dates with regex in doc file * Update api_doc readme * Freeze timestamps via regex and not specs * Make doc check action run on pull_request and push on main * Update Docs and README * Use api_docs label * Remove unnecessary configs * Remove unnecessary permissions * Freeze timestamps in update-docs * Update rspec-openapi to v0.9 * Improve date freezing in script * Improve api_docs readme * Improve readme * Only run openapi initializer in test * Fix code climate for pull_request events * Make the CI commit doc changes * Rename update-docs script * Make CI update docs with parallelization on main push * Remove unnecessary canges to freeze test data * Update README * Remove changes from password spec * Skip feature flags for openapi * Update CI and docs * Add push key to bypass branch protections * Remove duplicate endpoints when merging docs * Copy changes to docs and ci * Remove duplicate permissions * Document ignoring specs
1 parent d7a2f18 commit 911469a

29 files changed

+1082
-888
lines changed

Diff for: .env.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
SERVER_HOST=localhost
2-
PASSWORD_RESET_URL=/
2+
PASSWORD_RESET_URL=localhost

Diff for: .github/labeler.yml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
api_docs:
2+
- 'spec/requests/api/**/*'

Diff for: .github/workflows/ci.yml

+78-16
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ env:
1616
CI: true
1717
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1818
REPO: ${{ github.repository }}
19+
PARALLEL_TEST_FIRST_IS_1: true
1920

2021
jobs:
2122
linters:
@@ -29,9 +30,13 @@ jobs:
2930
uses: ruby/setup-ruby@v1
3031
with:
3132
bundler-cache: true
33+
- name: Label PR
34+
if: github.event.pull_request
35+
uses: actions/labeler@v4
36+
with:
37+
repo-token: ${{ secrets.GITHUB_TOKEN }}
3238
- name: Run Code Analysis
33-
run: |
34-
bundle exec rake code:analysis
39+
run: bundle exec rake code:analysis
3540
tests:
3641
name: Tests
3742
runs-on: ubuntu-latest
@@ -65,13 +70,21 @@ jobs:
6570
steps:
6671
- name: Checkout code
6772
uses: actions/checkout@v3
68-
- name: Set ENV for codeclimate (pull_request)
73+
with:
74+
fetch-depth: 0
75+
- name: Set ENV for CodeClimate
6976
if: github.event_name == 'pull_request'
7077
run: |
7178
git fetch --no-tags --prune --depth=1 origin +refs/heads/$GITHUB_HEAD_REF:refs/remotes/origin/$GITHUB_HEAD_REF
7279
echo "GIT_BRANCH=$GITHUB_HEAD_REF" >> $GITHUB_ENV
7380
echo "GIT_COMMIT_SHA=$(git rev-parse origin/$GITHUB_HEAD_REF)" >> $GITHUB_ENV
7481
echo "PULL_REQUEST_NUMBER=${{ github.event.pull_request.number }}" >> $GITHUB_ENV
82+
- name: Set ENV for API Docs
83+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
84+
run: |
85+
if [ $(git diff ${{ github.event.before }} ${{ github.event.after }} --name-only | grep 'spec/requests/api' | wc -l) -gt 0 ]; then
86+
echo "OPENAPI=true" >> $GITHUB_ENV
87+
fi
7588
- name: Setup Ruby
7689
uses: ruby/setup-ruby@v1
7790
with:
@@ -82,52 +95,101 @@ jobs:
8295
chmod +x ./cc-test-reporter
8396
./cc-test-reporter before-build
8497
- name: Setup Database
85-
run: |
86-
bundle exec rake parallel:load_schema
98+
run: bundle exec rake parallel:load_schema
8799
- name: Check for untracked changes in schema.rb
88100
uses: rootstrap/check_untracked_changes@v1
89101
with:
90102
path: "./db/schema.rb"
91103
- name: Get CPU info
92104
id: cpu_info
93-
run: |
94-
echo "cpu_cores=$(nproc)" >> $GITHUB_ENV
105+
run: echo "cpu_cores=$(nproc)" >> $GITHUB_ENV
95106
- name: Run Tests
96107
env:
97108
KNAPSACK_CI_NODE_TOTAL: ${{ matrix.ci_node_total }}
98109
KNAPSACK_CI_NODE_INDEX: ${{ matrix.ci_node_index }}
99110
PARALLEL_TESTS_CONCURRENCY: ${{ env.cpu_cores }}
100-
run: |
101-
bundle exec parallel_rspec -n $PARALLEL_TESTS_CONCURRENCY -e './bin/parallel_tests'
111+
run: bundle exec parallel_rspec -n $PARALLEL_TESTS_CONCURRENCY -e './bin/parallel_tests'
102112
- name: Check for missing annotations
103113
run: bundle exec annotate
104114
- name: Check for untracked changes in app and spec directories
105115
uses: rootstrap/check_untracked_changes@v1
106116
with:
107117
path: "./app/ ./spec/"
108118
- name: Report to CodeClimate
109-
run: |
110-
./cc-test-reporter format-coverage --output "coverage/coverage.${{ matrix.ci_node_index }}.json"
111-
- name: Upload partial converage
119+
run: ./cc-test-reporter format-coverage --output "coverage/coverage.${{ matrix.ci_node_index }}.json"
120+
- name: Upload partial coverage
112121
uses: actions/upload-artifact@v2
113122
with:
114123
name: coverage
115124
path: "coverage/coverage.${{ matrix.ci_node_index }}.json"
116-
coverage:
117-
name: Coverage
125+
- name: Merge API Docs from threads
126+
env:
127+
CI_NODE_INDEX: ${{ matrix.ci_node_index }}
128+
if: ${{ env.OPENAPI }}
129+
run: bundle exec ./bin/merge-api-docs.rb
130+
- name: Upload partial API Docs
131+
if: ${{ env.OPENAPI }}
132+
uses: actions/upload-artifact@v2
133+
with:
134+
name: api_docs
135+
path: "tmp/openapi${{ matrix.ci_node_index }}.yaml"
136+
merge_results:
137+
name: Merge Results
118138
runs-on: ubuntu-latest
119139
needs: tests
120140
steps:
141+
- name: Checkout code
142+
uses: actions/checkout@v3
143+
with:
144+
fetch-depth: 0
145+
ssh-key: "${{ secrets.PUSH_KEY }}"
146+
- name: Set ENV for CodeClimate
147+
if: github.event_name == 'pull_request'
148+
run: |
149+
git fetch --no-tags --prune --depth=1 origin +refs/heads/$GITHUB_HEAD_REF:refs/remotes/origin/$GITHUB_HEAD_REF
150+
echo "GIT_BRANCH=$GITHUB_HEAD_REF" >> $GITHUB_ENV
151+
echo "GIT_COMMIT_SHA=$(git rev-parse origin/$GITHUB_HEAD_REF)" >> $GITHUB_ENV
152+
echo "PULL_REQUEST_NUMBER=${{ github.event.pull_request.number }}" >> $GITHUB_ENV
153+
- name: Set ENV for API Docs
154+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
155+
run: |
156+
if [ $(git diff ${{ github.event.before }} ${{ github.event.after }} --name-only | grep 'spec/requests/api' | wc -l) -gt 0 ]; then
157+
echo "OPENAPI=true" >> $GITHUB_ENV
158+
fi
121159
- name: Setup Code Climate test-reporter
122160
run: |
123161
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
124162
chmod +x ./cc-test-reporter
125-
- name: download coverage reports
163+
- name: Download coverage reports
126164
uses: actions/download-artifact@v2
127165
with:
128166
name: coverage
129167
path: coverage/coverage.*.json
130-
- name: report coverage
168+
- name: Report coverage
131169
run: |
132170
./cc-test-reporter sum-coverage coverage/**/*.json
133171
./cc-test-reporter upload-coverage
172+
- name: Setup Ruby
173+
if: ${{ env.OPENAPI }}
174+
uses: ruby/setup-ruby@v1
175+
with:
176+
bundler-cache: true
177+
- name: Download API Docs
178+
if: ${{ env.OPENAPI }}
179+
uses: actions/download-artifact@v2
180+
with:
181+
name: api_docs
182+
path: tmp/
183+
- name: Merge API Docs from nodes
184+
env:
185+
MOVE_TMP_FILES: true
186+
if: ${{ env.OPENAPI }}
187+
run: bundle exec ./bin/merge-api-docs.rb
188+
- name: Commit & push API Docs
189+
if: ${{ env.OPENAPI }}
190+
run: |
191+
git config --local user.email "[email protected]"
192+
git config --local user.name "GitHub Action"
193+
git add "doc/openapi.yaml"
194+
git commit -m "Update API Docs" || echo "No changes to commit"
195+
git push origin main

Diff for: .reek.yml

-2
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,6 @@ detectors:
119119
- _
120120
UnusedParameters:
121121
enabled: true
122-
exclude:
123-
- DeviseTokenAuth::TokenFactory#self.create
124122
UnusedPrivateMethod:
125123
enabled: false
126124
UtilityFunction:

Diff for: Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ group :development, :test do
4343
gem 'factory_bot_rails', '~> 6.2'
4444
gem 'pry-byebug', '~> 3.9', platform: :mri
4545
gem 'pry-rails', '~> 0.3.9'
46-
gem 'rspec_api_documentation', '~> 6.1.0'
4746
end
4847

4948
group :development do
@@ -71,6 +70,7 @@ group :test do
7170
gem 'parallel_tests', '~> 4.3'
7271
gem 'pg_query', '~> 4.2.3'
7372
gem 'prosopite', '~> 1.4.1'
73+
gem 'rspec-openapi', '~> 0.9'
7474
gem 'rspec-rails', '~> 6.0'
7575
gem 'rspec-retry', github: 'rootstrap/rspec-retry', branch: 'add-intermittent-callback'
7676
gem 'shoulda-matchers', '~> 5.3'

Diff for: Gemfile.lock

+4-10
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,6 @@ GEM
285285
mini_portile2 (2.8.5)
286286
minitest (5.20.0)
287287
msgpack (1.7.2)
288-
mustache (1.1.1)
289288
net-imap (0.3.7)
290289
date
291290
net-protocol
@@ -398,10 +397,6 @@ GEM
398397
railties (>= 5.2)
399398
rexml (3.2.6)
400399
rouge (4.1.3)
401-
rspec (3.12.0)
402-
rspec-core (~> 3.12.0)
403-
rspec-expectations (~> 3.12.0)
404-
rspec-mocks (~> 3.12.0)
405400
rspec-core (3.12.2)
406401
rspec-support (~> 3.12.0)
407402
rspec-expectations (3.12.3)
@@ -410,6 +405,9 @@ GEM
410405
rspec-mocks (3.12.6)
411406
diff-lcs (>= 1.2.0, < 2.0)
412407
rspec-support (~> 3.12.0)
408+
rspec-openapi (0.9.0)
409+
actionpack (>= 5.2.0)
410+
rspec-core
413411
rspec-rails (6.0.3)
414412
actionpack (>= 6.1)
415413
activesupport (>= 6.1)
@@ -419,10 +417,6 @@ GEM
419417
rspec-mocks (~> 3.12)
420418
rspec-support (~> 3.12)
421419
rspec-support (3.12.1)
422-
rspec_api_documentation (6.1.0)
423-
activesupport (>= 3.0.0)
424-
mustache (~> 1.0, >= 0.99.4)
425-
rspec (~> 3.0)
426420
rubocop (1.57.1)
427421
base64 (~> 0.1.1)
428422
json (~> 2.3)
@@ -561,9 +555,9 @@ DEPENDENCIES
561555
rails (~> 7.0.8)
562556
rails_best_practices (~> 1.20)
563557
reek (~> 6.1, >= 6.1.1)
558+
rspec-openapi (~> 0.9)
564559
rspec-rails (~> 6.0)
565560
rspec-retry!
566-
rspec_api_documentation (~> 6.1.0)
567561
rubocop (~> 1.57)
568562
rubocop-factory_bot (~> 2.24)
569563
rubocop-performance (~> 1.19)

Diff for: README.md

+7-10
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ This template comes with:
2424
- Feature flags support with a UI for management.
2525
- RSpec tests
2626
- Code quality tools
27-
- API documentation following https://apiblueprint.org/
28-
- Docker support
27+
- API documentation following https://www.openapis.org/
2928
- RSpec API Doc Generator
29+
- Docker support
3030

3131
## How to use
3232

@@ -48,6 +48,7 @@ This template comes with:
4848
1. You can now try your REST services!
4949

5050
## Dev scripts
51+
5152
This template provides a handful of scripts to make your dev experience better!
5253

5354
- bin/bundle to run any `bundle` commands.
@@ -93,7 +94,7 @@ To illustrate, `bin/rails console` will run the console in the docker container
9394
- [Rails Best Practices](https://github.com/flyerhzm/rails_best_practices) for rails linting
9495
- [Reek](https://github.com/troessner/reek) for ruby linting
9596
- [RSpec](https://github.com/rspec/rspec) for testing
96-
- [RSpec API Doc Generator](https://github.com/zipmark/rspec_api_documentation) for API documentation
97+
- [RSpec OpenAPI](https://github.com/exoego/rspec-openapi) for API documentation
9798
- [Rubocop](https://github.com/bbatsov/rubocop/) for ruby linting
9899
- [Sendgrid](https://github.com/stephenb/sendgrid) for sending mails
99100
- [Shoulda Matchers](https://github.com/thoughtbot/shoulda-matchers) adds other testing matchers
@@ -112,14 +113,9 @@ To illustrate, `bin/rails console` will run the console in the docker container
112113

113114
https://railsapibasers.docs.apiary.io/
114115

115-
With [RSpec API Doc Generator](https://github.com/zipmark/rspec_api_documentation) you can generate the docs after writing the acceptance specs.
116-
117-
Just run:
118-
119-
`./bin/docs `
120-
121-
An `apiary.apib` file will be generated at the root directory of the project.
116+
With [RSpec API Doc Generator](https://github.com/exoego/rspec-openapi) you can generate the docs after writing requests specs.
122117

118+
See [api_documentation](./docs/api_documentation.md) docs for more info.
123119

124120
## Code quality
125121

@@ -136,6 +132,7 @@ In order to use [New Relic](https://newrelic.com) to monitor your application re
136132
To obtain an API key you must create an account in the platform.
137133

138134
## Configuring Code Climate
135+
139136
1. After adding the project to CC, go to `Repo Settings`
140137
1. On the `Test Coverage` tab, copy the `Test Reporter ID`
141138
1. Set the current value of `CC_TEST_REPORTER_ID` in the [circle-ci project env variables](https://circleci.com/docs/2.0/env-vars/#setting-an-environment-variable-in-a-project)

0 commit comments

Comments
 (0)