openapi-rails 0.3.0

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.
Files changed (62) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +2 -0
  3. data/Gemfile +3 -0
  4. data/Gemfile.lock +99 -0
  5. data/LICENSE.md +21 -0
  6. data/README.md +61 -0
  7. data/Rakefile +1 -0
  8. data/app/assets/fonts/openapi/DroidSans-Bold.ttf +0 -0
  9. data/app/assets/fonts/openapi/DroidSans.ttf +0 -0
  10. data/app/assets/images/openapi/collapse.gif +0 -0
  11. data/app/assets/images/openapi/expand.gif +0 -0
  12. data/app/assets/images/openapi/explorer_icons.png +0 -0
  13. data/app/assets/images/openapi/favicon-16x16.png +0 -0
  14. data/app/assets/images/openapi/favicon-32x32.png +0 -0
  15. data/app/assets/images/openapi/favicon.ico +0 -0
  16. data/app/assets/images/openapi/logo_small.png +0 -0
  17. data/app/assets/images/openapi/pet_store_api.png +0 -0
  18. data/app/assets/images/openapi/throbber.gif +0 -0
  19. data/app/assets/images/openapi/wordnik_api.png +0 -0
  20. data/app/assets/javascripts/openapi/application.coffee +58 -0
  21. data/app/assets/javascripts/openapi/lib/backbone-min.js +15 -0
  22. data/app/assets/javascripts/openapi/lib/es5-shim.js +2065 -0
  23. data/app/assets/javascripts/openapi/lib/handlebars-4.0.5.js +4608 -0
  24. data/app/assets/javascripts/openapi/lib/highlight.9.1.0.pack.js +2 -0
  25. data/app/assets/javascripts/openapi/lib/highlight.9.1.0.pack_extended.js +34 -0
  26. data/app/assets/javascripts/openapi/lib/jquery-1.8.0.min.js +2 -0
  27. data/app/assets/javascripts/openapi/lib/jquery.ba-bbq.min.js +18 -0
  28. data/app/assets/javascripts/openapi/lib/jquery.slideto.min.js +1 -0
  29. data/app/assets/javascripts/openapi/lib/jquery.wiggle.min.js +8 -0
  30. data/app/assets/javascripts/openapi/lib/js-yaml.min.js +3 -0
  31. data/app/assets/javascripts/openapi/lib/jsoneditor.min.js +11 -0
  32. data/app/assets/javascripts/openapi/lib/lodash.min.js +102 -0
  33. data/app/assets/javascripts/openapi/lib/marked.js +1272 -0
  34. data/app/assets/javascripts/openapi/lib/object-assign-pollyfill.js +23 -0
  35. data/app/assets/javascripts/openapi/lib/swagger-oauth.js +347 -0
  36. data/app/assets/javascripts/openapi/swagger-ui.js +24758 -0
  37. data/app/assets/stylesheets/openapi/application.scss +4 -0
  38. data/app/assets/stylesheets/openapi/print.scss +1367 -0
  39. data/app/assets/stylesheets/openapi/reset.scss +125 -0
  40. data/app/assets/stylesheets/openapi/screen.scss +1497 -0
  41. data/app/assets/stylesheets/openapi/typography.scss +14 -0
  42. data/app/controllers/openapi_controller.rb +24 -0
  43. data/app/views/openapi/index.html.erb +56 -0
  44. data/lib/generators/openapi/config_generator.rb +20 -0
  45. data/lib/generators/openapi/templates/base_controller.rb +6 -0
  46. data/lib/generators/openapi/templates/openapi.rb +21 -0
  47. data/lib/openapi-rails.rb +1 -0
  48. data/lib/openapi.rb +26 -0
  49. data/lib/openapi/configuration.rb +17 -0
  50. data/lib/openapi/engine.rb +32 -0
  51. data/lib/openapi/mongoid/crud_actions.rb +235 -0
  52. data/lib/openapi/mongoid/spec_builder.rb +451 -0
  53. data/lib/openapi/routes_parser.rb +50 -0
  54. data/lib/openapi/version.rb +3 -0
  55. data/lib/rails/routes.rb +20 -0
  56. data/lib/renderers/csv.rb +36 -0
  57. data/lib/swagger/blocks/items_node.rb +7 -0
  58. data/lib/swagger/blocks/property_node.rb +7 -0
  59. data/lib/swagger/blocks/schema_builder.rb +89 -0
  60. data/lib/swagger/blocks/schema_node.rb +7 -0
  61. data/openapi-rails.gemspec +35 -0
  62. metadata +204 -0
