ruby-swagger 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/ruby-swagger.rb +7 -0
- data/lib/ruby-swagger/data/contact.rb +49 -0
- data/lib/ruby-swagger/data/definitions.rb +49 -0
- data/lib/ruby-swagger/data/document.rb +181 -0
- data/lib/ruby-swagger/data/example.rb +29 -0
- data/lib/ruby-swagger/data/external_documentation.rb +24 -0
- data/lib/ruby-swagger/data/header.rb +34 -0
- data/lib/ruby-swagger/data/headers.rb +48 -0
- data/lib/ruby-swagger/data/info.rb +56 -0
- data/lib/ruby-swagger/data/items.rb +45 -0
- data/lib/ruby-swagger/data/license.rb +51 -0
- data/lib/ruby-swagger/data/mime.rb +31 -0
- data/lib/ruby-swagger/data/operation.rb +82 -0
- data/lib/ruby-swagger/data/parameter.rb +88 -0
- data/lib/ruby-swagger/data/parameters.rb +53 -0
- data/lib/ruby-swagger/data/path.rb +115 -0
- data/lib/ruby-swagger/data/paths.rb +50 -0
- data/lib/ruby-swagger/data/reference.rb +30 -0
- data/lib/ruby-swagger/data/response.rb +25 -0
- data/lib/ruby-swagger/data/responses.rb +50 -0
- data/lib/ruby-swagger/data/schema.rb +68 -0
- data/lib/ruby-swagger/data/scopes.rb +44 -0
- data/lib/ruby-swagger/data/security_definitions.rb +49 -0
- data/lib/ruby-swagger/data/security_requirement.rb +35 -0
- data/lib/ruby-swagger/data/security_scheme.rb +67 -0
- data/lib/ruby-swagger/data/tag.rb +24 -0
- data/lib/ruby-swagger/data/url.rb +26 -0
- data/lib/ruby-swagger/data/xml_object.rb +15 -0
- data/lib/ruby-swagger/grape/grape.rb +2 -0
- data/lib/ruby-swagger/grape/grape_config.rb +160 -0
- data/lib/ruby-swagger/grape/grape_presenter.rb +48 -0
- data/lib/ruby-swagger/grape/grape_template.rb +67 -0
- data/lib/ruby-swagger/grape/method.rb +295 -0
- data/lib/ruby-swagger/grape/param.rb +33 -0
- data/lib/ruby-swagger/grape/route_path.rb +37 -0
- data/lib/ruby-swagger/grape/routes.rb +52 -0
- data/lib/ruby-swagger/grape/type.rb +141 -0
- data/lib/ruby-swagger/io/comparable.rb +30 -0
- data/lib/ruby-swagger/io/definitions.rb +48 -0
- data/lib/ruby-swagger/io/file_system.rb +97 -0
- data/lib/ruby-swagger/io/paths.rb +55 -0
- data/lib/ruby-swagger/io/security.rb +45 -0
- data/lib/ruby-swagger/object.rb +67 -0
- data/lib/ruby-swagger/railtie.rb +7 -0
- data/lib/ruby-swagger/template.rb +29 -0
- data/lib/tasks/swagger.rake +125 -0
- metadata +176 -0
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'ruby-swagger/object'
|
2
|
+
require 'ruby-swagger/data/path'
|
3
|
+
|
4
|
+
module Swagger::Data
|
5
|
+
class Paths < Swagger::Object #https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#pathsObject
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@paths = {}
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.parse(paths)
|
12
|
+
raise (ArgumentError.new("Swagger::Data::Paths#parse - paths object is nil")) unless paths
|
13
|
+
raise (ArgumentError.new("Swagger::Data::Paths#parse - paths object is not an hash")) unless paths.is_a?(Hash)
|
14
|
+
|
15
|
+
pts = Swagger::Data::Paths.new
|
16
|
+
|
17
|
+
paths.each do |path, path_obj|
|
18
|
+
pts.add_path(path, path_obj)
|
19
|
+
end
|
20
|
+
|
21
|
+
pts
|
22
|
+
end
|
23
|
+
|
24
|
+
def add_path(path, path_obj)
|
25
|
+
raise ArgumentError.new("Swagger::Data::Paths#parse - path is nil") if path.nil? || path.empty?
|
26
|
+
raise ArgumentError.new("Swagger::Data::Paths#parse - path object is nil") if path_obj.nil?
|
27
|
+
|
28
|
+
unless path_obj.is_a?(Swagger::Data::Path)
|
29
|
+
path_obj = Swagger::Data::Path.parse(path_obj)
|
30
|
+
end
|
31
|
+
|
32
|
+
@paths[path] = path_obj
|
33
|
+
end
|
34
|
+
|
35
|
+
def [](path)
|
36
|
+
@paths[path]
|
37
|
+
end
|
38
|
+
|
39
|
+
def to_swagger
|
40
|
+
swag_obj = {}
|
41
|
+
|
42
|
+
@paths.each do |path, path_obj|
|
43
|
+
swag_obj[path] = path_obj.to_swagger
|
44
|
+
end
|
45
|
+
|
46
|
+
swag_obj
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'ruby-swagger/object'
|
2
|
+
|
3
|
+
module Swagger::Data
|
4
|
+
class Reference < Swagger::Object #https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#referenceObject
|
5
|
+
|
6
|
+
@ref = nil
|
7
|
+
|
8
|
+
def self.parse(reference)
|
9
|
+
return nil unless reference
|
10
|
+
|
11
|
+
r = Swagger::Data::Reference.new
|
12
|
+
r.ref = reference['$ref']
|
13
|
+
r
|
14
|
+
end
|
15
|
+
|
16
|
+
def ref=(new_ref)
|
17
|
+
raise (ArgumentError.new("Swagger::Data::Reference#ref= $ref is nil")) unless new_ref
|
18
|
+
@ref = new_ref
|
19
|
+
end
|
20
|
+
|
21
|
+
def ref
|
22
|
+
@ref
|
23
|
+
end
|
24
|
+
|
25
|
+
def as_swagger
|
26
|
+
@ref.nil? ? {} : { '$ref' => @ref }
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'ruby-swagger/object'
|
2
|
+
require 'ruby-swagger/data/schema'
|
3
|
+
require 'ruby-swagger/data/headers'
|
4
|
+
require 'ruby-swagger/data/example'
|
5
|
+
|
6
|
+
module Swagger::Data
|
7
|
+
class Response < Swagger::Object # https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#responseObject
|
8
|
+
|
9
|
+
attr_swagger :description, :schema, :headers, :examples
|
10
|
+
|
11
|
+
def self.parse(response)
|
12
|
+
return nil unless response
|
13
|
+
|
14
|
+
r = Swagger::Data::Response.new
|
15
|
+
|
16
|
+
r.description = response['description']
|
17
|
+
r.schema = Swagger::Data::Schema.parse(response['schema'])
|
18
|
+
r.headers = Swagger::Data::Headers.parse(response['headers'])
|
19
|
+
r.examples = Swagger::Data::Example.parse(response['examples'])
|
20
|
+
|
21
|
+
r
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'ruby-swagger/object'
|
2
|
+
require 'ruby-swagger/data/reference'
|
3
|
+
require 'ruby-swagger/data/response'
|
4
|
+
|
5
|
+
module Swagger::Data
|
6
|
+
class Responses < Swagger::Object # https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#responsesObject
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@responses = {}
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.parse(responses)
|
13
|
+
return nil unless responses
|
14
|
+
|
15
|
+
r = Swagger::Data::Responses.new
|
16
|
+
|
17
|
+
responses.each do |response_key, response_value|
|
18
|
+
r.add_response(response_key, response_value)
|
19
|
+
end
|
20
|
+
|
21
|
+
r
|
22
|
+
end
|
23
|
+
|
24
|
+
def add_response(response_code, response)
|
25
|
+
raise ArgumentError.new('Swagger::Data::Responses#add_response - response is nil') unless response
|
26
|
+
|
27
|
+
if !response.is_a?(Swagger::Data::Reference) && !response.is_a?(Swagger::Data::Response)
|
28
|
+
# it's a reference object or it's a parameter object
|
29
|
+
response = response['$ref'] ? Swagger::Data::Reference.parse(response) : Swagger::Data::Response.parse(response)
|
30
|
+
end
|
31
|
+
|
32
|
+
@responses[response_code] = response
|
33
|
+
end
|
34
|
+
|
35
|
+
def [](key)
|
36
|
+
@responses[key]
|
37
|
+
end
|
38
|
+
|
39
|
+
def as_swagger
|
40
|
+
res = {}
|
41
|
+
|
42
|
+
@responses.each do |other_name, other_value|
|
43
|
+
res[other_name] = other_value.to_swagger
|
44
|
+
end
|
45
|
+
|
46
|
+
res
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'ruby-swagger/object'
|
2
|
+
require 'ruby-swagger/data/reference'
|
3
|
+
require 'ruby-swagger/data/xml_object'
|
4
|
+
require 'ruby-swagger/data/external_documentation'
|
5
|
+
|
6
|
+
module Swagger::Data
|
7
|
+
class Schema < Swagger::Object #https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#schemaObject
|
8
|
+
|
9
|
+
attr_swagger :discriminator, :readOnly, :xml, :externalDocs, :example,
|
10
|
+
:format, :title, :description, :default,
|
11
|
+
:multipleOf, :maximum, :exclusiveMaximum, :minimum,
|
12
|
+
:exclusiveMinimum, :maxLength, :minLength,
|
13
|
+
:pattern, :maxItems, :minItems, :uniqueItems, :maxProperties,
|
14
|
+
:minProperties, :required, :enum, :type, :items, :allOf,
|
15
|
+
:properties, :additionalProperties
|
16
|
+
|
17
|
+
attr_reader :ref
|
18
|
+
|
19
|
+
def self.parse(schema)
|
20
|
+
return nil if schema.nil?
|
21
|
+
|
22
|
+
sc = Swagger::Data::Schema.new.bulk_set(schema)
|
23
|
+
sc.ref= schema['$ref']
|
24
|
+
sc
|
25
|
+
end
|
26
|
+
|
27
|
+
def ref=(new_ref)
|
28
|
+
return nil unless new_ref
|
29
|
+
|
30
|
+
@ref = new_ref
|
31
|
+
end
|
32
|
+
|
33
|
+
def externalDocs=(new_doc)
|
34
|
+
return nil unless new_doc
|
35
|
+
|
36
|
+
if !new_doc.is_a?(Swagger::Data::ExternalDocumentation)
|
37
|
+
new_doc = Swagger::Data::ExternalDocumentation.parse(new_doc)
|
38
|
+
end
|
39
|
+
|
40
|
+
@externalDocs = new_doc
|
41
|
+
end
|
42
|
+
|
43
|
+
def xml=(new_xml)
|
44
|
+
return nil unless new_xml
|
45
|
+
|
46
|
+
if !new_xml.is_a?(Swagger::Data::XMLObject)
|
47
|
+
new_xml = Swagger::Data::XMLObject.parse(new_xml)
|
48
|
+
end
|
49
|
+
|
50
|
+
@xml = new_xml
|
51
|
+
end
|
52
|
+
|
53
|
+
def []=(attrib, value)
|
54
|
+
self.send("#{attrib}=", value)
|
55
|
+
end
|
56
|
+
|
57
|
+
def [](attrib)
|
58
|
+
self.send("#{attrib}")
|
59
|
+
end
|
60
|
+
|
61
|
+
def as_swagger
|
62
|
+
res = super
|
63
|
+
res['$ref'] = @ref if @ref
|
64
|
+
res
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'ruby-swagger/object'
|
2
|
+
|
3
|
+
module Swagger::Data
|
4
|
+
class Scopes < Swagger::Object #https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#scopesObject
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@scopes = {}
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.parse(scopes)
|
11
|
+
return nil unless scopes
|
12
|
+
|
13
|
+
scope = Swagger::Data::Scopes.new
|
14
|
+
|
15
|
+
scopes.each do |scope_name, scope_value|
|
16
|
+
scope.add_scope(scope_name, scope_value)
|
17
|
+
end
|
18
|
+
|
19
|
+
scope
|
20
|
+
end
|
21
|
+
|
22
|
+
def add_scope(scope_name, scope_value)
|
23
|
+
raise ArgumentError.new("Swagger::Data::Scopes#add_scope - scope_name is nil") unless scope_name
|
24
|
+
raise ArgumentError.new("Swagger::Data::Scopes#add_scope - scope_value is nil") unless scope_value
|
25
|
+
|
26
|
+
@scopes[scope_name] = scope_value
|
27
|
+
end
|
28
|
+
|
29
|
+
def [](scope)
|
30
|
+
@scopes[scope]
|
31
|
+
end
|
32
|
+
|
33
|
+
def as_swagger
|
34
|
+
swagger_scopes = {}
|
35
|
+
|
36
|
+
@scopes.each do |scope_k, scope_v|
|
37
|
+
swagger_scopes[scope_k] = scope_v
|
38
|
+
end
|
39
|
+
|
40
|
+
swagger_scopes
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'ruby-swagger/object'
|
2
|
+
require 'ruby-swagger/data/security_scheme'
|
3
|
+
|
4
|
+
module Swagger::Data
|
5
|
+
class SecurityDefinitions < Swagger::Object #https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#securityDefinitionsObject
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@security = {}
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.parse(security)
|
12
|
+
return nil unless security
|
13
|
+
|
14
|
+
params = Swagger::Data::SecurityDefinitions.new
|
15
|
+
|
16
|
+
security.each do |pname, pvalue|
|
17
|
+
params.add_param(pname, pvalue)
|
18
|
+
end
|
19
|
+
|
20
|
+
params
|
21
|
+
end
|
22
|
+
|
23
|
+
def add_param(pname, pvalue)
|
24
|
+
raise ArgumentError.new("Swagger::Data::SecurityDefinitions#add_param - parameter name is nil") unless pname
|
25
|
+
raise ArgumentError.new("Swagger::Data::SecurityDefinitions#add_param - parameter value is nil") unless pvalue
|
26
|
+
|
27
|
+
if !pvalue.is_a?(Swagger::Data::SecurityScheme)
|
28
|
+
pvalue = Swagger::Data::SecurityScheme.parse(pvalue)
|
29
|
+
end
|
30
|
+
|
31
|
+
@security[pname] = pvalue
|
32
|
+
end
|
33
|
+
|
34
|
+
def [](pname)
|
35
|
+
@security[pname]
|
36
|
+
end
|
37
|
+
|
38
|
+
def as_swagger
|
39
|
+
swagger_params = {}
|
40
|
+
|
41
|
+
@security.each do |p_k, p_v|
|
42
|
+
swagger_params[p_k] = p_v.to_swagger
|
43
|
+
end
|
44
|
+
|
45
|
+
swagger_params
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'ruby-swagger/object'
|
2
|
+
|
3
|
+
module Swagger::Data
|
4
|
+
class SecurityRequirement < Swagger::Object #https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#securityRequirementObject
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@requirements = {}
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.parse(security)
|
11
|
+
return nil unless security
|
12
|
+
|
13
|
+
s = Swagger::Data::SecurityRequirement.new
|
14
|
+
security.each {|key, reqs| s.add_requirement(key, reqs)}
|
15
|
+
s
|
16
|
+
end
|
17
|
+
|
18
|
+
def add_requirement(key, requirements)
|
19
|
+
raise (ArgumentError.new("Swagger::Data::SecurityRequirement#add_requirement - key is nil")) unless key
|
20
|
+
raise (ArgumentError.new("Swagger::Data::SecurityRequirement#add_requirement - requirements is nil")) unless requirements
|
21
|
+
raise (ArgumentError.new("Swagger::Data::SecurityRequirement#add_requirement - requirements is not an array")) unless requirements.is_a?(Array)
|
22
|
+
|
23
|
+
@requirements[key] = requirements
|
24
|
+
end
|
25
|
+
|
26
|
+
def [](key)
|
27
|
+
@requirements[key]
|
28
|
+
end
|
29
|
+
|
30
|
+
def as_swagger
|
31
|
+
@requirements
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'ruby-swagger/object'
|
2
|
+
require 'ruby-swagger/data/scopes'
|
3
|
+
|
4
|
+
module Swagger::Data
|
5
|
+
class SecurityScheme < Swagger::Object #https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#securitySchemeObject
|
6
|
+
|
7
|
+
attr_swagger :type, :description, :name, :in, :flow, :authorizationUrl, :tokenUrl, :scopes
|
8
|
+
|
9
|
+
def self.parse(security)
|
10
|
+
return nil unless security
|
11
|
+
|
12
|
+
Swagger::Data::SecurityScheme.new.bulk_set(security)
|
13
|
+
end
|
14
|
+
|
15
|
+
def type=(new_type)
|
16
|
+
raise ArgumentError.new("Security::Data::SecurityScheme#type= - type is nil") unless new_type
|
17
|
+
raise ArgumentError.new("Security::Data::SecurityScheme#type= - unrecognized type #{new_type}") unless %w(basic apiKey oauth2).include?(new_type)
|
18
|
+
|
19
|
+
@type = new_type
|
20
|
+
end
|
21
|
+
|
22
|
+
def name=(new_name)
|
23
|
+
raise ArgumentError.new("Security::Data::SecurityScheme#name= - name is nil") if @type == 'apiKey' && !new_name
|
24
|
+
|
25
|
+
@name = new_name
|
26
|
+
end
|
27
|
+
|
28
|
+
def in=(new_in)
|
29
|
+
if @type == 'apiKey'
|
30
|
+
raise ArgumentError.new("Security::Data::SecurityScheme#in= - in is nil") if !new_in
|
31
|
+
raise ArgumentError.new("Security::Data::SecurityScheme#in= - unrecognized in #{new_in}") unless %w(query header).include?(new_in)
|
32
|
+
end
|
33
|
+
|
34
|
+
@in = new_in
|
35
|
+
end
|
36
|
+
|
37
|
+
def flow=(new_flow)
|
38
|
+
if @type == 'oauth2'
|
39
|
+
raise ArgumentError.new("Security::Data::SecurityScheme#flow= - flow is nil") if !new_flow
|
40
|
+
raise ArgumentError.new("Security::Data::SecurityScheme#flow= - unrecognized flow #{new_flow}") unless %w(implicit password application accessCode).include?(new_flow)
|
41
|
+
end
|
42
|
+
|
43
|
+
@flow = new_flow
|
44
|
+
end
|
45
|
+
|
46
|
+
def authorizationUrl=(new_authorizationUrl)
|
47
|
+
raise ArgumentError.new("Security::Data::SecurityScheme#authorizationUrl= - authorizationUrl is nil") if @type == 'oauth2' && (@flow == 'implicit' || @flow == 'accessCode') && !new_authorizationUrl
|
48
|
+
|
49
|
+
@authorizationUrl = new_authorizationUrl
|
50
|
+
end
|
51
|
+
|
52
|
+
def tokenUrl=(new_tokenUrl)
|
53
|
+
raise ArgumentError.new("Security::Data::SecurityScheme#tokenUrl= - tokenUrl is nil") if @type == 'oauth2' && (@flow == 'password' || @flow == 'application' || @flow == 'accessCode') && !new_tokenUrl
|
54
|
+
|
55
|
+
@tokenUrl = new_tokenUrl
|
56
|
+
end
|
57
|
+
|
58
|
+
def scopes=(new_scopes)
|
59
|
+
raise ArgumentError.new("Security::Data::SecurityScheme#scopes= - scopes is nil") if @type == 'oauth2' && !new_scopes
|
60
|
+
|
61
|
+
new_scopes = Swagger::Data::Scopes.parse(new_scopes) if(!new_scopes.is_a?(Swagger::Data::Scopes))
|
62
|
+
|
63
|
+
@scopes = new_scopes
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'ruby-swagger/object'
|
2
|
+
require 'ruby-swagger/data/external_documentation'
|
3
|
+
|
4
|
+
module Swagger::Data
|
5
|
+
class Tag < Swagger::Object #https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#tag-object
|
6
|
+
|
7
|
+
attr_swagger :name, :description, :externalDocs
|
8
|
+
|
9
|
+
def self.parse(xml_object)
|
10
|
+
return nil unless xml_object
|
11
|
+
|
12
|
+
Swagger::Data::Tag.new.bulk_set(xml_object)
|
13
|
+
end
|
14
|
+
|
15
|
+
def externalDocs=(newDoc)
|
16
|
+
return nil unless newDoc
|
17
|
+
|
18
|
+
newDoc = Swagger::Data::ExternalDocumentation.parse(newDoc) unless newDoc.is_a?(Swagger::Data::ExternalDocumentation)
|
19
|
+
|
20
|
+
@externalDocs=newDoc
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|