swagger_api 0.1.43
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 +7 -0
- data/.codeclimate.yml +20 -0
- data/.gitignore +13 -0
- data/.gitlab-ci.yml +61 -0
- data/.rspec +3 -0
- data/.ruby-version +1 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +155 -0
- data/LICENSE.txt +21 -0
- data/README.md +45 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/swagger_api.rb +123 -0
- data/lib/swagger_api/actions.rb +43 -0
- data/lib/swagger_api/column_schema.rb +41 -0
- data/lib/swagger_api/component_schema.rb +50 -0
- data/lib/swagger_api/components.rb +24 -0
- data/lib/swagger_api/concerns/columns.rb +24 -0
- data/lib/swagger_api/operations/base.rb +86 -0
- data/lib/swagger_api/operations/create.rb +39 -0
- data/lib/swagger_api/operations/delete.rb +20 -0
- data/lib/swagger_api/operations/index.rb +50 -0
- data/lib/swagger_api/operations/show.rb +11 -0
- data/lib/swagger_api/operations/update.rb +32 -0
- data/lib/swagger_api/paths.rb +52 -0
- data/lib/swagger_api/railtie.rb +6 -0
- data/lib/swagger_api/request_bodies.rb +28 -0
- data/lib/swagger_api/tasks/swagger.rake +13 -0
- data/lib/swagger_api/version.rb +3 -0
- data/swagger.yml +46 -0
- data/swagger_api.gemspec +38 -0
- metadata +162 -0
@@ -0,0 +1,20 @@
|
|
1
|
+
module SwaggerApi
|
2
|
+
module Operations
|
3
|
+
class Delete < Base
|
4
|
+
def success_response
|
5
|
+
{
|
6
|
+
'204' => {
|
7
|
+
description: "#{readable_action} #{model_name.downcase}'s information",
|
8
|
+
}
|
9
|
+
}
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
def error_responses
|
14
|
+
super.reject do |error_response|
|
15
|
+
%w(422).include?(error_response.keys.first)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module SwaggerApi
|
2
|
+
module Operations
|
3
|
+
class Index < Base
|
4
|
+
def headers
|
5
|
+
{
|
6
|
+
'x-total' => {
|
7
|
+
schema: {
|
8
|
+
type: :integer
|
9
|
+
},
|
10
|
+
description: 'total results available',
|
11
|
+
},
|
12
|
+
'x-link-next' => {
|
13
|
+
schema: {
|
14
|
+
type: :string
|
15
|
+
},
|
16
|
+
description: 'uri for next page of results',
|
17
|
+
},
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
def parameters
|
22
|
+
columns.map do |column|
|
23
|
+
{
|
24
|
+
name: column.name,
|
25
|
+
in: 'query',
|
26
|
+
required: false,
|
27
|
+
description: "#{column.name} of #{model.name}",
|
28
|
+
schema: SwaggerApi::ColumnSchema.new(column: column).create,
|
29
|
+
}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def success_response
|
34
|
+
success = super
|
35
|
+
success['200'][:headers] = headers
|
36
|
+
success
|
37
|
+
end
|
38
|
+
|
39
|
+
def readable_action
|
40
|
+
'list'
|
41
|
+
end
|
42
|
+
|
43
|
+
def error_responses
|
44
|
+
super.reject do |error_response|
|
45
|
+
%w(404 422).include?(error_response.keys.first)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module SwaggerApi
|
2
|
+
module Operations
|
3
|
+
class Update < Base
|
4
|
+
def create
|
5
|
+
create = super
|
6
|
+
create[:requestBody] = request_body
|
7
|
+
create
|
8
|
+
end
|
9
|
+
|
10
|
+
def request_body
|
11
|
+
{
|
12
|
+
"$ref" => "#/components/requestBodies/#{model_name}"
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
def success_response
|
17
|
+
{
|
18
|
+
'303' => {
|
19
|
+
description: "#{readable_action} #{model_name.downcase}'s information",
|
20
|
+
headers: {
|
21
|
+
Location: {
|
22
|
+
schema: {
|
23
|
+
type: :string
|
24
|
+
}
|
25
|
+
}
|
26
|
+
}
|
27
|
+
}
|
28
|
+
}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module SwaggerApi
|
2
|
+
class Paths
|
3
|
+
include ActiveAttr::Model
|
4
|
+
attr_accessor :controllers
|
5
|
+
|
6
|
+
def create
|
7
|
+
return @paths unless @paths.nil?
|
8
|
+
@paths = {}
|
9
|
+
controllers.each do |controller|
|
10
|
+
if controller.custom_path_file.nil?
|
11
|
+
@paths.merge!(paths(controller))
|
12
|
+
else
|
13
|
+
@paths.merge!(custom_json(controller))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
@paths
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def paths(controller)
|
22
|
+
paths = {}
|
23
|
+
paths["#{route(controller)}"] = {}
|
24
|
+
paths["#{route(controller)}{id}/"] = {}
|
25
|
+
paths["#{route(controller)}"][:get] = SwaggerApi::Operations::Index.new(controller: controller).create if action?(controller, 'index')
|
26
|
+
paths["#{route(controller)}"][:post] = SwaggerApi::Operations::Create.new(controller: controller).create if action?(controller, 'create')
|
27
|
+
paths["#{route(controller)}{id}/"][:get] = SwaggerApi::Operations::Show.new(controller: controller).create if action?(controller, 'show')
|
28
|
+
paths["#{route(controller)}{id}/"][:put] = SwaggerApi::Operations::Update.new(controller: controller).create if action?(controller, 'update')
|
29
|
+
paths["#{route(controller)}{id}/"][:delete] = SwaggerApi::Operations::Delete.new(controller: controller).create if action?(controller, 'delete')
|
30
|
+
paths["#{route(controller)}"].delete if paths["#{route(controller)}"].blank?
|
31
|
+
paths["#{route(controller)}{id}/"].delete if paths["#{route(controller)}{id}/"].blank?
|
32
|
+
paths
|
33
|
+
end
|
34
|
+
|
35
|
+
def route(controller)
|
36
|
+
"/#{controller.name.demodulize.underscore.gsub('_controller', '')}/"
|
37
|
+
end
|
38
|
+
|
39
|
+
def custom_json(controller)
|
40
|
+
file = File.read(controller.custom_path_file)
|
41
|
+
JSON.parse(file)
|
42
|
+
end
|
43
|
+
|
44
|
+
def actions(controller)
|
45
|
+
SwaggerApi::Actions.new(controller: controller).all!
|
46
|
+
end
|
47
|
+
|
48
|
+
def action?(controller, action_name)
|
49
|
+
actions(controller).include?(action_name)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module SwaggerApi
|
2
|
+
class RequestBodies
|
3
|
+
include ActiveAttr::Model
|
4
|
+
attr_accessor :controllers
|
5
|
+
|
6
|
+
def create
|
7
|
+
request_bodies = {}
|
8
|
+
controllers.each do |controller|
|
9
|
+
request_bodies[controller.model] = request_body(controller)
|
10
|
+
end
|
11
|
+
request_bodies
|
12
|
+
end
|
13
|
+
|
14
|
+
def request_body(controller)
|
15
|
+
{
|
16
|
+
content: {
|
17
|
+
'application/json' => {
|
18
|
+
schema: {
|
19
|
+
'$ref' => "#/components/schemas/#{controller.model}"
|
20
|
+
}
|
21
|
+
}
|
22
|
+
},
|
23
|
+
description: "audience attribute",
|
24
|
+
required: true
|
25
|
+
}
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
|
2
|
+
namespace :swagger do
|
3
|
+
desc 'Create a local version of the swagger api json file'
|
4
|
+
task swagger_api: [:environment] do
|
5
|
+
generator = SwaggerApi::Generator.new
|
6
|
+
File.open('api.yml', 'w+') do |file|
|
7
|
+
file.write(YAML.dump(JSON.parse(generator.json)))
|
8
|
+
end
|
9
|
+
File.open('api.json', 'w+') do |file|
|
10
|
+
file.write(generator.prettify)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/swagger.yml
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
info:
|
2
|
+
version: 1.0.0-oas
|
3
|
+
title: FME Integrations
|
4
|
+
description: Student basic information and audiences
|
5
|
+
servers:
|
6
|
+
cm_production:
|
7
|
+
url: https://cm.fullmeasureed.com/api/webservices
|
8
|
+
cm_stage:
|
9
|
+
url: https://cm.stage.fullmeasureed.com/api/webservices
|
10
|
+
iwu_production:
|
11
|
+
url: https://iwu.fullmeasureed.com/api/webservices
|
12
|
+
iwu_stage:
|
13
|
+
url: https://iwu.stage.fullmeasureed.com/api/webservices
|
14
|
+
development:
|
15
|
+
url: https://localhost:3000/api/webservices
|
16
|
+
controllers:
|
17
|
+
- name: Api::WebServices::StudentsController
|
18
|
+
model: Student
|
19
|
+
columns:
|
20
|
+
only:
|
21
|
+
- id
|
22
|
+
- first_name
|
23
|
+
- last_name
|
24
|
+
- email
|
25
|
+
- mobile_phone_number
|
26
|
+
- external_student_id
|
27
|
+
- type
|
28
|
+
|
29
|
+
required:
|
30
|
+
- id
|
31
|
+
- first_name
|
32
|
+
- last_name
|
33
|
+
- email
|
34
|
+
- mobile_phone_number
|
35
|
+
- external_student_id
|
36
|
+
- type
|
37
|
+
|
38
|
+
- name: Api::WebServices::AudiencesController
|
39
|
+
model: Audience
|
40
|
+
|
41
|
+
- name: Api::WebServices::AudienceStudentsController
|
42
|
+
actions:
|
43
|
+
except:
|
44
|
+
- update
|
45
|
+
model: AudienceStudent
|
46
|
+
|
data/swagger_api.gemspec
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'swagger_api/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'swagger_api'
|
7
|
+
spec.version = SwaggerApi::VERSION
|
8
|
+
spec.authors = ['Full Measure Education']
|
9
|
+
spec.email = ['devops@fullmeasureed.com']
|
10
|
+
|
11
|
+
spec.summary = %q{A simple library for autocreating RESTful swagger api docs from Rails controllers.}
|
12
|
+
spec.description = %q{A simple library for autocreating RESTful swagger api docs from Rails controllers.}
|
13
|
+
spec.homepage = 'https://gitlab.com/fullmeasure/public/swagger-api/swagger_api'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
20
|
+
else
|
21
|
+
raise 'RubyGems 2.0 or newer is required to protect against ' \
|
22
|
+
'public gem pushes.'
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
26
|
+
f.match(%r{^(test|spec|features)/})
|
27
|
+
end
|
28
|
+
spec.bindir = 'exe'
|
29
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ['lib']
|
31
|
+
|
32
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
33
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
34
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
35
|
+
spec.add_dependency 'rails', '>= 5.0'
|
36
|
+
spec.add_dependency 'active_attr'
|
37
|
+
spec.add_dependency 'rspec-rails'
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,162 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: swagger_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.43
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Full Measure Education
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-04-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rails
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '5.0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '5.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: active_attr
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec-rails
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: A simple library for autocreating RESTful swagger api docs from Rails
|
98
|
+
controllers.
|
99
|
+
email:
|
100
|
+
- devops@fullmeasureed.com
|
101
|
+
executables: []
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".codeclimate.yml"
|
106
|
+
- ".gitignore"
|
107
|
+
- ".gitlab-ci.yml"
|
108
|
+
- ".rspec"
|
109
|
+
- ".ruby-version"
|
110
|
+
- CODE_OF_CONDUCT.md
|
111
|
+
- Gemfile
|
112
|
+
- Gemfile.lock
|
113
|
+
- LICENSE.txt
|
114
|
+
- README.md
|
115
|
+
- Rakefile
|
116
|
+
- bin/console
|
117
|
+
- bin/setup
|
118
|
+
- lib/swagger_api.rb
|
119
|
+
- lib/swagger_api/actions.rb
|
120
|
+
- lib/swagger_api/column_schema.rb
|
121
|
+
- lib/swagger_api/component_schema.rb
|
122
|
+
- lib/swagger_api/components.rb
|
123
|
+
- lib/swagger_api/concerns/columns.rb
|
124
|
+
- lib/swagger_api/operations/base.rb
|
125
|
+
- lib/swagger_api/operations/create.rb
|
126
|
+
- lib/swagger_api/operations/delete.rb
|
127
|
+
- lib/swagger_api/operations/index.rb
|
128
|
+
- lib/swagger_api/operations/show.rb
|
129
|
+
- lib/swagger_api/operations/update.rb
|
130
|
+
- lib/swagger_api/paths.rb
|
131
|
+
- lib/swagger_api/railtie.rb
|
132
|
+
- lib/swagger_api/request_bodies.rb
|
133
|
+
- lib/swagger_api/tasks/swagger.rake
|
134
|
+
- lib/swagger_api/version.rb
|
135
|
+
- swagger.yml
|
136
|
+
- swagger_api.gemspec
|
137
|
+
homepage: https://gitlab.com/fullmeasure/public/swagger-api/swagger_api
|
138
|
+
licenses:
|
139
|
+
- MIT
|
140
|
+
metadata:
|
141
|
+
allowed_push_host: https://rubygems.org
|
142
|
+
post_install_message:
|
143
|
+
rdoc_options: []
|
144
|
+
require_paths:
|
145
|
+
- lib
|
146
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
147
|
+
requirements:
|
148
|
+
- - ">="
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: '0'
|
151
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
152
|
+
requirements:
|
153
|
+
- - ">="
|
154
|
+
- !ruby/object:Gem::Version
|
155
|
+
version: '0'
|
156
|
+
requirements: []
|
157
|
+
rubyforge_project:
|
158
|
+
rubygems_version: 2.6.14
|
159
|
+
signing_key:
|
160
|
+
specification_version: 4
|
161
|
+
summary: A simple library for autocreating RESTful swagger api docs from Rails controllers.
|
162
|
+
test_files: []
|