@@ -0,0 +1,3 @@
1
+ module Openapi
2
+ VERSION = '0.3.0'.freeze
3
+ end
@@ -0,0 +1,20 @@
1
+ module ActionDispatch
2
+ module Routing
3
+ class Mapper
4
+ def crud(*options, &block)
5
+ options << { except: %w(new edit), defaults: { format: :json } }
6
+ resources(*options, &block)
7
+ end
8
+
9
+ def mount_openapi_documentation
10
+ get :openapi, to: 'openapi#index'
11
+ end
12
+
13
+ def mount_openapi_specification(options={})
14
+ name = options[:name] || :default
15
+ get :spec, to: '/openapi#spec',
16
+ defaults: { format: :json, name: name }
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,36 @@
1
+ require 'csv'
2
+ require 'action_controller/metal/renderers'
3
+
4
+ ActionController::Renderers.add :csv do |objects, options|
5
+ return '' unless objects.first
6
+
7
+ object_klass = objects.first.class
8
+
9
+ return '' unless object_klass.respond_to? :fields
10
+
11
+ columns = object_klass.fields.keys
12
+ csv_options = self.csv_config || {}
13
+
14
+ if csv_options
15
+ if csv_options.key?(:only)
16
+ columns &= csv_options[:only].map(&:to_s)
17
+ end
18
+
19
+ if csv_options.key?(:except)
20
+ columns -= csv_options[:except].map(&:to_s)
21
+ end
22
+
23
+ if csv_options.key?(:methods)
24
+ columns += csv_options[:methods].map(&:to_s)
25
+ end
26
+ end
27
+
28
+ str = CSV.generate do |row|
29
+ row << columns
30
+ objects.each do |obj|
31
+ row << columns.map { |c| obj.send(c) }
32
+ end
33
+ end
34
+
35
+ return str
36
+ end
@@ -0,0 +1,7 @@
1
+ module Swagger
2
+ module Blocks
3
+ class ItemsNode
4
+ include SchemaBuilder
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Swagger
2
+ module Blocks
3
+ class PropertyNode
4
+ include SchemaBuilder
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,89 @@
1
+ module Swagger
2
+ module Blocks
3
+ module SchemaBuilder
4
+ extend ActiveSupport::Concern
5
+
6
+ SUPPORTED_TYPES = %w(Mongoid::Boolean
7
+ BSON::ObjectId
8
+ Object
9
+ Time
10
+ String
11
+ Integer
12
+ Array
13
+ Date
14
+ Symbol).freeze
15
+
16
+ def get_required_fields(model_class)
17
+ presence_validators = model_class.
18
+ validators.
19
+ select { |v| v.class == Mongoid::Validatable::PresenceValidator }
20
+
21
+ required_fields = presence_validators.map { |v| v.attributes.first }
22
+ required_fields << '_id'
23
+ required_fields
24
+ end
25
+
26
+ def build_model_schema(model_class, include_only_required_fields=false)
27
+ required_fields = get_required_fields(model_class)
28
+
29
+ key :required, required_fields
30
+
31
+ model_class.fields.each do |name, options|
32
+ type = options.type.to_s
33
+ defaul_value = options.options[:default]
34
+
35
+ next unless SUPPORTED_TYPES.include?(type)
36
+
37
+ if include_only_required_fields
38
+ next if name == '_id'
39
+ next unless required_fields.include?(name.to_sym)
40
+ end
41
+
42
+ property name do
43
+ case type
44
+ when 'Symbol'
45
+ klass = options.options[:klass].to_s
46
+ constant = name.sub('_', '').upcase
47
+ values = "#{klass}::#{constant}".constantize
48
+
49
+ key :type, :string
50
+ key :enum, values
51
+
52
+ when 'Array'
53
+ key :type, :array
54
+ # TODO: autodetect type of Array Item
55
+ items do
56
+ key :type, :string
57
+ end
58
+
59
+ when 'BSON::ObjectId'
60
+ key :type, :string
61
+ key :format, :uuid
62
+
63
+ when 'Date'
64
+ key :type, :string
65
+ key :format, :date
66
+
67
+ when 'Time'
68
+ key :type, :string
69
+ key :format, 'date-time'
70
+
71
+ when 'Mongoid::Boolean'
72
+ key :type, :boolean
73
+ key :default, defaul_value
74
+
75
+ when 'Integer'
76
+ key :type, :integer
77
+ key :default, defaul_value.to_i
78
+
79
+ else
80
+ key :type, :string
81
+ key :default, defaul_value.to_s
82
+
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,7 @@
1
+ module Swagger
2
+ module Blocks
3
+ class SchemaNode
4
+ include SchemaBuilder
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,35 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'openapi/version'
4
+ require 'date'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = 'openapi-rails'
8
+ s.summary = 'CRUD interface for Rails models with OpenAPI (Swagger) specification support and Swagger UI integration.'
9
+ s.homepage = 'http://github.com/slate-studio/openapi-rails'
10
+ s.authors = [ 'Alexander Kravets', 'Denis Popov' ]
11
+ s.email = "alex@slatestudio.com"
12
+ s.date = Date.today.strftime('%Y-%m-%d')
13
+ s.extra_rdoc_files = %w[ README.md ]
14
+ s.license = 'MIT'
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.require_paths = [ 'lib' ]
18
+ s.version = Openapi::VERSION
19
+ s.platform = Gem::Platform::RUBY
20
+
21
+ # DSL for pure Ruby code blocks that can be turned into JSON
22
+ s.add_dependency 'swagger-blocks'
23
+ # A set of Rails responders to dry up application controllers
24
+ s.add_dependency 'responders', '~> 2.3'
25
+ # Clean, powerful, customizable and sophisticated paginator
26
+ s.add_dependency 'kaminari'
27
+ # C extensions to accelerate the Ruby BSON serialization
28
+ s.add_dependency 'bson_ext'
29
+ # Fast streaming JSON parsing and encoding library for Ruby
30
+ s.add_dependency 'yajl-ruby'
31
+ # Ruby ODM framework for MongoDB
32
+ s.add_dependency 'mongoid'
33
+ # Map incoming controller parameters to named scopes in resources
34
+ s.add_dependency 'has_scope'
35
+ end
metadata ADDED
@@ -0,0 +1,204 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: openapi-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ platform: ruby
6
+ authors:
7
+ - Alexander Kravets
8
+ - Denis Popov
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2016-08-30 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: swagger-blocks
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: responders
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '2.3'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '2.3'
42
+ - !ruby/object:Gem::Dependency
43
+ name: kaminari
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: bson_ext
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: yajl-ruby
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: mongoid
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :runtime
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: has_scope
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ type: :runtime
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ description:
113
+ email: alex@slatestudio.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files:
117
+ - README.md
118
+ files:
119
+ - ".gitignore"
120
+ - Gemfile
121
+ - Gemfile.lock
122
+ - LICENSE.md
123
+ - README.md
124
+ - Rakefile
125
+ - app/assets/fonts/openapi/DroidSans-Bold.ttf
126
+ - app/assets/fonts/openapi/DroidSans.ttf
127
+ - app/assets/images/openapi/collapse.gif
128
+ - app/assets/images/openapi/expand.gif
129
+ - app/assets/images/openapi/explorer_icons.png
130
+ - app/assets/images/openapi/favicon-16x16.png
131
+ - app/assets/images/openapi/favicon-32x32.png
132
+ - app/assets/images/openapi/favicon.ico
133
+ - app/assets/images/openapi/logo_small.png
134
+ - app/assets/images/openapi/pet_store_api.png
135
+ - app/assets/images/openapi/throbber.gif
136
+ - app/assets/images/openapi/wordnik_api.png
137
+ - app/assets/javascripts/openapi/application.coffee
138
+ - app/assets/javascripts/openapi/lib/backbone-min.js
139
+ - app/assets/javascripts/openapi/lib/es5-shim.js
140
+ - app/assets/javascripts/openapi/lib/handlebars-4.0.5.js
141
+ - app/assets/javascripts/openapi/lib/highlight.9.1.0.pack.js
142
+ - app/assets/javascripts/openapi/lib/highlight.9.1.0.pack_extended.js
143
+ - app/assets/javascripts/openapi/lib/jquery-1.8.0.min.js
144
+ - app/assets/javascripts/openapi/lib/jquery.ba-bbq.min.js
145
+ - app/assets/javascripts/openapi/lib/jquery.slideto.min.js
146
+ - app/assets/javascripts/openapi/lib/jquery.wiggle.min.js
147
+ - app/assets/javascripts/openapi/lib/js-yaml.min.js
148
+ - app/assets/javascripts/openapi/lib/jsoneditor.min.js
149
+ - app/assets/javascripts/openapi/lib/lodash.min.js
150
+ - app/assets/javascripts/openapi/lib/marked.js
151
+ - app/assets/javascripts/openapi/lib/object-assign-pollyfill.js
152
+ - app/assets/javascripts/openapi/lib/swagger-oauth.js
153
+ - app/assets/javascripts/openapi/swagger-ui.js
154
+ - app/assets/stylesheets/openapi/application.scss
155
+ - app/assets/stylesheets/openapi/print.scss
156
+ - app/assets/stylesheets/openapi/reset.scss
157
+ - app/assets/stylesheets/openapi/screen.scss
158
+ - app/assets/stylesheets/openapi/typography.scss
159
+ - app/controllers/openapi_controller.rb
160
+ - app/views/openapi/index.html.erb
161
+ - lib/generators/openapi/config_generator.rb
162
+ - lib/generators/openapi/templates/base_controller.rb
163
+ - lib/generators/openapi/templates/openapi.rb
164
+ - lib/openapi-rails.rb
165
+ - lib/openapi.rb
166
+ - lib/openapi/configuration.rb
167
+ - lib/openapi/engine.rb
168
+ - lib/openapi/mongoid/crud_actions.rb
169
+ - lib/openapi/mongoid/spec_builder.rb
170
+ - lib/openapi/routes_parser.rb
171
+ - lib/openapi/version.rb
172
+ - lib/rails/routes.rb
173
+ - lib/renderers/csv.rb
174
+ - lib/swagger/blocks/items_node.rb
175
+ - lib/swagger/blocks/property_node.rb
176
+ - lib/swagger/blocks/schema_builder.rb
177
+ - lib/swagger/blocks/schema_node.rb
178
+ - openapi-rails.gemspec
179
+ homepage: http://github.com/slate-studio/openapi-rails
180
+ licenses:
181
+ - MIT
182
+ metadata: {}
183
+ post_install_message:
184
+ rdoc_options: []
185
+ require_paths:
186
+ - lib
187
+ required_ruby_version: !ruby/object:Gem::Requirement
188
+ requirements:
189
+ - - ">="
190
+ - !ruby/object:Gem::Version
191
+ version: '0'
192
+ required_rubygems_version: !ruby/object:Gem::Requirement
193
+ requirements:
194
+ - - ">="
195
+ - !ruby/object:Gem::Version
196
+ version: '0'
197
+ requirements: []
198
+ rubyforge_project:
199
+ rubygems_version: 2.5.1
200
+ signing_key:
201
+ specification_version: 4
202
+ summary: CRUD interface for Rails models with OpenAPI (Swagger) specification support
203
+ and Swagger UI integration.
204
+ test_files: []