swaggard 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/swaggard/api_definition.rb +1 -1
- data/lib/swaggard/configuration.rb +8 -2
- data/lib/swaggard/parsers/models.rb +2 -2
- data/lib/swaggard/parsers/property.rb +21 -0
- data/lib/swaggard/parsers/type.rb +15 -0
- data/lib/swaggard/swagger/parameters/body.rb +2 -7
- data/lib/swaggard/swagger/parameters/query.rb +2 -3
- data/lib/swaggard/swagger/property.rb +3 -14
- data/lib/swaggard/swagger/type.rb +4 -10
- data/lib/swaggard/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f1057b0a7cf432113d8b58f3bb1857dd4f3fc72b2f916e7dd7342878b6f0192
|
4
|
+
data.tar.gz: 732909ca2cab511875bf16403f83d4f5a00e796ad211ce49e83dd5af96eceb4b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 778991418f4c1640172aa9cb306070a5562b4cc1f9736b6f0bbed659e8a9f4c10d269dec050389cb8c4e8e8d480d164bc6f75fbf8b53a002bf057e55a1debe41
|
7
|
+
data.tar.gz: c1c8c9944b66ef1f736d1a323d3484aaab883f62fba843e5bcf442d0ff60fbb3fab728b367be25772e794def8f3c604bae7f64d66a3c1a8ba8dcf3de127c55f8
|
@@ -51,7 +51,7 @@ module Swaggard
|
|
51
51
|
'produces' => Swaggard.configuration.api_formats.map { |format| "application/#{format}" },
|
52
52
|
'tags' => @tags.map { |_, tag| tag.to_doc },
|
53
53
|
'paths' => Hash[@paths.values.map { |path| [format_path(path.path), path.to_doc] }],
|
54
|
-
'definitions' => Hash[@definitions.map { |id, definition| [id, definition.to_doc(@definitions)] }]
|
54
|
+
'definitions' => Hash[@definitions.merge(Swaggard.configuration.definitions).map { |id, definition| [id, definition.to_doc(@definitions)] }]
|
55
55
|
}
|
56
56
|
end
|
57
57
|
|
@@ -23,8 +23,6 @@ module Swaggard
|
|
23
23
|
:default_response_status_code, :excluded_paths, :path_parameter_description,
|
24
24
|
:ignore_put_if_patch_exists
|
25
25
|
|
26
|
-
attr_reader :custom_types
|
27
|
-
|
28
26
|
def swagger_version
|
29
27
|
@swagger_version ||= '2.0'
|
30
28
|
end
|
@@ -149,6 +147,14 @@ module Swaggard
|
|
149
147
|
custom_types[name] = definition
|
150
148
|
end
|
151
149
|
|
150
|
+
def definitions
|
151
|
+
@definitions ||= {}
|
152
|
+
end
|
153
|
+
|
154
|
+
def add_definition(definition)
|
155
|
+
definitions[definition.id] = definition
|
156
|
+
end
|
157
|
+
|
152
158
|
def path_parameter_description
|
153
159
|
@path_parameter_description ||= ->(path_parameter) { "Scope response to #{path_parameter.name}" }
|
154
160
|
end
|
@@ -22,9 +22,9 @@ module Swaggard
|
|
22
22
|
|
23
23
|
Swagger::Definition.new(yard_object.path, ancestors: yard_object.inheritance_tree.map(&:path)).tap do |definition|
|
24
24
|
yard_object.tags.each do |tag|
|
25
|
-
case tag.tag_name
|
25
|
+
case tag.tag_name
|
26
26
|
when 'attr'
|
27
|
-
property =
|
27
|
+
property = Swaggard::Parsers::Property.run(tag)
|
28
28
|
definition.add_property(property)
|
29
29
|
when 'ignore_inherited'
|
30
30
|
definition.ignore_inherited = true
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require_relative '../swagger/property'
|
2
|
+
|
3
|
+
module Swaggard
|
4
|
+
module Parsers
|
5
|
+
module Property
|
6
|
+
def self.run(yard_object)
|
7
|
+
name = yard_object.name.dup
|
8
|
+
options_and_description = yard_object.text&.dup || ''
|
9
|
+
|
10
|
+
options_and_description.gsub!("\n", ' ')
|
11
|
+
options, description = options_and_description.match(/\A(\[.*\])?(.*)\Z/).captures
|
12
|
+
options = options ? options.gsub(/\[?\]?\s?/, '').split(',') : []
|
13
|
+
description = description.strip
|
14
|
+
required = name.gsub!(/^!/, '')
|
15
|
+
type = Parsers::Type.run(yard_object.types.first)
|
16
|
+
|
17
|
+
Swaggard::Swagger::Property.new(name, type, description, required.present?, options)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require_relative '../swagger/type'
|
2
|
+
|
3
|
+
module Swaggard
|
4
|
+
module Parsers
|
5
|
+
module Type
|
6
|
+
def self.run(string)
|
7
|
+
parts = string.split(/[<>]/)
|
8
|
+
name = parts.last
|
9
|
+
is_array = parts.grep(/array/i).any?
|
10
|
+
|
11
|
+
Swaggard::Swagger::Type.new(name, is_array)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -1,11 +1,10 @@
|
|
1
1
|
require_relative 'base'
|
2
|
-
require_relative '
|
2
|
+
require_relative '../../parsers/type'
|
3
3
|
|
4
4
|
module Swaggard
|
5
5
|
module Swagger
|
6
6
|
module Parameters
|
7
7
|
class Body < Base
|
8
|
-
|
9
8
|
attr_reader :definition
|
10
9
|
|
11
10
|
def initialize(operation_name)
|
@@ -51,9 +50,7 @@ module Swaggard
|
|
51
50
|
|
52
51
|
private
|
53
52
|
|
54
|
-
|
55
53
|
class Property
|
56
|
-
|
57
54
|
attr_reader :id
|
58
55
|
|
59
56
|
def initialize(string)
|
@@ -83,13 +80,11 @@ module Swaggard
|
|
83
80
|
|
84
81
|
@id = name
|
85
82
|
@description = description if description.present?
|
86
|
-
@type = Type.
|
83
|
+
@type = Parsers::Type.run(data_type)
|
87
84
|
@required = required
|
88
85
|
@options = options
|
89
86
|
end
|
90
|
-
|
91
87
|
end
|
92
|
-
|
93
88
|
end
|
94
89
|
end
|
95
90
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
require_relative 'base'
|
2
|
+
require_relative '../../parsers/type'
|
2
3
|
|
3
4
|
module Swaggard
|
4
5
|
module Swagger
|
5
6
|
module Parameters
|
6
7
|
class Query < Base
|
7
|
-
|
8
8
|
def initialize(string)
|
9
9
|
@in = 'query'
|
10
10
|
parse(string)
|
@@ -37,12 +37,11 @@ module Swaggard
|
|
37
37
|
|
38
38
|
@name = name
|
39
39
|
@description = description
|
40
|
-
@type = Type.
|
40
|
+
@type = Parsers::Type.run(data_type)
|
41
41
|
@is_required = required.present?
|
42
42
|
@allow_multiple = allow_multiple.present?
|
43
43
|
@options = options
|
44
44
|
end
|
45
|
-
|
46
45
|
end
|
47
46
|
end
|
48
47
|
end
|
@@ -3,23 +3,13 @@ require_relative 'type'
|
|
3
3
|
module Swaggard
|
4
4
|
module Swagger
|
5
5
|
class Property
|
6
|
-
|
7
6
|
attr_reader :id, :type, :description
|
8
7
|
|
9
|
-
def initialize(
|
10
|
-
name = yard_object.name.dup
|
11
|
-
options_and_description = yard_object.text&.dup || ''
|
12
|
-
|
13
|
-
options_and_description.gsub!("\n", ' ')
|
14
|
-
options, description = options_and_description.match(/\A(\[.*\])?(.*)\Z/).captures
|
15
|
-
options = options ? options.gsub(/\[?\]?\s?/, '').split(',') : []
|
16
|
-
description = description.strip
|
17
|
-
required = name.gsub!(/^!/, '')
|
18
|
-
|
8
|
+
def initialize(name, type, description = '', required = false, options = [])
|
19
9
|
@id = name
|
20
|
-
@type =
|
10
|
+
@type = type
|
21
11
|
@description = description
|
22
|
-
@required = required
|
12
|
+
@required = required
|
23
13
|
@options = options
|
24
14
|
end
|
25
15
|
|
@@ -33,7 +23,6 @@ module Swaggard
|
|
33
23
|
result['enum'] = @options if @options.present?
|
34
24
|
result
|
35
25
|
end
|
36
|
-
|
37
26
|
end
|
38
27
|
end
|
39
28
|
end
|
@@ -12,14 +12,16 @@ module Swaggard
|
|
12
12
|
'boolean' => { 'type' => 'boolean' },
|
13
13
|
'date' => { 'type' => 'string', 'format' => 'date' },
|
14
14
|
'date-time' => { 'type' => 'string', 'format' => 'date-time' },
|
15
|
+
'datetime' => { 'type' => 'string', 'format' => 'date-time' },
|
15
16
|
'password' => { 'type' => 'string', 'format' => 'password' },
|
16
17
|
'hash' => { 'type' => 'object' }
|
17
18
|
}
|
18
19
|
|
19
20
|
attr_reader :name
|
20
21
|
|
21
|
-
def initialize(
|
22
|
-
|
22
|
+
def initialize(name, is_array = false)
|
23
|
+
@name = name.to_s
|
24
|
+
@is_array = is_array
|
23
25
|
end
|
24
26
|
|
25
27
|
def to_doc
|
@@ -32,14 +34,6 @@ module Swaggard
|
|
32
34
|
|
33
35
|
private
|
34
36
|
|
35
|
-
def parse(types)
|
36
|
-
parts = types.first.split(/[<>]/)
|
37
|
-
|
38
|
-
@name = parts.last
|
39
|
-
@is_array = parts.grep(/array/i).any?
|
40
|
-
end
|
41
|
-
|
42
|
-
|
43
37
|
def basic_type?
|
44
38
|
BASIC_TYPES.has_key?(@name.downcase)
|
45
39
|
end
|
data/lib/swaggard/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: swaggard
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adrian Gomez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-03-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -168,7 +168,9 @@ files:
|
|
168
168
|
- lib/swaggard/engine.rb
|
169
169
|
- lib/swaggard/parsers/controller.rb
|
170
170
|
- lib/swaggard/parsers/models.rb
|
171
|
+
- lib/swaggard/parsers/property.rb
|
171
172
|
- lib/swaggard/parsers/routes.rb
|
173
|
+
- lib/swaggard/parsers/type.rb
|
172
174
|
- lib/swaggard/swagger/definition.rb
|
173
175
|
- lib/swaggard/swagger/operation.rb
|
174
176
|
- lib/swaggard/swagger/parameters/base.rb
|