r2-oas 0.1.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -0
- data/.rubocop.yml +6 -3
- data/.rubocop_todo.yml +68 -1
- data/.travis.yml +6 -2
- data/Appraisals +13 -0
- data/CHANGELOG.md +58 -1
- data/GEMSPEC.md +20 -0
- data/README.ja.md +65 -396
- data/README.md +62 -392
- data/devscript/all_support_ruby.sh +43 -0
- data/devscript/bundle_for_all_support_ruby.sh +31 -0
- data/devscript/rspec_for_all_support_ruby.sh +27 -0
- data/docs/.nojekyll +0 -0
- data/docs/README.md +173 -0
- data/docs/_sidebar.md +25 -0
- data/docs/attention/if_clash.md +17 -0
- data/docs/index.html +29 -0
- data/docs/{versions/v3.md → schema/3.0.0.md} +1 -1
- data/docs/setting/COC.md +14 -0
- data/docs/setting/CORS.md +22 -0
- data/docs/setting/configure.md +176 -0
- data/docs/trableshouting/runtime_error.md +44 -0
- data/docs/{HOW_TO_ANALYZE_DOCS.md → usage/analyze_docs.md} +52 -52
- data/docs/usage/clean_docs.md +19 -0
- data/docs/{HOW_TO_DEPLOY_SWAGGER_DOC.md → usage/deploy_docs.md} +29 -29
- data/docs/usage/display_paths_list.md +35 -0
- data/docs/{HOW_TO_DISPLAY_PATHS_STATS.md → usage/display_paths_stats.md} +15 -14
- data/docs/{HOW_TO_START_SWAGGER_EDITOR.md → usage/edit_docs.md} +88 -88
- data/docs/usage/generate_docs.md +412 -0
- data/docs/{HOW_TO_MONITOR_SWAGGER_DOC.md → usage/monitor_docs.md} +71 -71
- data/docs/usage/use_hook_methods.md +236 -0
- data/docs/{HOW_TO_USE_HOOK_WHEN_GENERATE_DOC.md → usage/use_hook_to_generate_docs.md} +48 -57
- data/docs/{HOW_TO_USE_SCHEMA_NAMESPACE.md → usage/use_schema_namespace.md} +46 -41
- data/docs/{HOW_TO_USE_TAG_NAMESPACE.md → usage/use_tag_namespace.md} +46 -42
- data/docs/{HOW_TO_START_SWAGGER_UI.md → usage/view_docs.md} +132 -132
- data/gemfiles/ruby_2.3.3.gemfile +11 -0
- data/gemfiles/ruby_2.4.2.gemfile +11 -0
- data/gemfiles/ruby_2.5.8.gemfile +11 -0
- data/gemfiles/ruby_2.6.6.gemfile +11 -0
- data/gemfiles/ruby_2.7.1.gemfile +11 -0
- data/lib/r2-oas.rb +3 -4
- data/lib/r2-oas/app_configuration.rb +19 -16
- data/lib/r2-oas/deploy/client.rb +14 -2
- data/lib/r2-oas/errors.rb +1 -0
- data/lib/r2-oas/lib/core_ext/hash/deep_merge.rb +44 -0
- data/lib/r2-oas/lib/core_ext/object/blank.rb +135 -0
- data/lib/r2-oas/lib/three-way-merge/twm.rb +83 -0
- data/lib/r2-oas/schema/builder.rb +23 -0
- data/lib/r2-oas/schema/editor.rb +26 -7
- data/lib/r2-oas/schema/generator.rb +1 -1
- data/lib/r2-oas/schema/manager/file_manager.rb +26 -0
- data/lib/r2-oas/schema/ui.rb +0 -1
- data/lib/r2-oas/schema/v3/analyzer/base_analyzer.rb +1 -6
- data/lib/r2-oas/schema/v3/analyzer/components/object_analyzer.rb +1 -1
- data/lib/r2-oas/schema/v3/analyzer/path_analyzer.rb +1 -1
- data/lib/r2-oas/schema/v3/analyzer/tag_analyzer.rb +1 -1
- data/lib/r2-oas/schema/v3/builder.rb +28 -0
- data/lib/r2-oas/schema/v3/builder/base_builder.rb +60 -0
- data/lib/r2-oas/schema/v3/builder/doc_builder.rb +43 -0
- data/lib/r2-oas/schema/v3/cleaner/base_cleaner.rb +1 -1
- data/lib/r2-oas/schema/v3/generator.rb +1 -5
- data/lib/r2-oas/schema/v3/generator/base_generator.rb +30 -1
- data/lib/r2-oas/schema/v3/generator/components/object_generator.rb +6 -25
- data/lib/r2-oas/schema/v3/generator/components/request_body_generator.rb +6 -6
- data/lib/r2-oas/schema/v3/generator/doc_generator.rb +84 -18
- data/lib/r2-oas/schema/v3/generator/path_generator.rb +7 -19
- data/lib/r2-oas/schema/v3/generator/schema_generator.rb +6 -26
- data/lib/r2-oas/schema/v3/manager/file/base_file_manager.rb +10 -4
- data/lib/r2-oas/schema/v3/manager/pathname_manager.rb +6 -1
- data/lib/r2-oas/schema/v3/object/path_item_object.rb +17 -9
- data/lib/r2-oas/store.rb +118 -0
- data/lib/r2-oas/task_logging.rb +6 -0
- data/lib/r2-oas/tasks/main.rake +66 -73
- data/lib/r2-oas/tasks/tool.rake +25 -28
- data/lib/r2-oas/tool/paths/ls.rb +1 -1
- data/lib/r2-oas/version.rb +1 -1
- data/r2-oas.gemspec +20 -25
- metadata +122 -52
- data/Gemfile.lock +0 -207
- data/docs/HOW_TO_CLEAN_DOCS.md +0 -19
- data/docs/HOW_TO_DISPLAY_PATHS_LIST.md +0 -28
- data/docs/HOW_TO_GENERATE_DOCS.md +0 -256
@@ -0,0 +1,43 @@
|
|
1
|
+
#!/usr/local/bin/bash
|
2
|
+
|
3
|
+
if [ $# -eq 0 ]; then
|
4
|
+
echo "Please specify 'rspec' or 'bundle', 'list'"
|
5
|
+
exit 1
|
6
|
+
fi
|
7
|
+
|
8
|
+
# Check if rbenv is installed
|
9
|
+
which rbenv > /dev/null 2>&1 && if [ $? -ne 0 ]; then echo -e 'rbenv is need\nPlease install rbenv: https://github.com/rbenv/rbenv'; exit 1; fi
|
10
|
+
|
11
|
+
declare -a all_support_ruby=(
|
12
|
+
'2.3.3'
|
13
|
+
'2.4.2'
|
14
|
+
'2.5.8'
|
15
|
+
'2.6.6'
|
16
|
+
'2.7.1'
|
17
|
+
)
|
18
|
+
|
19
|
+
declare -a target_ruby
|
20
|
+
declare -a versions=${@:2:$#}
|
21
|
+
if [[ $# > 1 ]]; then
|
22
|
+
target_ruby=("${versions[@]}")
|
23
|
+
else
|
24
|
+
target_ruby=("${all_support_ruby[@]}")
|
25
|
+
fi
|
26
|
+
|
27
|
+
command=$1
|
28
|
+
case $command in
|
29
|
+
"bundle")
|
30
|
+
source "$(pwd)/devscript/bundle_for_all_support_ruby.sh" "${target_ruby[@]}";;
|
31
|
+
"rspec")
|
32
|
+
source "$(pwd)/devscript/rspec_for_all_support_ruby.sh" "${target_ruby[@]}";;
|
33
|
+
"list")
|
34
|
+
echo "===== Display All Support Ruby Version ====="
|
35
|
+
for version in "${target_ruby[@]}"; do
|
36
|
+
echo "${version}"
|
37
|
+
done
|
38
|
+
echo "============================================";;
|
39
|
+
*)
|
40
|
+
echo -n "Do not support command: ${command}\nPlease specify 'bundle' or 'rspec', 'list'"
|
41
|
+
exit 1;;
|
42
|
+
esac
|
43
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
#!/usr/local/bin/bash
|
2
|
+
|
3
|
+
# Bundle install each All Support Ruby
|
4
|
+
declare -a report
|
5
|
+
for version in $@; do
|
6
|
+
echo "== Bundle install for Ruby Version: ${version} =="
|
7
|
+
|
8
|
+
# Remove gemfile.lock
|
9
|
+
lockfile="./gemfiles/ruby_${version}.gemfile.lock"
|
10
|
+
if [[ -f $lockfile ]]; then rm $lockfile; fi
|
11
|
+
|
12
|
+
# Change Ruby Version
|
13
|
+
echo ${version} > ./.ruby-version && rbenv rehash
|
14
|
+
|
15
|
+
# Bundle install
|
16
|
+
if [[ $version == "2.3.3" ]]; then
|
17
|
+
BUNDLE_GEMFILE=./gemfiles/ruby_${version}.gemfile bundle _1.17.3_ install --path vendor/bundle && report+=("ruby-${version}: $?")
|
18
|
+
else
|
19
|
+
BUNDLE_GEMFILE=./gemfiles/ruby_${version}.gemfile bundle install --path vendor/bundle && report+=("ruby-${version}: $?")
|
20
|
+
fi
|
21
|
+
if [ $? -ne 0 ]; then report+=("ruby-${version}: 1 (failed)");fi
|
22
|
+
|
23
|
+
echo "== End for Ruby Version: ${version} =="
|
24
|
+
done
|
25
|
+
|
26
|
+
# Display report
|
27
|
+
echo "===== Bundle install for All Support Ruby Result ====="
|
28
|
+
for result in "${report[@]}"; do
|
29
|
+
echo $result
|
30
|
+
done
|
31
|
+
echo "======================================================"
|
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/local/bin/bash
|
2
|
+
|
3
|
+
# Rspec each All Support Ruby
|
4
|
+
declare -a report
|
5
|
+
for version in $@; do
|
6
|
+
echo "== Rspec for Ruby Version: ${version} =="
|
7
|
+
|
8
|
+
# Change Ruby Version
|
9
|
+
echo ${version} > ./.ruby-version && rbenv rehash
|
10
|
+
|
11
|
+
# Rspec
|
12
|
+
if [[ $version == "2.3.3" ]];then
|
13
|
+
BUNDLE_GEMFILE=./gemfiles/ruby_${version}.gemfile bundle _1.17.3_ exec rspec --format progress && report+=("ruby-${version}: $?")
|
14
|
+
else
|
15
|
+
BUNDLE_GEMFILE=./gemfiles/ruby_${version}.gemfile bundle exec rspec --format progress && report+=("ruby-${version}: $?")
|
16
|
+
fi
|
17
|
+
if [ $? -ne 0 ]; then report+=("ruby-${version}: 1 (failed)");fi
|
18
|
+
|
19
|
+
echo "== End for Ruby Version: ${version} =="
|
20
|
+
done
|
21
|
+
|
22
|
+
# Display report
|
23
|
+
echo "===== Rspec for All Support Ruby Result ====="
|
24
|
+
for result in "${report[@]}"; do
|
25
|
+
echo $result
|
26
|
+
done
|
27
|
+
echo "============================================="
|
data/docs/.nojekyll
ADDED
File without changes
|
data/docs/README.md
ADDED
@@ -0,0 +1,173 @@
|
|
1
|
+
# R2-OAS
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/r2-oas.svg)](https://badge.fury.io/rb/r2-oas)
|
4
|
+
[![Build Status](https://travis-ci.org/yukihirop/r2-oas.svg?branch=master)](https://travis-ci.org/yukihirop/r2-oas)
|
5
|
+
[![Coverage Status](https://coveralls.io/repos/github/yukihirop/r2-oas/badge.svg)](https://coveralls.io/github/yukihirop/r2-oas)
|
6
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/f8c3846f350bb412fd63/maintainability)](https://codeclimate.com/github/yukihirop/r2-oas/maintainability)
|
7
|
+
|
8
|
+
Generate api docment(OpenAPI) side only from `Rails` routing.
|
9
|
+
|
10
|
+
Provides a rake command to help `generate` , `view` , and `edit` OpenAPI documents.
|
11
|
+
|
12
|
+
```bash
|
13
|
+
bundle exec rake routes:oas:docs # generate
|
14
|
+
bundle exec rake routes:oas:ui # view
|
15
|
+
bundle exec rake routes:oas:editor # edit
|
16
|
+
bundle exec rake routes:oas:monitor # monitor
|
17
|
+
bundle exec rake routes:oas:dist # distribute
|
18
|
+
bundle exec rake routes:oas:clean # clean
|
19
|
+
bundle exec rake routes:oas:analyze # analyze
|
20
|
+
bundle exec rake routes:oas:deploy # deploy
|
21
|
+
```
|
22
|
+
|
23
|
+
## 💎 Installation
|
24
|
+
|
25
|
+
Add this line to your application's Gemfile:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
group :development do
|
29
|
+
gem 'r2-oas'
|
30
|
+
end
|
31
|
+
```
|
32
|
+
|
33
|
+
And then execute:
|
34
|
+
|
35
|
+
$ bundle
|
36
|
+
|
37
|
+
Or install it yourself as:
|
38
|
+
|
39
|
+
$ gem install r2-oas
|
40
|
+
|
41
|
+
## 🔦 Requirements
|
42
|
+
|
43
|
+
If you want to view with `Swagger UI` or edit with `Swagger Editor`, This gem needs the following:
|
44
|
+
|
45
|
+
- [`swaggerapi/swagger-ui:latest` docker image](https://hub.docker.com/r/swaggerapi/swagger-ui/)
|
46
|
+
- [`swaggerapi/swagger-editor:latest` docker image](https://hub.docker.com/r/swaggerapi/swagger-editor/)
|
47
|
+
- [`chromedriver`](http://chromedriver.chromium.org/downloads)
|
48
|
+
|
49
|
+
If you do not have it download as below.
|
50
|
+
|
51
|
+
```
|
52
|
+
$ docker pull swaggerapi/swagger-editor:latest
|
53
|
+
$ docker pull swaggerapi/swagger-ui:latest
|
54
|
+
$ brew cask install chromedriver
|
55
|
+
```
|
56
|
+
|
57
|
+
## 🚀 Tutorial
|
58
|
+
|
59
|
+
After requiring a gem,
|
60
|
+
|
61
|
+
```bash
|
62
|
+
bundle exec routes:oas:docs
|
63
|
+
bundle exec routes:oas:editor
|
64
|
+
```
|
65
|
+
|
66
|
+
#### Generate docs
|
67
|
+
|
68
|
+
![oas_docs](https://user-images.githubusercontent.com/11146767/80856236-0b839a80-8c83-11ea-888f-d0e659e0c251.gif)
|
69
|
+
|
70
|
+
|
71
|
+
#### Edit docs
|
72
|
+
|
73
|
+
![oas_editor](https://user-images.githubusercontent.com/11146767/80856240-15a59900-8c83-11ea-9dbd-4382528944f2.gif)
|
74
|
+
|
75
|
+
## 📖 Usage
|
76
|
+
|
77
|
+
|
78
|
+
You can execute the following command in the root directory of rails.
|
79
|
+
|
80
|
+
```bash
|
81
|
+
$ # Generate docs
|
82
|
+
$ bundle exec rake routes:oas:docs # Generate docs
|
83
|
+
$ PATHS_FILE="oas_docs/schema/paths/api/v1/task.yml" bundle exec rake routes:oas:docs # Generate docs by specify unit paths
|
84
|
+
|
85
|
+
$ # Start swagger editor
|
86
|
+
$ bundle exec rake routes:oas:editor # Start swagger editor
|
87
|
+
$ PATHS_FILE="oas_docs/schema/paths/api/v1/task.yml" bundle exec rake routes:oas:editor # Start swagger editor by specify unit paths
|
88
|
+
$ # Start swagger ui
|
89
|
+
$ bundle exec rake routes:oas:ui # Start swagger ui
|
90
|
+
$ PATHS_FILE="oas_docs/schema/paths/api/v1/task.yml" bundle exec rake routes:oas:ui # Start swagger ui by specify unit paths
|
91
|
+
$ # Monitor swagger document
|
92
|
+
$ bundle exec rake routes:oas:monitor # Monitor swagger document
|
93
|
+
$ PATHS_FILE="oas_docs/schema/paths/api/v1/task.yml" bundle exec rake routes:oas:monitor # Monitor swagger by specify unit paths
|
94
|
+
|
95
|
+
$ # Analyze docs
|
96
|
+
$ OAS_FILE="~/Desktop/swagger.yml" bundle exec rake routes:oas:analyze
|
97
|
+
$ # Clean docs
|
98
|
+
$ bundle exec rake routes:oas:clean
|
99
|
+
$ # Deploy docs
|
100
|
+
$ bundle exec rake routes:oas:deploy
|
101
|
+
$ # Distribute swagger document
|
102
|
+
$ bundle exec rake routes:oas:dist
|
103
|
+
$ # Distribute swagger document
|
104
|
+
$ PATHS_FILE="oas_docs/schema/paths/api/v1/task.yml" bundle exec rake routes:oas:dist # Distribute swagger document by specify unit paths
|
105
|
+
|
106
|
+
# Display paths list
|
107
|
+
$ bundle exec rake routes:oas:paths_ls
|
108
|
+
# Display paths stats
|
109
|
+
$ bundle exec rake routes:oas:paths_stats
|
110
|
+
```
|
111
|
+
|
112
|
+
## ❤️ Support Rails Version
|
113
|
+
|
114
|
+
- Rails (>= 4.2.5.1)
|
115
|
+
|
116
|
+
## ❤️ Support Ruby Version
|
117
|
+
|
118
|
+
- Ruby (>= 2.3.3p222 (2016-11-21 revision 56859) [x86_64-darwin18])
|
119
|
+
|
120
|
+
## ❤️ Support Rouging
|
121
|
+
|
122
|
+
- Rails Engine Routing
|
123
|
+
- Rails Normal Routing
|
124
|
+
|
125
|
+
## ❗️ Convention over Configuration (CoC)
|
126
|
+
|
127
|
+
- `tag name` represents `controller name` and determine `paths file name`.
|
128
|
+
- For example, If `controller name` is `Api::V1::UsersController`, `tag_name` is `api/v1/user`. and `paths file name` is `api/v1/user.yml`
|
129
|
+
|
130
|
+
- `_` of `components/{schemas,requestBodies, ...} name` convert `/` when save file.
|
131
|
+
- For example, If `components/schemas name` is `Api_V1_User`, `components/schemas file name` is `api/v1/user.yml`.
|
132
|
+
- `_` is supposed to be used to express `namespace`.
|
133
|
+
- format is `Namespace1_Namespace2_Model`.
|
134
|
+
|
135
|
+
- `.` of `components/{schemas,requestBodies, ...} name` convert `/` when save file.
|
136
|
+
- For example, If `components/schemas name` is `api.v1.User`, `components/schemas file name` is `api/v1/user.yml`.
|
137
|
+
- `.` is supposed to be used to express `namespace`.
|
138
|
+
- format is `namespace1.namespace2.Model`.
|
139
|
+
|
140
|
+
## 🔩 CORS
|
141
|
+
|
142
|
+
Use [rack-cors](https://github.com/cyu/rack-cors) to enable CORS.
|
143
|
+
|
144
|
+
```ruby
|
145
|
+
require 'rack/cors'
|
146
|
+
use Rack::Cors do
|
147
|
+
allow do
|
148
|
+
origins '*'
|
149
|
+
resource '*', headers: :any, methods: [ :get, :post, :put, :delete, :options ]
|
150
|
+
end
|
151
|
+
end
|
152
|
+
```
|
153
|
+
|
154
|
+
Alternatively you can set CORS headers in a `before` block.
|
155
|
+
|
156
|
+
```ruby
|
157
|
+
before do
|
158
|
+
header['Access-Control-Allow-Origin'] = '*'
|
159
|
+
header['Access-Control-Request-Method'] = '*'
|
160
|
+
end
|
161
|
+
```
|
162
|
+
|
163
|
+
## 📝 License
|
164
|
+
|
165
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
166
|
+
|
167
|
+
## 🤝 Contributing
|
168
|
+
|
169
|
+
1. Fork it ( http://github.com/yukihirop/r2-oas/fork )
|
170
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
171
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
172
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
173
|
+
5. Create new Pull Request
|
data/docs/_sidebar.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
<!-- docs/_sidebar.md -->
|
2
|
+
* **Attention**
|
3
|
+
* [If Clash](/attention/if_clash)
|
4
|
+
* **Trableshouting**
|
5
|
+
* [RuntimeError](/trableshouting/runtime_error)
|
6
|
+
* **Usage**
|
7
|
+
* [Generate Docs](/usage/generate_docs)
|
8
|
+
* [Edit docs](/usage/edit_docs)
|
9
|
+
* [View docs](/usage/view_docs)
|
10
|
+
* [Monitor Docs](/usage/monitor_docs)
|
11
|
+
* [Analyze Docs](/usage/analyze_docs)
|
12
|
+
* [Use Hook to Generate Docs](/usage/use_hook_to_generate_docs)
|
13
|
+
* [Use schema namespace](/usage/use_schema_namespace)
|
14
|
+
* [Use tag namespace](/usage/use_tag_namespace)
|
15
|
+
* [Use hook methods](/usage/use_hook_methods)
|
16
|
+
* [Deploy docs](/usage/deploy_docs)
|
17
|
+
* [Clean Docs](/usage/clean_docs)
|
18
|
+
* [Display Paths Lists](/usage/display_paths_list)
|
19
|
+
* [Display Paths Stats](/usage/display_paths_stats)
|
20
|
+
* **Configure**
|
21
|
+
* [COC](/setting/COC)
|
22
|
+
* [Configure](/setting/configure)
|
23
|
+
* [CORS](/setting/CORS)
|
24
|
+
* **Support Schema**
|
25
|
+
* [3.0.0](/schema/3.0.0)
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# If clash
|
2
|
+
|
3
|
+
If you crash while Swagger Editor is running, you can execute the following command to reflect the editing status up to a few seconds before in the local file.
|
4
|
+
|
5
|
+
```bash
|
6
|
+
bundle exec rake routes:oas:analyze
|
7
|
+
```
|
8
|
+
|
9
|
+
It is a file generated by parsing the generated file oas_doc.yml and dividing it into each file.
|
10
|
+
|
11
|
+
## Attention
|
12
|
+
|
13
|
+
Please be aware that if you execute the following command immediately after the crash, the change history will be `lost`.
|
14
|
+
|
15
|
+
```bash
|
16
|
+
bundle exec rake routes:oas:editor
|
17
|
+
```
|
data/docs/index.html
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html lang="en">
|
3
|
+
<head>
|
4
|
+
<meta charset="UTF-8">
|
5
|
+
<title>Document</title>
|
6
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
|
7
|
+
<meta name="description" content="Description">
|
8
|
+
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
|
9
|
+
<link rel="stylesheet" href="//unpkg.com/docsify/lib/themes/vue.css">
|
10
|
+
</head>
|
11
|
+
<body>
|
12
|
+
<div id="app"></div>
|
13
|
+
<script>
|
14
|
+
window.$docsify = {
|
15
|
+
auto2top: true,
|
16
|
+
name: '<span>r2-oas</span>',
|
17
|
+
repo: 'https://github.com/yukihirop/r2-oas',
|
18
|
+
loadSidebar: true,
|
19
|
+
subMaxLevel: 2
|
20
|
+
}
|
21
|
+
</script>
|
22
|
+
<script src="//unpkg.com/docsify/lib/docsify.min.js"></script>
|
23
|
+
<script src="//unpkg.com/docsify/lib/plugins/search.min.js"></script>
|
24
|
+
<script src="//unpkg.com/docsify/lib/plugins/emoji.min.js"></script>
|
25
|
+
<script src="//cdn.jsdelivr.net/npm/prismjs/components/prism-ruby.min.js"></script>
|
26
|
+
<script src="//cdn.jsdelivr.net/npm/prismjs/components/prism-bash.min.js"></script>
|
27
|
+
<script src="//cdn.jsdelivr.net/npm/prismjs/components/prism-diff.min.js"></script>
|
28
|
+
</body>
|
29
|
+
</html>
|
data/docs/setting/COC.md
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# ❗️Convention over Configuration (CoC)
|
2
|
+
|
3
|
+
- `tag name` represents `controller name` and determine `paths file name`.
|
4
|
+
- For example, If `controller name` is `Api::V1::UsersController`, `tag_name` is `api/v1/user`. and `paths file name` is `api/v1/user.yml`
|
5
|
+
|
6
|
+
- `_` of `components/{schemas,requestBodies, ...} name` convert `/` when save file.
|
7
|
+
- For example, If `components/schemas name` is `Api_V1_User`, `components/schemas file name` is `api/v1/user.yml`.
|
8
|
+
- `_` is supposed to be used to express `namespace`.
|
9
|
+
- format is `Namespace1_Namespace2_Model`.
|
10
|
+
|
11
|
+
- `.` of `components/{schemas,requestBodies, ...} name` convert `/` when save file.
|
12
|
+
- For example, If `components/schemas name` is `api.v1.User`, `components/schemas file name` is `api/v1/user.yml`.
|
13
|
+
- `.` is supposed to be used to express `namespace`.
|
14
|
+
- format is `namespace1.namespace2.Model`.
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# CORS
|
2
|
+
|
3
|
+
Use [rack-cors](https://github.com/cyu/rack-cors) to enable CORS.
|
4
|
+
|
5
|
+
```ruby
|
6
|
+
require 'rack/cors'
|
7
|
+
use Rack::Cors do
|
8
|
+
allow do
|
9
|
+
origins '*'
|
10
|
+
resource '*', headers: :any, methods: [ :get, :post, :put, :delete, :options ]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
```
|
14
|
+
|
15
|
+
Alternatively you can set CORS headers in a `before` block.
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
before do
|
19
|
+
header['Access-Control-Allow-Origin'] = '*'
|
20
|
+
header['Access-Control-Request-Method'] = '*'
|
21
|
+
end
|
22
|
+
```
|
@@ -0,0 +1,176 @@
|
|
1
|
+
## Configure
|
2
|
+
|
3
|
+
All settings are `optional`. The initial value is as follows.
|
4
|
+
|
5
|
+
In your rails project, Write `config/environments/development.rb` like that:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
# default setting
|
9
|
+
R2OAS.configure do |config|
|
10
|
+
config.version = :v3
|
11
|
+
config.root_dir_path = "./oas_docs"
|
12
|
+
config.schema_save_dir_name = "src"
|
13
|
+
config.doc_save_file_name = "oas_doc.yml"
|
14
|
+
config.force_update_schema = false
|
15
|
+
config.use_tag_namespace = true
|
16
|
+
config.use_schema_namespace = false
|
17
|
+
config.interval_to_save_edited_tmp_schema = 15
|
18
|
+
# :dot or :underbar
|
19
|
+
config.namespace_type = :underbar
|
20
|
+
config.deploy_dir_path = "./deploy_docs"
|
21
|
+
|
22
|
+
config.server.data = [
|
23
|
+
{
|
24
|
+
url: "http://localhost:3000",
|
25
|
+
description: "localhost"
|
26
|
+
}
|
27
|
+
]
|
28
|
+
|
29
|
+
config.swagger.configure do |swagger|
|
30
|
+
swagger.ui.image = "swaggerapi/swagger-ui"
|
31
|
+
swagger.ui.port = "8080"
|
32
|
+
swagger.ui.exposed_port = "8080/tcp"
|
33
|
+
swagger.ui.volume = "/app/swagger.json"
|
34
|
+
swagger.editor.image = "swaggerapi/swagger-editor"
|
35
|
+
swagger.editor.port = "81"
|
36
|
+
swagger.editor.exposed_port = "8080/tcp"
|
37
|
+
end
|
38
|
+
|
39
|
+
config.use_object_classes = {
|
40
|
+
info_object: R2OAS::Schema::V3::InfoObject,
|
41
|
+
paths_object: R2OAS::Schema::V3::PathsObject,
|
42
|
+
path_item_object: R2OAS::Schema::V3::PathItemObject,
|
43
|
+
external_document_object: R2OAS::Schema::V3::ExternalDocumentObject,
|
44
|
+
components_object: R2OAS::Schema::V3::ComponentsObject,
|
45
|
+
components_schema_object: R2OAS::Schema::V3::Components::SchemaObject,
|
46
|
+
components_request_body_object: R2OAS::Schema::V3::Components::RequestBodyObject
|
47
|
+
}
|
48
|
+
|
49
|
+
config.http_statuses_when_http_method = {
|
50
|
+
get: {
|
51
|
+
default: %w(200 422),
|
52
|
+
path_parameter: %w(200 404 422)
|
53
|
+
},
|
54
|
+
post: {
|
55
|
+
default: %w(201 422),
|
56
|
+
path_parameter: %w(201 404 422)
|
57
|
+
},
|
58
|
+
patch: {
|
59
|
+
default: %w(204 422),
|
60
|
+
path_parameter: %w(204 404 422)
|
61
|
+
},
|
62
|
+
put: {
|
63
|
+
default: %w(204 422),
|
64
|
+
path_parameter: %w(204 404 422)
|
65
|
+
},
|
66
|
+
delete: {
|
67
|
+
default: %w(200 422),
|
68
|
+
path_parameter: %w(200 404 422)
|
69
|
+
}
|
70
|
+
}
|
71
|
+
|
72
|
+
config.http_methods_when_generate_request_body = %w[post patch put]
|
73
|
+
config.ignored_http_statuses_when_generate_component_schema = %w[204 404]
|
74
|
+
|
75
|
+
config.tool.paths_stats.configure do |paths_stats|
|
76
|
+
paths_stats.month_to_turn_to_warning_color = 3
|
77
|
+
paths_stats.warning_color = :red
|
78
|
+
paths_stats.table_title_color = :yellow
|
79
|
+
paths_stats.heading_color = :yellow
|
80
|
+
paths_stats.highlight_color = :magenta
|
81
|
+
end
|
82
|
+
end
|
83
|
+
```
|
84
|
+
|
85
|
+
we explain the options that can be set.
|
86
|
+
|
87
|
+
#### basic
|
88
|
+
|
89
|
+
|option|description|default|
|
90
|
+
|------|-----------|---|
|
91
|
+
|version|OpenAPI schema version| `:v3` |
|
92
|
+
|root_dir_path|Root directory for storing products.| `"./oas_docs"` |
|
93
|
+
|schema_save_dir_name|Directory name for storing swagger schemas|`"src"`|
|
94
|
+
|doc_save_file_name|File name for storing swagger doc|`"oas_doc.yml"`|
|
95
|
+
|force_update_schema|Force update schema from routes data|`false`|
|
96
|
+
|use_tag_namespace|Use namespace for tag name|`true`|
|
97
|
+
|use_schema_namespace|Use namespace for schema name|`true`|
|
98
|
+
|interval_to_save_edited_tmp_schema|Interval(sec) to save edited tmp schema|`15`|
|
99
|
+
|http_statuses_when_http_method|Determine the response to support for each HTTP method|omission...|
|
100
|
+
|http_methods_when_generate_request_body|HTTP methods when generate requestBody|`[post put patch]`|
|
101
|
+
|ignored_http_statuses_when_generate_component_schema|Ignore HTTP statuses when generate component schema|`[204 404]`|
|
102
|
+
|namespace_type|namespace for components(schemas/requestBodies) name| `underbar` |
|
103
|
+
|deploy_dir_path|deploy directory.|`"./deploy_docs"`|
|
104
|
+
|
105
|
+
#### server
|
106
|
+
|
107
|
+
|option|children option|description|default|
|
108
|
+
|------|---------------|-----------|-------|
|
109
|
+
|server|data|Server data (url, description) |[{ url: `http://localhost:3000`, description: `localhost` }] |
|
110
|
+
|
111
|
+
#### swagger
|
112
|
+
|
113
|
+
|option|children option|grandchild option|description|default|
|
114
|
+
|------|---------------|-----------------|-----------|-------|
|
115
|
+
|swagger|ui|image|Swagger UI Docker Image|`"swaggerapi/swagger-ui"`|
|
116
|
+
|swagger|ui|port|Swagger UI Port|`"8080"`|
|
117
|
+
|swagger|ui|exposed_port|Swagger UI Exposed Port|`"8080/tcp"`|
|
118
|
+
|swagger|ui|volume|Swagger UI Volume|`"/app/swagger.json"`|
|
119
|
+
|swagger|editor|image|Swagger Editor Docker Image|`"swaggerapi/swagger-editor"`|
|
120
|
+
|swagger|editor|port|Swagger Editor Port|`"8080"`|
|
121
|
+
|swagger|editor|exposed_port|Swagger Editor Exposed Port|`"8080/tcp"`|
|
122
|
+
|
123
|
+
#### hook
|
124
|
+
|
125
|
+
|option|description|default|
|
126
|
+
|------|-----------|-------|
|
127
|
+
|use_object_classes|Object class(hook class) to generate Openapi document|{ info_object: `R2OAS::Schema::V3::InfoObject`,<br>paths_object: `R2OAS::Schema::V3::PathsObject`,<br>path_item_object: `R2OAS::Schema::V3::PathItemObject`, external_document_object: `R2OAS::Schema::V3::ExternalDocumentObject`,<br> components_object: `R2OAS::Schema::V3::ComponentsObject`,<br> components_schema_object: `R2OAS::Schema::V3::Components::SchemaObject`, <br> components_request_body_object:`R2OAS::Schema::V3::Components::RequestBodyObject` }|
|
128
|
+
|
129
|
+
#### tool
|
130
|
+
|
131
|
+
|option|children option|grandchild option|description|default|
|
132
|
+
|------|---------------|-----------------|-----------|-------|
|
133
|
+
|tool|paths_stats|month_to_turn_to_warning_color|Elapsed month to issue a warning|`3`|
|
134
|
+
|tool|paths_stats|warning_color|Warning Color|`:red`|
|
135
|
+
|tool|paths_stats|table_title_color|Table Title Color|`:yellow`|
|
136
|
+
|tool|paths_stats|heading_color|Heading Color|`:yellow`|
|
137
|
+
|tool|paths_stats|highlight_color|Highlight Color|`:magenta`|
|
138
|
+
|
139
|
+
Please refer to [here](https://github.com/janlelis/paint) for the color.
|
140
|
+
|
141
|
+
## Environment variables
|
142
|
+
|
143
|
+
We explain the environment variables that can be set.
|
144
|
+
|
145
|
+
|variable|description|default|
|
146
|
+
|--------|-----------|-------|
|
147
|
+
|PATHS_FILE|Specify one paths file path|`""`|
|
148
|
+
|OAS_FILE|Specify swagger file path to analyze|`""`|
|
149
|
+
|CACHE_DOCS|Effective only when there is no `.docs` file. Specifying `true` will generate a` .docs` file when the `routes:oas:docs` command is executed.|`false`|
|
150
|
+
|
151
|
+
|
152
|
+
## .paths
|
153
|
+
|
154
|
+
Writing file paths in .paths will only read them.
|
155
|
+
You can comment out with `#`
|
156
|
+
|
157
|
+
`oas_docs/.paths`
|
158
|
+
|
159
|
+
```
|
160
|
+
#account_user_role.yml # ignore
|
161
|
+
account.yml
|
162
|
+
account.yml # ignore
|
163
|
+
account.yml # ignore
|
164
|
+
```
|
165
|
+
|
166
|
+
## .docs
|
167
|
+
|
168
|
+
It holds the information in the current routing as a cache. Thanks to this, when the `routes:oas:docs` command is executed, changes in routing can be detected and appropriate processing can be performed.
|
169
|
+
|
170
|
+
If you want to inspect `.docs`. You can check it by entering the following code with `pry` or something.
|
171
|
+
|
172
|
+
```ruby
|
173
|
+
result = IO.binread("oas_docs/.docs")
|
174
|
+
inflate = Zlib::Inflate.inflate(result)
|
175
|
+
puts Marshal.load(inflate)
|
176
|
+
```
|