zero-rails_openapi 2.0.2 → 2.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/open_api.rb +2 -2
- data/lib/open_api/config_dsl.rb +42 -44
- data/lib/open_api/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 99c7a0aeaedb2ff14dc929912f7aa734122c7ab76bea448c68186ab512ef79e1
|
4
|
+
data.tar.gz: a2c95b2bf0856dee961183bb10f8f76f7a9031902199fc5874ac195b04eb4691
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f868f8ccc21c52f10391dd9153814fa0cad1378fb1044455d07754639ad9e2951b331013d38accc28006e3ddf20944fa3179c1f34f5b460c3dff0072758de3b
|
7
|
+
data.tar.gz: 18b5a70b962887ba16a79e58cd11ae3e16cd8460f4c9e3d2f96812e9effdf482203a7f8bb92697ddd6046b1e7e9f9e9d184eed2624cf601eb905aa909aab4145
|
data/lib/open_api.rb
CHANGED
@@ -10,8 +10,8 @@ require 'open_api/dsl'
|
|
10
10
|
|
11
11
|
module OpenApi
|
12
12
|
module_function
|
13
|
-
cattr_accessor
|
14
|
-
cattr_accessor
|
13
|
+
cattr_accessor(:routes_index) { { } }
|
14
|
+
cattr_accessor(:docs) { { } }
|
15
15
|
|
16
16
|
def write_docs(if: true, read_on_controller: true)
|
17
17
|
(docs = generate_docs(read_on_controller)) and Tip.loaded
|
data/lib/open_api/config_dsl.rb
CHANGED
@@ -1,52 +1,50 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'active_support/concern'
|
4
|
+
|
3
5
|
module OpenApi
|
4
6
|
module ConfigDSL
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
open_api_docs[name] = { base_doc_classes: base_doc_classes }
|
12
|
-
end
|
13
|
-
|
14
|
-
def info version:, title:, desc: '', **addition
|
15
|
-
open_api_docs[@api][:info] = { version: version, title: title, description: desc, **addition }
|
16
|
-
end
|
17
|
-
|
18
|
-
def server url, desc: ''
|
19
|
-
(open_api_docs[@api][:servers] ||= [ ]) << { url: url, description: desc }
|
20
|
-
end
|
21
|
-
|
22
|
-
def security_scheme scheme_name, other_info# = { }
|
23
|
-
other_info[:description] = other_info.delete(:desc) if other_info.key?(:desc)
|
24
|
-
(open_api_docs[@api][:securitySchemes] ||= { })[scheme_name] = other_info
|
25
|
-
end
|
26
|
-
|
27
|
-
def base_auth scheme_name, other_info = { }
|
28
|
-
security_scheme scheme_name, { type: 'http', scheme: 'basic', **other_info }
|
29
|
-
end
|
30
|
-
|
31
|
-
def bearer_auth scheme_name, format = 'JWT', other_info = { }
|
32
|
-
security_scheme scheme_name, { type: 'http', scheme: 'bearer', bearerFormat: format, **other_info }
|
33
|
-
end
|
34
|
-
|
35
|
-
def api_key scheme_name, field:, in: 'header', **other_info
|
36
|
-
_in = binding.local_variable_get(:in)
|
37
|
-
security_scheme scheme_name, { type: 'apiKey', name: field, in: _in, **other_info }
|
38
|
-
end
|
39
|
-
|
40
|
-
def global_security_require scheme_name, scopes: [ ]
|
41
|
-
(open_api_docs[@api][:global_security] ||= [ ]) << { scheme_name => scopes }
|
42
|
-
end
|
43
|
-
|
44
|
-
class << self
|
45
|
-
alias global_security global_security_require
|
46
|
-
alias global_auth global_security_require
|
47
|
-
alias auth_scheme security_scheme
|
48
|
-
end
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
class_methods do
|
10
|
+
def open_api name, base_doc_classes:
|
11
|
+
@api = name
|
12
|
+
open_api_docs[name] = { base_doc_classes: base_doc_classes }
|
49
13
|
end
|
14
|
+
|
15
|
+
def info version:, title:, desc: '', **addition
|
16
|
+
open_api_docs[@api][:info] = { version: version, title: title, description: desc, **addition }
|
17
|
+
end
|
18
|
+
|
19
|
+
def server url, desc: ''
|
20
|
+
(open_api_docs[@api][:servers] ||= [ ]) << { url: url, description: desc }
|
21
|
+
end
|
22
|
+
|
23
|
+
def security_scheme scheme_name, other_info# = { }
|
24
|
+
other_info[:description] = other_info.delete(:desc) if other_info.key?(:desc)
|
25
|
+
(open_api_docs[@api][:securitySchemes] ||= { })[scheme_name] = other_info
|
26
|
+
end
|
27
|
+
|
28
|
+
def base_auth scheme_name, other_info = { }
|
29
|
+
security_scheme scheme_name, { type: 'http', scheme: 'basic', **other_info }
|
30
|
+
end
|
31
|
+
|
32
|
+
def bearer_auth scheme_name, format = 'JWT', other_info = { }
|
33
|
+
security_scheme scheme_name, { type: 'http', scheme: 'bearer', bearerFormat: format, **other_info }
|
34
|
+
end
|
35
|
+
|
36
|
+
def api_key scheme_name, field:, in: 'header', **other_info
|
37
|
+
_in = binding.local_variable_get(:in)
|
38
|
+
security_scheme scheme_name, { type: 'apiKey', name: field, in: _in, **other_info }
|
39
|
+
end
|
40
|
+
|
41
|
+
def global_security_require scheme_name, scopes: [ ]
|
42
|
+
(open_api_docs[@api][:global_security] ||= [ ]) << { scheme_name => scopes }
|
43
|
+
end
|
44
|
+
|
45
|
+
alias global_security global_security_require
|
46
|
+
alias global_auth global_security_require
|
47
|
+
alias auth_scheme security_scheme
|
50
48
|
end
|
51
49
|
end
|
52
50
|
end
|
data/lib/open_api/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zero-rails_openapi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- zhandao
|
@@ -188,7 +188,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
188
188
|
version: '0'
|
189
189
|
requirements: []
|
190
190
|
rubyforge_project:
|
191
|
-
rubygems_version: 2.
|
191
|
+
rubygems_version: 2.7.3
|
192
192
|
signing_key:
|
193
193
|
specification_version: 4
|
194
194
|
summary: Concise DSL for generating OpenAPI3 documentation.
|