ruby-swagger 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ruby-swagger/data/mime.rb +1 -1
- data/lib/ruby-swagger/data/path.rb +5 -1
- data/lib/ruby-swagger/data/paths.rb +4 -0
- data/lib/ruby-swagger/grape/method.rb +11 -5
- data/lib/ruby-swagger/grape/type.rb +84 -38
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ccc71e0ff84b67c4ac47b030628c2066702eb09
|
4
|
+
data.tar.gz: 3e41cd67f7e59e2edfc529946eddee2e9704c95b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fccc7b0f0152cd5bd34e06747b91cc6a632d03a18056415a2f826fe8b9384a75acc38ac49dc14658d13e7e17a25c6fbc8bd42e1b90c5f2fc01c7b36272cabfd8
|
7
|
+
data.tar.gz: 7e6f89f399ba6f59749da1fcbc0f33cb046a4137d6c6f61109d4b5632e24d89402279f257328d6fd24feace23f965b37948bfd62048fcdb942edfcab9a5eada2
|
@@ -3,9 +3,9 @@ module Swagger::Data
|
|
3
3
|
@@types = [
|
4
4
|
'text/plain',
|
5
5
|
'text/plain; charset=utf-8',
|
6
|
-
'application/octet-stream',
|
7
6
|
'application/json',
|
8
7
|
'application/hal+json',
|
8
|
+
'application/problem+json',
|
9
9
|
'application/postscript',
|
10
10
|
'application/pdf',
|
11
11
|
'application/postscript',
|
@@ -16,6 +16,10 @@ module Swagger::Data
|
|
16
16
|
res
|
17
17
|
end
|
18
18
|
|
19
|
+
def all_methods
|
20
|
+
[@get, @put, @post, @delete, @options, @head, @patch].compact
|
21
|
+
end
|
22
|
+
|
19
23
|
def get=(new_get)
|
20
24
|
return nil unless new_get
|
21
25
|
unless new_get.is_a?(Swagger::Data::Operation)
|
@@ -25,7 +29,7 @@ module Swagger::Data
|
|
25
29
|
@get = new_get
|
26
30
|
end
|
27
31
|
|
28
|
-
def
|
32
|
+
def put=(new_put)
|
29
33
|
return nil unless new_put
|
30
34
|
unless new_put.is_a?(Swagger::Data::Operation)
|
31
35
|
new_put = Swagger::Data::Operation.parse(new_put)
|
@@ -239,12 +239,18 @@ module Swagger::Grape
|
|
239
239
|
end
|
240
240
|
|
241
241
|
# Can potentionelly be used for per-param documentation, for now used for example values
|
242
|
-
def documented_paramter(schema,
|
242
|
+
def documented_paramter(schema, target, parameter)
|
243
243
|
return if parameter.nil? || parameter[:documentation].nil?
|
244
|
-
|
245
244
|
unless parameter[:documentation][:example].nil?
|
246
245
|
schema['example'] ||= {}
|
247
|
-
|
246
|
+
if target.is_a? Array
|
247
|
+
nesting = target[0]
|
248
|
+
target = target[1]
|
249
|
+
schema['example'][nesting] ||= {}
|
250
|
+
schema['example'][nesting][target] = parameter[:documentation][:example]
|
251
|
+
else
|
252
|
+
schema['example'][target] = parameter[:documentation][:example]
|
253
|
+
end
|
248
254
|
end
|
249
255
|
end
|
250
256
|
|
@@ -259,12 +265,12 @@ module Swagger::Grape
|
|
259
265
|
path = param_name.scan(/[0-9a-zA-Z_]+/)
|
260
266
|
append_to = find_elem_in_schema(schema, path.dup)
|
261
267
|
converted_param = Swagger::Grape::Param.new(parameter)
|
268
|
+
|
262
269
|
append_to['properties'][path.last] = converted_param.to_swagger
|
263
270
|
|
264
271
|
remember_type(converted_param.type_definition) if converted_param.has_type_definition?
|
265
|
-
|
266
272
|
required_parameter(append_to, path.last, parameter)
|
267
|
-
documented_paramter(
|
273
|
+
documented_paramter(schema, path, parameter)
|
268
274
|
end
|
269
275
|
|
270
276
|
def find_elem_in_schema(root, schema_path)
|
@@ -8,11 +8,10 @@ module Swagger::Grape
|
|
8
8
|
|
9
9
|
def initialize(type)
|
10
10
|
@type = type.to_s || 'String'
|
11
|
-
@swagger_type = {}
|
12
11
|
end
|
13
12
|
|
14
13
|
def to_swagger(with_definition = true)
|
15
|
-
translate(
|
14
|
+
translate(with_definition)
|
16
15
|
end
|
17
16
|
|
18
17
|
def sub_types
|
@@ -21,47 +20,94 @@ module Swagger::Grape
|
|
21
20
|
|
22
21
|
private
|
23
22
|
|
24
|
-
def translate(
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
when 'array'
|
31
|
-
@swagger_type['type'] = 'array'
|
32
|
-
@swagger_type['items'] = { 'type' => 'string' }
|
33
|
-
when 'hash'
|
34
|
-
@swagger_type['type'] = 'object'
|
35
|
-
@swagger_type['properties'] = {}
|
36
|
-
when 'boolean'
|
37
|
-
@swagger_type['type'] = 'boolean'
|
38
|
-
when 'virtus::attribute::boolean'
|
39
|
-
@swagger_type['type'] = 'boolean'
|
40
|
-
when 'symbol'
|
41
|
-
@swagger_type['type'] = 'string'
|
42
|
-
when 'float'
|
43
|
-
@swagger_type['type'] = 'number'
|
44
|
-
@swagger_type['format'] = 'float'
|
45
|
-
when 'rack::multipart::uploadedfile'
|
46
|
-
@swagger_type['type'] = 'string'
|
47
|
-
STDERR.puts 'Warning - I have no idea how to handle the type file. Right now I will consider this a string, but we should probably handle it...'
|
48
|
-
when 'date'
|
49
|
-
@swagger_type['type'] = 'string'
|
50
|
-
@swagger_type['format'] = 'date'
|
51
|
-
when 'datetime'
|
52
|
-
@swagger_type['type'] = 'string'
|
53
|
-
@swagger_type['format'] = 'date-time'
|
54
|
-
else
|
23
|
+
def translate(with_definition)
|
24
|
+
swagger_type = {}
|
25
|
+
|
26
|
+
# basic type
|
27
|
+
if basic_type?
|
28
|
+
swagger_type = basic_type_schemes[@type.downcase]
|
55
29
|
|
30
|
+
# grape shorthand array eg. `Array[Integer]`
|
31
|
+
elsif short_hand_array?
|
32
|
+
swagger_type = shorthand_array_scheme
|
33
|
+
|
34
|
+
# representer or entity object
|
35
|
+
else
|
56
36
|
if with_definition
|
57
|
-
# I can just reference the name of the
|
58
|
-
|
59
|
-
|
37
|
+
# I can just reference the name of the representer here
|
38
|
+
swagger_type = {
|
39
|
+
'type' => 'object',
|
40
|
+
'$ref' => "#/definitions/#{@type}"
|
41
|
+
}
|
42
|
+
|
43
|
+
# grape-entity object
|
60
44
|
else
|
61
|
-
|
45
|
+
swagger_type = Swagger::Grape::Entity.new(@type).to_swagger
|
62
46
|
end
|
63
47
|
end
|
64
|
-
|
48
|
+
swagger_type
|
49
|
+
end
|
50
|
+
|
51
|
+
def short_hand_array?
|
52
|
+
!(@type.downcase =~ /\[[a-zA-Z]+\]/).nil?
|
53
|
+
end
|
54
|
+
|
55
|
+
def basic_type?
|
56
|
+
basic_type_schemes.key? @type.downcase
|
57
|
+
end
|
58
|
+
|
59
|
+
def shorthand_array_scheme
|
60
|
+
match = @type.downcase.match(/\[(.*?)\]/)
|
61
|
+
@swagger_type = {
|
62
|
+
'type' => 'array',
|
63
|
+
'items' => {
|
64
|
+
'type' => match[1]
|
65
|
+
}
|
66
|
+
}
|
67
|
+
end
|
68
|
+
|
69
|
+
def basic_type_schemes
|
70
|
+
{
|
71
|
+
'string' => {
|
72
|
+
'type' => 'string'
|
73
|
+
},
|
74
|
+
'integer' => {
|
75
|
+
'type' => 'integer'
|
76
|
+
},
|
77
|
+
'array' => {
|
78
|
+
'type' => 'array',
|
79
|
+
'items' => { 'type' => 'string' }
|
80
|
+
},
|
81
|
+
'hash' => {
|
82
|
+
'type' => 'object',
|
83
|
+
'properties' => {}
|
84
|
+
},
|
85
|
+
'boolean' => {
|
86
|
+
'type' => 'boolean'
|
87
|
+
},
|
88
|
+
'virtus::attribute::boolean' => {
|
89
|
+
'type' => 'boolean'
|
90
|
+
},
|
91
|
+
'symbol' => {
|
92
|
+
'type' => 'string'
|
93
|
+
},
|
94
|
+
'float' => {
|
95
|
+
'type' => 'number',
|
96
|
+
'format' => 'float'
|
97
|
+
},
|
98
|
+
'rack::multipart::uploadedfile' => {
|
99
|
+
'type' => 'string' # 'Warning - I have no idea how to handle the type file. Right now I will consider this a string, but we should probably handle it...'
|
100
|
+
},
|
101
|
+
'date' => {
|
102
|
+
'type' => 'string',
|
103
|
+
'format' => 'date'
|
104
|
+
},
|
105
|
+
'datetime' => {
|
106
|
+
'type' => 'string',
|
107
|
+
'format' => 'date-time'
|
108
|
+
}
|
109
|
+
|
110
|
+
}.freeze
|
65
111
|
end
|
66
112
|
end
|
67
113
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-swagger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luca Bonmassar
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|