swagger_api 0.1.48 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +10 -5
- data/.gitignore +2 -1
- data/.gitlab-ci.yml +25 -21
- data/.rubocop.yml +1837 -0
- data/Gemfile +16 -4
- data/Gemfile.lock +40 -0
- data/Rakefile +4 -2
- data/lib/swagger_api/actions.rb +11 -11
- data/lib/swagger_api/column_schema.rb +26 -15
- data/lib/swagger_api/component_schema.rb +7 -3
- data/lib/swagger_api/components.rb +10 -4
- data/lib/swagger_api/concerns/columns.rb +14 -3
- data/lib/swagger_api/concerns/sti_schema.rb +6 -4
- data/lib/swagger_api/operations/base.rb +5 -3
- data/lib/swagger_api/operations/create.rb +4 -2
- data/lib/swagger_api/operations/delete.rb +5 -4
- data/lib/swagger_api/operations/index.rb +8 -6
- data/lib/swagger_api/operations/show.rb +3 -1
- data/lib/swagger_api/operations/update.rb +3 -1
- data/lib/swagger_api/paths.rb +31 -5
- data/lib/swagger_api/railtie.rb +11 -4
- data/lib/swagger_api/request_bodies.rb +3 -1
- data/lib/swagger_api/tasks/swagger.rake +2 -1
- data/lib/swagger_api/version.rb +3 -1
- data/lib/swagger_api.rb +36 -22
- data/swagger_api.gemspec +5 -4
- metadata +2 -1
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module SwaggerApi
|
2
4
|
module Operations
|
3
5
|
class Show < Base
|
4
6
|
def error_responses
|
5
7
|
super.reject do |error_response|
|
6
|
-
%w
|
8
|
+
%w[422].include?(error_response.keys.first)
|
7
9
|
end
|
8
10
|
end
|
9
11
|
end
|
data/lib/swagger_api/paths.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module SwaggerApi
|
2
4
|
class Paths
|
3
5
|
include ActiveAttr::Model
|
@@ -20,16 +22,40 @@ module SwaggerApi
|
|
20
22
|
|
21
23
|
def paths(controller)
|
22
24
|
paths = {}
|
23
|
-
paths[
|
25
|
+
paths[route(controller)] = {}
|
24
26
|
paths["#{route(controller)}{id}/"] = {}
|
25
|
-
paths
|
26
|
-
paths
|
27
|
+
collection_paths(paths, controller)
|
28
|
+
member_paths(paths, controller)
|
29
|
+
paths
|
30
|
+
end
|
31
|
+
|
32
|
+
def collection_paths(paths, controller)
|
33
|
+
paths[route(controller)][:get] = SwaggerApi::Operations::Index.new(controller: controller).create if action?(controller, 'index')
|
34
|
+
paths[route(controller)][:post] = SwaggerApi::Operations::Create.new(controller: controller).create if action?(controller, 'create')
|
35
|
+
end
|
36
|
+
|
37
|
+
def member_paths(paths, controller)
|
38
|
+
show_path(paths, controller)
|
39
|
+
update_path(paths, controller)
|
40
|
+
delete_path(paths, controller)
|
41
|
+
clean_out_delete_path(paths, controller)
|
42
|
+
end
|
43
|
+
|
44
|
+
def show_path(paths, controller)
|
27
45
|
paths["#{route(controller)}{id}/"][:get] = SwaggerApi::Operations::Show.new(controller: controller).create if action?(controller, 'show')
|
46
|
+
end
|
47
|
+
|
48
|
+
def update_path(paths, controller)
|
28
49
|
paths["#{route(controller)}{id}/"][:put] = SwaggerApi::Operations::Update.new(controller: controller).create if action?(controller, 'update')
|
50
|
+
end
|
51
|
+
|
52
|
+
def delete_path(paths, controller)
|
29
53
|
paths["#{route(controller)}{id}/"][:delete] = SwaggerApi::Operations::Delete.new(controller: controller).create if action?(controller, 'delete')
|
30
|
-
|
54
|
+
end
|
55
|
+
|
56
|
+
def clean_out_delete_path(paths, controller)
|
57
|
+
paths[route(controller)].delete if paths[route(controller)].blank?
|
31
58
|
paths["#{route(controller)}{id}/"].delete if paths["#{route(controller)}{id}/"].blank?
|
32
|
-
paths
|
33
59
|
end
|
34
60
|
|
35
61
|
def route(controller)
|
data/lib/swagger_api/railtie.rb
CHANGED
@@ -1,6 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rails'
|
2
|
-
|
3
|
-
|
4
|
-
|
4
|
+
|
5
|
+
#:nocov:#
|
6
|
+
module SwaggerApi
|
7
|
+
class Railtie < Rails::Railtie
|
8
|
+
rake_tasks do
|
9
|
+
load 'swagger_api/tasks/swagger.rake'
|
10
|
+
end
|
5
11
|
end
|
6
|
-
end
|
12
|
+
end
|
13
|
+
#:nocov:#
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module SwaggerApi
|
2
4
|
class RequestBodies
|
3
5
|
include ActiveAttr::Model
|
@@ -17,7 +19,7 @@ module SwaggerApi
|
|
17
19
|
{
|
18
20
|
content: {
|
19
21
|
'application/json' => {
|
20
|
-
schema: schema(controller.model.safe_constantize || controller.model)
|
22
|
+
schema: schema(controller.model.try(:safe_constantize) || controller.model)
|
21
23
|
}
|
22
24
|
},
|
23
25
|
description: "#{controller.model} attribute",
|
data/lib/swagger_api/version.rb
CHANGED
data/lib/swagger_api.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'swagger_api/version'
|
2
4
|
require 'rails'
|
3
5
|
|
@@ -14,21 +16,25 @@ module SwaggerApi
|
|
14
16
|
def create
|
15
17
|
@config ||= {
|
16
18
|
openapi: '3.0.0',
|
17
|
-
security: [{api_key: []}],
|
19
|
+
security: [{ api_key: [] }],
|
18
20
|
info: info,
|
19
|
-
servers: [{url: server_url}],
|
21
|
+
servers: [{ url: server_url }],
|
20
22
|
paths: Paths.new(controllers: config.controllers).create,
|
21
|
-
components:
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
23
|
+
components: components
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
def components
|
28
|
+
{
|
29
|
+
responses: responses,
|
30
|
+
schemas: Components.new(controllers: config.controllers).create,
|
31
|
+
requestBodies: RequestBodies.new(controllers: config.controllers).create,
|
32
|
+
securitySchemes: security_schemes
|
27
33
|
}
|
28
34
|
end
|
29
35
|
|
30
36
|
def config
|
31
|
-
@yaml_config ||= JSON.parse(YAML.load_file("#{Rails.root
|
37
|
+
@yaml_config ||= JSON.parse(YAML.load_file("#{Rails.root}/config/swagger.yml").to_json, object_class: OpenStruct)
|
32
38
|
end
|
33
39
|
|
34
40
|
def security_schemes
|
@@ -42,19 +48,17 @@ module SwaggerApi
|
|
42
48
|
end
|
43
49
|
|
44
50
|
def responses
|
45
|
-
@responses ||=
|
51
|
+
@responses ||= default_responses
|
46
52
|
end
|
47
53
|
|
48
|
-
def
|
49
|
-
|
50
|
-
return unless File.exist?(custom_responses_path)
|
51
|
-
@custom_responses ||= JSON.parse(File.read(custom_responses_path), object_class: OpenStruct)
|
54
|
+
def default_responses
|
55
|
+
{}.merge(default_not_found_response).merge(default_unauthorized_response).merge(default_bad_request_response)
|
52
56
|
end
|
53
57
|
|
54
|
-
def
|
58
|
+
def default_not_found_response
|
55
59
|
{
|
56
60
|
NotFound: {
|
57
|
-
description:
|
61
|
+
description: 'The specified resource was not found',
|
58
62
|
content: {
|
59
63
|
'application/json; charset=utf-8' => {
|
60
64
|
schema: {
|
@@ -63,9 +67,14 @@ module SwaggerApi
|
|
63
67
|
}
|
64
68
|
}
|
65
69
|
}
|
66
|
-
}
|
70
|
+
}
|
71
|
+
}
|
72
|
+
end
|
73
|
+
|
74
|
+
def default_unauthorized_response
|
75
|
+
{
|
67
76
|
Unauthorized: {
|
68
|
-
description:
|
77
|
+
description: 'Unauthorized',
|
69
78
|
content: {
|
70
79
|
'application/json; charset=utf-8' => {
|
71
80
|
schema: {
|
@@ -74,9 +83,14 @@ module SwaggerApi
|
|
74
83
|
}
|
75
84
|
}
|
76
85
|
}
|
77
|
-
}
|
86
|
+
}
|
87
|
+
}
|
88
|
+
end
|
89
|
+
|
90
|
+
def default_bad_request_response
|
91
|
+
{
|
78
92
|
BadRequest: {
|
79
|
-
description:
|
93
|
+
description: 'Bad Request',
|
80
94
|
content: {
|
81
95
|
'application/json; charset=utf-8' => {
|
82
96
|
schema: {
|
@@ -96,12 +110,12 @@ module SwaggerApi
|
|
96
110
|
{
|
97
111
|
version: config.info.version,
|
98
112
|
title: config.info.title,
|
99
|
-
description: config.info.description
|
113
|
+
description: config.info.description
|
100
114
|
}
|
101
115
|
end
|
102
116
|
|
103
117
|
def server_url
|
104
|
-
return unless config.
|
118
|
+
return unless config.servers.respond_to?(Rails.env)
|
105
119
|
config.servers.send(Rails.env).url
|
106
120
|
end
|
107
121
|
end
|
data/swagger_api.gemspec
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
lib = File.expand_path('../lib', __FILE__)
|
2
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
5
|
require 'swagger_api/version'
|
@@ -8,8 +10,8 @@ Gem::Specification.new do |spec|
|
|
8
10
|
spec.authors = ['Full Measure Education']
|
9
11
|
spec.email = ['devops@fullmeasureed.com']
|
10
12
|
|
11
|
-
spec.summary =
|
12
|
-
spec.description =
|
13
|
+
spec.summary = 'A simple library for autocreating RESTful swagger api docs from Rails controllers.'
|
14
|
+
spec.description = 'A simple library for autocreating RESTful swagger api docs from Rails controllers.'
|
13
15
|
spec.homepage = 'https://gitlab.com/fullmeasure/public/swagger-api/swagger_api'
|
14
16
|
spec.license = 'MIT'
|
15
17
|
|
@@ -18,8 +20,7 @@ Gem::Specification.new do |spec|
|
|
18
20
|
if spec.respond_to?(:metadata)
|
19
21
|
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
20
22
|
else
|
21
|
-
raise 'RubyGems 2.0 or newer is required to protect against '
|
22
|
-
'public gem pushes.'
|
23
|
+
raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
|
23
24
|
end
|
24
25
|
|
25
26
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: swagger_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Full Measure Education
|
@@ -106,6 +106,7 @@ files:
|
|
106
106
|
- ".gitignore"
|
107
107
|
- ".gitlab-ci.yml"
|
108
108
|
- ".rspec"
|
109
|
+
- ".rubocop.yml"
|
109
110
|
- ".ruby-version"
|
110
111
|
- CODE_OF_CONDUCT.md
|
111
112
|
- Gemfile
|