zero-rails_openapi 1.4.1 → 1.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +7 -5
- data/README.md +1 -0
- data/README_zh.md +1 -0
- data/bin/console +3 -3
- data/documentation/examples/auto_gen_doc.rb +5 -8
- data/lib/oas_objs/schema_obj.rb +3 -2
- data/lib/open_api/config.rb +1 -13
- data/lib/open_api/dsl/components.rb +9 -5
- data/lib/open_api/generator.rb +1 -1
- data/lib/open_api/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f96bf52633bfd7fe91394003f64571c24bfc4ad
|
4
|
+
data.tar.gz: f44d8713d0691eacd66ae9a5ff62f90f21b97595
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ad13a356350c385963ac5a62233afc6f4a182360b6684e2536782ffaadb86d4458112844ec44eff8055adf5c1957c2dd2ac92b32c906445c221de17693aa34a
|
7
|
+
data.tar.gz: 1dc8b8bb3002a33ac62ab4016fb2359e72a4ce1e43b378c520cf3dbd40dd43227162e43a31801ef824a02323b1fbe5c9f9cdeb51cfe42cb6ee7ba6d3cc174cab
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
zero-rails_openapi (1.4.
|
4
|
+
zero-rails_openapi (1.4.2)
|
5
5
|
activesupport (>= 3)
|
6
6
|
rails (>= 3)
|
7
7
|
|
@@ -58,10 +58,12 @@ GEM
|
|
58
58
|
loofah (2.1.1)
|
59
59
|
crass (~> 1.0.2)
|
60
60
|
nokogiri (>= 1.5.9)
|
61
|
-
mail (2.
|
62
|
-
|
61
|
+
mail (2.6.6)
|
62
|
+
mime-types (>= 1.16, < 4)
|
63
63
|
method_source (0.9.0)
|
64
|
-
|
64
|
+
mime-types (3.1)
|
65
|
+
mime-types-data (~> 3.2015)
|
66
|
+
mime-types-data (3.2016.0521)
|
65
67
|
mini_portile2 (2.3.0)
|
66
68
|
minitest (5.10.3)
|
67
69
|
nio4r (2.1.0)
|
@@ -120,7 +122,7 @@ GEM
|
|
120
122
|
thread_safe (~> 0.1)
|
121
123
|
websocket-driver (0.6.5)
|
122
124
|
websocket-extensions (>= 0.1.0)
|
123
|
-
websocket-extensions (0.1.
|
125
|
+
websocket-extensions (0.1.2)
|
124
126
|
|
125
127
|
PLATFORMS
|
126
128
|
ruby
|
data/README.md
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/zero-rails_openapi.svg)](https://badge.fury.io/rb/zero-rails_openapi)
|
4
4
|
[![Build Status](https://travis-ci.org/zhandao/zero-rails_openapi.svg?branch=master)](https://travis-ci.org/zhandao/zero-rails_openapi)
|
5
5
|
[![Maintainability](https://api.codeclimate.com/v1/badges/471fd60f6eb7b019ceed/maintainability)](https://codeclimate.com/github/zhandao/zero-rails_openapi/maintainability)
|
6
|
+
[![Gitter Chat](https://badges.gitter.im/zero-rails_openapi/Lobby.svg)](https://gitter.im/zero-rails_openapi/Lobby)
|
6
7
|
|
7
8
|
Concise DSL for generating OpenAPI Specification 3 (**OAS3**, formerly Swagger3) JSON documentation for Rails application,
|
8
9
|
then you can use Swagger UI 3.2.0+ to show the documentation.
|
data/README_zh.md
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/zero-rails_openapi.svg)](https://badge.fury.io/rb/zero-rails_openapi)
|
4
4
|
[![Build Status](https://travis-ci.org/zhandao/zero-rails_openapi.svg?branch=master)](https://travis-ci.org/zhandao/zero-rails_openapi)
|
5
5
|
[![Maintainability](https://api.codeclimate.com/v1/badges/471fd60f6eb7b019ceed/maintainability)](https://codeclimate.com/github/zhandao/zero-rails_openapi/maintainability)
|
6
|
+
[![Gitter Chat](https://badges.gitter.im/zero-rails_openapi/Lobby.svg)](https://gitter.im/zero-rails_openapi/Lobby)
|
6
7
|
|
7
8
|
一套简洁的 DSL,用于为 Rails 应用生成 OpenAPI Specification 3 (**OAS3**, 旧称「Swagger3」) 标准的 JSON 文档。
|
8
9
|
(你还可以使用 Swagger-UI 3.2.0 以上版本来可视化所生成的文档。)
|
data/bin/console
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'open_api'
|
5
5
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +10,5 @@ require "open_api"
|
|
10
10
|
# require "pry"
|
11
11
|
# Pry.start
|
12
12
|
|
13
|
-
require
|
13
|
+
require 'irb'
|
14
14
|
IRB.start(__FILE__)
|
@@ -51,20 +51,17 @@ module AutoGenDoc
|
|
51
51
|
model = Object.const_get(action_path.split('#').first.split('/').last[0..-2].camelize) rescue nil
|
52
52
|
type = action.in?(%w[ index show ]) ? Array[load_schema(model)] : String
|
53
53
|
response '200', 'success', :json, type: {
|
54
|
-
code:
|
55
|
-
|
56
|
-
|
57
|
-
timestamp: { type: Integer },
|
58
|
-
language: { type: String, dft: 'Ruby' },
|
59
|
-
data: { type: type }
|
54
|
+
code: { type: Integer, dft: 200 },
|
55
|
+
msg: { type: String, dft: 'success' },
|
56
|
+
data: { type: type }
|
60
57
|
}
|
61
58
|
|
62
59
|
|
63
60
|
### Automatically generate responses based on the agreed error class.
|
64
61
|
# The business error-class's implementation see:
|
65
|
-
# https://github.com/zhandao/zero-rails/blob/master/lib/business_error/
|
62
|
+
# https://github.com/zhandao/zero-rails/blob/master/lib/business_error/dsl.rb
|
66
63
|
# It's usage see:
|
67
|
-
# https://github.com/zhandao/zero-rails/blob/master/app/
|
64
|
+
# https://github.com/zhandao/zero-rails/blob/master/app/_docs/api_error.rb
|
68
65
|
# Then, the following code will auto generate error responses by
|
69
66
|
# extracting the specified error classes info, for example,
|
70
67
|
# in ExamplesError: `mattr_reader :name_not_found, 'can not find the name', 404`
|
data/lib/oas_objs/schema_obj.rb
CHANGED
@@ -11,9 +11,10 @@ module OpenApi
|
|
11
11
|
include SchemaObjHelpers
|
12
12
|
include Helpers
|
13
13
|
|
14
|
-
attr_accessor :processed, :type
|
14
|
+
attr_accessor :processed, :type, :preprocessed
|
15
15
|
|
16
16
|
def initialize(type, schema_hash)
|
17
|
+
self.preprocessed = false
|
17
18
|
self.processed = { }
|
18
19
|
# [Note] Here is no limit to type, even if the input isn't up to OAS,
|
19
20
|
# like: double, float, hash.
|
@@ -51,7 +52,7 @@ module OpenApi
|
|
51
52
|
def preprocess_with_desc desc, param_name = nil
|
52
53
|
self.__desc = desc
|
53
54
|
process_for param_name
|
54
|
-
|
55
|
+
self.preprocessed = true
|
55
56
|
__desc
|
56
57
|
end
|
57
58
|
|
data/lib/open_api/config.rb
CHANGED
@@ -23,7 +23,7 @@ module OpenApi
|
|
23
23
|
end
|
24
24
|
|
25
25
|
cattr_accessor :active_record_base do
|
26
|
-
|
26
|
+
nil
|
27
27
|
end
|
28
28
|
|
29
29
|
# Everything about OAS3 is on https://github.com/OAI/OpenAPI-Specification/blob/OpenAPI.next/versions/3.0.0.md
|
@@ -55,18 +55,6 @@ module OpenApi
|
|
55
55
|
'binary'
|
56
56
|
end
|
57
57
|
|
58
|
-
cattr_accessor :generate_jbuilder_file do
|
59
|
-
false
|
60
|
-
end
|
61
|
-
|
62
|
-
cattr_accessor :overwrite_jbuilder_file do
|
63
|
-
false
|
64
|
-
end
|
65
|
-
|
66
|
-
cattr_accessor :jbuilder_templates do
|
67
|
-
{ }
|
68
|
-
end
|
69
|
-
|
70
58
|
def self.docs
|
71
59
|
open_api_docs
|
72
60
|
end
|
@@ -8,18 +8,19 @@ module OpenApi
|
|
8
8
|
|
9
9
|
def schema component_key, type = nil, one_of: nil, all_of: nil, any_of: nil, not: nil, **schema_hash
|
10
10
|
(schema_hash = type) and (type = type.delete(:type)) if type.is_a?(Hash) && type.key?(:type)
|
11
|
-
type
|
12
|
-
type
|
11
|
+
type ||= schema_hash[:type]
|
12
|
+
type ||= load_schema component_key if component_key.try(:superclass) == Config.active_record_base || ApplicationRecord
|
13
13
|
|
14
|
-
combined_schema =
|
14
|
+
combined_schema = (_not = binding.local_variable_get(:not)) || one_of || all_of || any_of
|
15
15
|
combined_schema = CombinedSchema.new(one_of: one_of, all_of: all_of, any_of: any_of, _not: _not) if combined_schema
|
16
16
|
(self[:schemas] ||= { })[component_key.to_s.to_sym] = combined_schema&.process || SchemaObj.new(type, schema_hash).process
|
17
17
|
end
|
18
18
|
arrow_enable :schema
|
19
19
|
|
20
|
-
def example
|
21
|
-
|
20
|
+
def example component_key, examples_hash
|
21
|
+
(self[:examples] ||= { })[component_key] = ExampleObj.new(examples_hash).process
|
22
22
|
end
|
23
|
+
arrow_enable :example
|
23
24
|
|
24
25
|
def param component_key, param_type, name, type, required, schema_hash = { }
|
25
26
|
(self[:parameters] ||= { })[component_key] = ParamObj.new(name, param_type, type, required, schema_hash).process
|
@@ -60,15 +61,18 @@ module OpenApi
|
|
60
61
|
def base_auth scheme_name, other_info = { }
|
61
62
|
security_scheme scheme_name, { type: 'http', scheme: 'basic' }.merge(other_info)
|
62
63
|
end
|
64
|
+
arrow_enable :base_auth
|
63
65
|
|
64
66
|
def bearer_auth scheme_name, format = 'JWT', other_info = { }
|
65
67
|
security_scheme scheme_name, { type: 'http', scheme: 'bearer', bearerFormat: format }.merge(other_info)
|
66
68
|
end
|
69
|
+
arrow_enable :bearer_auth
|
67
70
|
|
68
71
|
def api_key scheme_name, field:, in:, **other_info
|
69
72
|
_in = binding.local_variable_get(:in)
|
70
73
|
security_scheme scheme_name, { type: 'apiKey', name: field, in: _in }.merge(other_info)
|
71
74
|
end
|
75
|
+
arrow_enable :api_key
|
72
76
|
|
73
77
|
def _process_objs
|
74
78
|
self[:responses]&.each do |code, obj|
|
data/lib/open_api/generator.rb
CHANGED
@@ -27,7 +27,7 @@ module OpenApi
|
|
27
27
|
security: settings[:global_security], tags: [ ], paths: { },
|
28
28
|
components: {
|
29
29
|
securitySchemes: { }, schemas: { }, parameters: { }, requestBodies: { }
|
30
|
-
}.merge(settings[:components])
|
30
|
+
}.merge(settings[:components] || { })
|
31
31
|
)
|
32
32
|
|
33
33
|
settings[:root_controller].descendants.each do |ctrl|
|
data/lib/open_api/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zero-rails_openapi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- zhandao
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-12-
|
11
|
+
date: 2017-12-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -150,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
150
150
|
version: '0'
|
151
151
|
requirements: []
|
152
152
|
rubyforge_project:
|
153
|
-
rubygems_version: 2.6.
|
153
|
+
rubygems_version: 2.6.13
|
154
154
|
signing_key:
|
155
155
|
specification_version: 4
|
156
156
|
summary: Concise DSL for generating OpenAPI3 documentation.
|