swagger_codegen_rails 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/README.md +17 -6
- data/lib/generators/swagger/add/add_generator.rb +9 -0
- data/lib/generators/swagger/add/templates/_swagger.rb.tt +4 -4
- data/lib/generators/swagger/install/install_generator.rb +0 -6
- data/lib/swagger_codegen_rails/base.rb +2 -10
- data/lib/swagger_codegen_rails/defaults.rb +0 -1
- data/lib/swagger_codegen_rails/konstants.rb +3 -3
- data/lib/swagger_codegen_rails/parameter.rb +2 -2
- data/lib/swagger_codegen_rails/version.rb +2 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c23da6493e46a0fe783c81597ad8e0bffa605f7e5f133b6a701458730be9e4eb
|
4
|
+
data.tar.gz: f6da5bc77b6132383338a571f7720b82d74fd0f3f0e2b0c181978e295afa0bb2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b7aaab84299f12322d83dd0a2a0290d7e4b8341539e823b435f10b2ea8f8b4ccc91120b37081166431fedcfcfb7b205e8087e8072deb4a98054d03b575453db
|
7
|
+
data.tar.gz: 7670e9e0bf2b886a3c0ac19c66bdf182921a7b4ab04470c42f82798110370f679b3d3d922a85bb27259c6f3607fea2127c1f9f79f62fb606ff42d7710aa28aef
|
data/README.md
CHANGED
@@ -29,7 +29,7 @@ $ gem install swagger_codegen_rails
|
|
29
29
|
```bash
|
30
30
|
$ rails g swagger:install
|
31
31
|
$ rails g swagger:init /api/v1
|
32
|
-
$ rails g swagger:add /api/v1 /api/v1/user/:id id:path:integer:true
|
32
|
+
$ rails g swagger:add /api/v1 get /api/v1/user/:id id:path:integer:true
|
33
33
|
```
|
34
34
|
|
35
35
|
### Create intializer file
|
@@ -42,8 +42,6 @@ $ rails g swagger:install
|
|
42
42
|
# config/initializers/swagger_codegen_rails.rb
|
43
43
|
|
44
44
|
SwaggerCodegenRails.configure do |config|
|
45
|
-
config.versioned = false # boolean
|
46
|
-
|
47
45
|
config.versions_url = {
|
48
46
|
v1: 'api/v1',
|
49
47
|
v2: 'api/v2'
|
@@ -61,7 +59,6 @@ Options:
|
|
61
59
|
|
62
60
|
|configurations|type|default|description|
|
63
61
|
|:------|:----|:-|:-------------------------|
|
64
|
-
|config.versioned|boolean|false|set path of versioned API documentations|
|
65
62
|
config.versions_url|hash|EMPTY|define versioned path|
|
66
63
|
|config.concern_dir|string|/app/controllers/concern|set root path of endpoint documentations|
|
67
64
|
|config.schema_dir|string|/app/models/concern|set root path of response schema documentations|
|
@@ -76,9 +73,8 @@ $ rails g swagger:init NAMESPACE
|
|
76
73
|
```bash
|
77
74
|
$ rails g swagger:add NAMESPACE HTTP_METHOD URI [PARAMETERS; name:in:type:required]
|
78
75
|
$ # If you do NOT want namespace, example below
|
79
|
-
$ rails g swagger:add .
|
76
|
+
$ rails g swagger:add . get /users id:path:integer:true
|
80
77
|
```
|
81
|
-
|
82
78
|
Parameters:
|
83
79
|
|
84
80
|
||description|
|
@@ -89,6 +85,21 @@ Parameters:
|
|
89
85
|
|required|required|
|
90
86
|
|
91
87
|
|
88
|
+
### To show SwaggerUI
|
89
|
+
Add these lines in your config/application.rb (If you won't create versioned API, it is no needed.)
|
90
|
+
```Ruby
|
91
|
+
# config/application.rb
|
92
|
+
config.paths.add "#{config.root}/app/controllers/**/*", glob: "**/*", eager_load: true
|
93
|
+
```
|
94
|
+
|
95
|
+
Then start your server with rails command
|
96
|
+
```bash
|
97
|
+
$ rails s
|
98
|
+
```
|
99
|
+
And access ``http://localhost:3000/swagger`` in browser.
|
100
|
+
|
101
|
+
|
102
|
+
|
92
103
|
## Contributing
|
93
104
|
1. Fork it ( https://github.com/technobrain/swagger_codegen_rails )
|
94
105
|
2. Create your feature branch (git checkout -b my-new-feature)
|
@@ -21,10 +21,19 @@ module Swagger
|
|
21
21
|
end
|
22
22
|
|
23
23
|
private
|
24
|
+
|
24
25
|
def module_name
|
25
26
|
swagger_file_name.camelize
|
26
27
|
end
|
27
28
|
|
29
|
+
def full_uri
|
30
|
+
if uri.sub(/\A\//, "").start_with?(namespace)
|
31
|
+
'/' + uri.sub(/\A\//, "")
|
32
|
+
else
|
33
|
+
'/' + namespace + '/' + uri.sub(/\A\//, "")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
28
37
|
def namespace
|
29
38
|
config = SwaggerCodegenRails.configuration.versions_url
|
30
39
|
config ? (config[name.to_sym] || name) : name
|
@@ -6,12 +6,12 @@ module <%= module_name %>
|
|
6
6
|
include_swagger '<%= swagger_schema_dir -%>', type: :model
|
7
7
|
|
8
8
|
included do
|
9
|
-
swagger_path '<%=
|
9
|
+
swagger_path '<%= full_uri -%>' do
|
10
10
|
operation :<%= http_method.downcase -%> do
|
11
11
|
key :description, "TODO: describe endpoint here"
|
12
12
|
key :operationId, "TODO: "
|
13
13
|
key :produces, [
|
14
|
-
'application/
|
14
|
+
'application/json',
|
15
15
|
]
|
16
16
|
key :tags, [
|
17
17
|
# A list of tags used by the specification with additional metadata.
|
@@ -33,14 +33,14 @@ module <%= module_name %>
|
|
33
33
|
# key :'$ref', TODO:
|
34
34
|
end
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
response 404 do
|
38
38
|
key :description, "TODO: "
|
39
39
|
schema do
|
40
40
|
# key :'$ref', TODO:
|
41
41
|
end
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
response 501 do
|
45
45
|
key :description, "TODO: "
|
46
46
|
schema do
|
@@ -1,19 +1,11 @@
|
|
1
1
|
module SwaggerCodegenRails
|
2
2
|
module Base
|
3
3
|
def concern_dir
|
4
|
-
|
5
|
-
end
|
6
|
-
|
7
|
-
def concerns
|
8
|
-
Proc.new { SwaggerCodegenRails.configuration.concern_dir }
|
4
|
+
SwaggerCodegenRails.configuration.concern_dir
|
9
5
|
end
|
10
6
|
|
11
7
|
def schema_dir
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
def schemas
|
16
|
-
Proc.new { SwaggerCodegenRails.configuration.schema_dir }
|
8
|
+
SwaggerCodegenRails.configuration.schema_dir
|
17
9
|
end
|
18
10
|
end
|
19
11
|
end
|
@@ -45,8 +45,9 @@ module SwaggerCodegenRails
|
|
45
45
|
# => hoge/foo/bar
|
46
46
|
# ------------
|
47
47
|
def reduct(source, reduction)
|
48
|
-
File.join(File.dirname(source.sub(reduction, '')),
|
49
|
-
|
48
|
+
File.join(File.dirname(source.sub(reduction, '')),
|
49
|
+
File.basename(source,
|
50
|
+
File.extname(source))).sub(/\A\//,'')
|
50
51
|
end
|
51
52
|
|
52
53
|
# ------------
|
@@ -56,7 +57,6 @@ module SwaggerCodegenRails
|
|
56
57
|
def constant(str)
|
57
58
|
str.split("/").map(&:camelize).join("::").constantize
|
58
59
|
end
|
59
|
-
|
60
60
|
end
|
61
61
|
end
|
62
62
|
end
|
@@ -10,8 +10,8 @@ module SwaggerCodegenRails
|
|
10
10
|
self[i] = params[i].blank? ? "TODO" : params[i]
|
11
11
|
end
|
12
12
|
rescue IndexError => e
|
13
|
-
logger.error e
|
14
|
-
logger.error e.backtrace.join("\n")
|
13
|
+
Rails.logger.error e
|
14
|
+
Rails.logger.error e.backtrace.join("\n")
|
15
15
|
return nil
|
16
16
|
end
|
17
17
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: swagger_codegen_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Akifumi Tomiyama
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-
|
12
|
+
date: 2018-04-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -158,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
158
158
|
version: '0'
|
159
159
|
requirements: []
|
160
160
|
rubyforge_project:
|
161
|
-
rubygems_version: 2.
|
161
|
+
rubygems_version: 2.7.3
|
162
162
|
signing_key:
|
163
163
|
specification_version: 4
|
164
164
|
summary: Generator for swagger-blocks and swagger_ui_engine
|