ruby-swagger 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ruby-swagger.rb +1 -5
  3. data/lib/ruby-swagger/data/contact.rb +3 -8
  4. data/lib/ruby-swagger/data/definitions.rb +5 -7
  5. data/lib/ruby-swagger/data/document.rb +22 -24
  6. data/lib/ruby-swagger/data/example.rb +3 -5
  7. data/lib/ruby-swagger/data/external_documentation.rb +4 -6
  8. data/lib/ruby-swagger/data/header.rb +2 -4
  9. data/lib/ruby-swagger/data/headers.rb +5 -8
  10. data/lib/ruby-swagger/data/info.rb +6 -8
  11. data/lib/ruby-swagger/data/items.rb +4 -6
  12. data/lib/ruby-swagger/data/license.rb +4 -6
  13. data/lib/ruby-swagger/data/mime.rb +0 -2
  14. data/lib/ruby-swagger/data/operation.rb +7 -9
  15. data/lib/ruby-swagger/data/parameter.rb +4 -10
  16. data/lib/ruby-swagger/data/parameters.rb +4 -6
  17. data/lib/ruby-swagger/data/path.rb +14 -18
  18. data/lib/ruby-swagger/data/paths.rb +5 -7
  19. data/lib/ruby-swagger/data/reference.rb +4 -8
  20. data/lib/ruby-swagger/data/response.rb +1 -3
  21. data/lib/ruby-swagger/data/responses.rb +1 -3
  22. data/lib/ruby-swagger/data/schema.rb +7 -9
  23. data/lib/ruby-swagger/data/scopes.rb +4 -6
  24. data/lib/ruby-swagger/data/security_definitions.rb +5 -7
  25. data/lib/ruby-swagger/data/security_requirement.rb +6 -8
  26. data/lib/ruby-swagger/data/security_scheme.rb +10 -12
  27. data/lib/ruby-swagger/data/tag.rb +3 -5
  28. data/lib/ruby-swagger/data/url.rb +1 -3
  29. data/lib/ruby-swagger/data/xml_object.rb +2 -4
  30. data/lib/ruby-swagger/grape/entity.rb +41 -0
  31. data/lib/ruby-swagger/grape/entity_exposure.rb +96 -0
  32. data/lib/ruby-swagger/grape/entity_nesting_exposure.rb +38 -0
  33. data/lib/ruby-swagger/grape/grape.rb +1 -1
  34. data/lib/ruby-swagger/grape/grape_config.rb +19 -22
  35. data/lib/ruby-swagger/grape/grape_presenter.rb +6 -9
  36. data/lib/ruby-swagger/grape/grape_template.rb +3 -5
  37. data/lib/ruby-swagger/grape/method.rb +79 -71
  38. data/lib/ruby-swagger/grape/param.rb +3 -3
  39. data/lib/ruby-swagger/grape/route_path.rb +1 -3
  40. data/lib/ruby-swagger/grape/routes.rb +6 -9
  41. data/lib/ruby-swagger/grape/type.rb +46 -119
  42. data/lib/ruby-swagger/io/comparable.rb +13 -16
  43. data/lib/ruby-swagger/io/definitions.rb +5 -11
  44. data/lib/ruby-swagger/io/file_system.rb +8 -9
  45. data/lib/ruby-swagger/io/paths.rb +6 -11
  46. data/lib/ruby-swagger/io/security.rb +3 -6
  47. data/lib/ruby-swagger/object.rb +5 -7
  48. data/lib/ruby-swagger/railtie.rb +1 -1
  49. data/lib/ruby-swagger/template.rb +2 -4
  50. data/lib/tasks/swagger.rake +13 -18
  51. metadata +10 -7
@@ -2,8 +2,7 @@ require 'ruby-swagger/data/url'
2
2
  require 'ruby-swagger/object'
3
3
 
4
4
  module Swagger::Data
5
- class License < Swagger::Object #https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#license-object
6
-
5
+ class License < Swagger::Object # https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#license-object
7
6
  DEFAULT_NAME = 'Apache 2.0'
8
7
  DEFAULT_URL = 'http://www.apache.org/licenses/LICENSE-2.0.html'
9
8
 
@@ -21,7 +20,7 @@ module Swagger::Data
21
20
  end
22
21
 
23
22
  def name=(new_name)
24
- raise (ArgumentError.new("Swagger::Data::License - license name is invalid ")) if new_name.nil? || new_name.empty?
23
+ raise ArgumentError.new('Swagger::Data::License - license name is invalid ') if new_name.nil? || new_name.empty?
25
24
  @name = new_name
26
25
  end
27
26
 
@@ -44,8 +43,7 @@ module Swagger::Data
44
43
  private
45
44
 
46
45
  def validate_url!
47
- raise (ArgumentError.new("Swagger::Data::License - contact url is invalid")) unless @url.valid?
46
+ raise ArgumentError.new('Swagger::Data::License - contact url is invalid') unless @url.valid?
48
47
  end
49
-
50
48
  end
51
- end
49
+ end
@@ -1,6 +1,5 @@
1
1
  module Swagger::Data
2
2
  class Mime
3
-
4
3
  @@types = [
5
4
  'text/plain',
6
5
  'text/plain; charset=utf-8',
@@ -28,6 +27,5 @@ module Swagger::Data
28
27
  def self.valid?(type)
29
28
  @@types.include?(type)
30
29
  end
31
-
32
30
  end
33
31
  end
@@ -4,8 +4,7 @@ require 'ruby-swagger/data/responses'
4
4
  require 'ruby-swagger/data/security_requirement'
5
5
 
6
6
  module Swagger::Data
7
- class Operation < Swagger::Object #https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#operationObject
8
-
7
+ class Operation < Swagger::Object # https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#operationObject
9
8
  attr_swagger :tags, :summary, :description, :externalDocs, :operationId,
10
9
  :consumes, :produces, :parameters, :responses,
11
10
  :schemes, :deprecated, :security
@@ -23,7 +22,7 @@ module Swagger::Data
23
22
  newDoc = Swagger::Data::ExternalDocumentation.parse(newDoc)
24
23
  end
25
24
 
26
- @externalDocs=newDoc
25
+ @externalDocs = newDoc
27
26
  end
28
27
 
29
28
  def responses=(newResp)
@@ -66,17 +65,16 @@ module Swagger::Data
66
65
  if new_parameter.is_a?(Hash)
67
66
 
68
67
  new_parameter = if new_parameter['$ref']
69
- #it's a reference object
70
- Swagger::Data::Reference.parse(new_parameter)
68
+ # it's a reference object
69
+ Swagger::Data::Reference.parse(new_parameter)
71
70
  else
72
- #it's a parameter object
73
- Swagger::Data::Parameter.parse(new_parameter)
71
+ # it's a parameter object
72
+ Swagger::Data::Parameter.parse(new_parameter)
74
73
  end
75
74
 
76
75
  end
77
76
 
78
77
  @parameters.push(new_parameter)
79
78
  end
80
-
81
79
  end
82
- end
80
+ end
@@ -5,7 +5,6 @@ require 'ruby-swagger/grape/param'
5
5
 
6
6
  module Swagger::Data
7
7
  class Parameter < Swagger::Object # https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#parameter-object
8
-
9
8
  attr_swagger :name, :in, :description, :required, :schema,
10
9
  :type, :format, :allowEmptyValue, :items,
11
10
  :collectionFormat, :default, :maximum,
@@ -46,7 +45,7 @@ module Swagger::Data
46
45
  end
47
46
 
48
47
  def items=(new_items)
49
- raise ArgumentError.new("Swagger::Data::Parameter#items= items is nil") if new_items.nil? && @type == 'array'
48
+ raise ArgumentError.new('Swagger::Data::Parameter#items= items is nil') if new_items.nil? && @type == 'array'
50
49
  if !new_items.nil? && !new_items.is_a?(Swagger::Data::Items)
51
50
  new_items = Swagger::Data::Items.parse(new_items)
52
51
  end
@@ -60,8 +59,8 @@ module Swagger::Data
60
59
  grape_type = Swagger::Grape::Param.new(grape_parameter.last).to_swagger
61
60
 
62
61
  parameter = Swagger::Data::Parameter.new
63
- parameter.name= grape_parameter.first
64
- parameter.in= 'formData'
62
+ parameter.name = grape_parameter.first
63
+ parameter.in = 'formData'
65
64
  parameter.description = grape_type['description']
66
65
  parameter.required = grape_type['required']
67
66
  parameter.default = grape_type['default']
@@ -79,10 +78,5 @@ module Swagger::Data
79
78
  puts "error processing parameter #{grape_parameter} [#{e}]"
80
79
  raise e
81
80
  end
82
-
83
- private
84
-
85
-
86
-
87
81
  end
88
- end
82
+ end
@@ -3,7 +3,6 @@ require 'ruby-swagger/data/parameter'
3
3
 
4
4
  module Swagger::Data
5
5
  class Parameters < Swagger::Object # https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#parametersDefinitionsObject
6
-
7
6
  def initialize
8
7
  @parameters = {}
9
8
  end
@@ -21,10 +20,10 @@ module Swagger::Data
21
20
  end
22
21
 
23
22
  def add_param(pname, pvalue)
24
- raise ArgumentError.new("Swagger::Data::Parameters#add_param - parameter name is nil") unless pname
25
- raise ArgumentError.new("Swagger::Data::Parameters#add_param - parameter value is nil") unless pvalue
23
+ raise ArgumentError.new('Swagger::Data::Parameters#add_param - parameter name is nil') unless pname
24
+ raise ArgumentError.new('Swagger::Data::Parameters#add_param - parameter value is nil') unless pvalue
26
25
 
27
- if !pvalue.is_a?(Swagger::Data::Parameter)
26
+ unless pvalue.is_a?(Swagger::Data::Parameter)
28
27
  pvalue = Swagger::Data::Parameter.parse(pvalue)
29
28
  end
30
29
 
@@ -48,6 +47,5 @@ module Swagger::Data
48
47
 
49
48
  swagger_params
50
49
  end
51
-
52
50
  end
53
- end
51
+ end
@@ -4,16 +4,15 @@ require 'ruby-swagger/data/parameter'
4
4
  require 'ruby-swagger/data/reference'
5
5
 
6
6
  module Swagger::Data
7
- class Path < Swagger::Object #https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#path-item-object
8
-
9
- attr_swagger :get, :put, :post, :delete, :options, :head, :patch, :parameters #and $ref
7
+ class Path < Swagger::Object # https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#path-item-object
8
+ attr_swagger :get, :put, :post, :delete, :options, :head, :patch, :parameters # and $ref
10
9
  @ref = nil
11
10
 
12
11
  def self.parse(path)
13
- raise (ArgumentError.new("Swagger::Data::Path - path is nil")) unless path
12
+ raise ArgumentError.new('Swagger::Data::Path - path is nil') unless path
14
13
 
15
14
  res = Swagger::Data::Path.new.bulk_set(path)
16
- res.ref= path['$ref'] if path['$ref']
15
+ res.ref = path['$ref'] if path['$ref']
17
16
  res
18
17
  end
19
18
 
@@ -39,7 +38,7 @@ module Swagger::Data
39
38
  unless new_post.is_a?(Swagger::Data::Operation)
40
39
  new_post = Swagger::Data::Operation.parse(new_post)
41
40
  end
42
- @post= new_post
41
+ @post = new_post
43
42
  end
44
43
 
45
44
  def delete=(new_delete)
@@ -47,7 +46,7 @@ module Swagger::Data
47
46
  unless new_delete.is_a?(Swagger::Data::Operation)
48
47
  new_delete = Swagger::Data::Operation.parse(new_delete)
49
48
  end
50
- @delete= new_delete
49
+ @delete = new_delete
51
50
  end
52
51
 
53
52
  def options=(new_options)
@@ -55,7 +54,7 @@ module Swagger::Data
55
54
  unless new_options.is_a?(Swagger::Data::Operation)
56
55
  new_options = Swagger::Data::Operation.parse(new_options)
57
56
  end
58
- @options= new_options
57
+ @options = new_options
59
58
  end
60
59
 
61
60
  def head=(new_head)
@@ -64,7 +63,7 @@ module Swagger::Data
64
63
  new_head = Swagger::Data::Operation.parse(new_head)
65
64
  end
66
65
 
67
- @head= new_head
66
+ @head = new_head
68
67
  end
69
68
 
70
69
  def patch=(new_patch)
@@ -72,39 +71,36 @@ module Swagger::Data
72
71
  unless new_patch.is_a?(Swagger::Data::Operation)
73
72
  new_patch = Swagger::Data::Operation.parse(new_patch)
74
73
  end
75
- @patch= new_patch
74
+ @patch = new_patch
76
75
  end
77
76
 
78
77
  def parameters=(new_parameters)
79
78
  return nil unless new_parameters
80
- raise (ArgumentError.new("Swagger::Data::Path#parameters= - parameters is not an array")) unless new_parameters.is_a?(Array)
79
+ raise ArgumentError.new('Swagger::Data::Path#parameters= - parameters is not an array') unless new_parameters.is_a?(Array)
81
80
 
82
81
  @parameters = []
83
82
 
84
83
  new_parameters.each do |parameter|
85
84
  new_param = if parameter['$ref']
86
- #it's a reference object
85
+ # it's a reference object
87
86
  Swagger::Data::Reference.parse(parameter)
88
87
  else
89
- #it's a parameter object
88
+ # it's a parameter object
90
89
  Swagger::Data::Parameter.parse(parameter)
91
90
  end
92
91
 
93
92
  @parameters.push(new_param)
94
93
  end
95
-
96
94
  end
97
95
 
98
96
  def ref=(new_ref)
99
97
  return nil unless new_ref
100
- raise (ArgumentError.new("Swagger::Data::Path#ref= - $ref is not a string")) unless new_ref.is_a?(String)
98
+ raise ArgumentError.new('Swagger::Data::Path#ref= - $ref is not a string') unless new_ref.is_a?(String)
101
99
 
102
100
  @ref = new_ref
103
101
  end
104
102
 
105
- def ref
106
- @ref
107
- end
103
+ attr_reader :ref
108
104
 
109
105
  def as_swagger
110
106
  res = super
@@ -2,15 +2,14 @@ require 'ruby-swagger/object'
2
2
  require 'ruby-swagger/data/path'
3
3
 
4
4
  module Swagger::Data
5
- class Paths < Swagger::Object #https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#pathsObject
6
-
5
+ class Paths < Swagger::Object # https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#pathsObject
7
6
  def initialize
8
7
  @paths = {}
9
8
  end
10
9
 
11
10
  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)
11
+ raise ArgumentError.new('Swagger::Data::Paths#parse - paths object is nil') unless paths
12
+ raise ArgumentError.new('Swagger::Data::Paths#parse - paths object is not an hash') unless paths.is_a?(Hash)
14
13
 
15
14
  pts = Swagger::Data::Paths.new
16
15
 
@@ -22,8 +21,8 @@ module Swagger::Data
22
21
  end
23
22
 
24
23
  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?
24
+ raise ArgumentError.new('Swagger::Data::Paths#parse - path is nil') if path.nil? || path.empty?
25
+ raise ArgumentError.new('Swagger::Data::Paths#parse - path object is nil') if path_obj.nil?
27
26
 
28
27
  unless path_obj.is_a?(Swagger::Data::Path)
29
28
  path_obj = Swagger::Data::Path.parse(path_obj)
@@ -45,6 +44,5 @@ module Swagger::Data
45
44
 
46
45
  swag_obj
47
46
  end
48
-
49
47
  end
50
48
  end
@@ -1,8 +1,7 @@
1
1
  require 'ruby-swagger/object'
2
2
 
3
3
  module Swagger::Data
4
- class Reference < Swagger::Object #https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#referenceObject
5
-
4
+ class Reference < Swagger::Object # https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#referenceObject
6
5
  @ref = nil
7
6
 
8
7
  def self.parse(reference)
@@ -14,17 +13,14 @@ module Swagger::Data
14
13
  end
15
14
 
16
15
  def ref=(new_ref)
17
- raise (ArgumentError.new("Swagger::Data::Reference#ref= $ref is nil")) unless new_ref
16
+ raise ArgumentError.new('Swagger::Data::Reference#ref= $ref is nil') unless new_ref
18
17
  @ref = new_ref
19
18
  end
20
19
 
21
- def ref
22
- @ref
23
- end
20
+ attr_reader :ref
24
21
 
25
22
  def as_swagger
26
23
  @ref.nil? ? {} : { '$ref' => @ref }
27
24
  end
28
-
29
25
  end
30
- end
26
+ end
@@ -5,7 +5,6 @@ require 'ruby-swagger/data/example'
5
5
 
6
6
  module Swagger::Data
7
7
  class Response < Swagger::Object # https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#responseObject
8
-
9
8
  attr_swagger :description, :schema, :headers, :examples
10
9
 
11
10
  def self.parse(response)
@@ -20,6 +19,5 @@ module Swagger::Data
20
19
 
21
20
  r
22
21
  end
23
-
24
22
  end
25
- end
23
+ end
@@ -4,7 +4,6 @@ require 'ruby-swagger/data/response'
4
4
 
5
5
  module Swagger::Data
6
6
  class Responses < Swagger::Object # https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#responsesObject
7
-
8
7
  def initialize
9
8
  @responses = {}
10
9
  end
@@ -45,6 +44,5 @@ module Swagger::Data
45
44
 
46
45
  res
47
46
  end
48
-
49
47
  end
50
- end
48
+ end
@@ -4,8 +4,7 @@ require 'ruby-swagger/data/xml_object'
4
4
  require 'ruby-swagger/data/external_documentation'
5
5
 
6
6
  module Swagger::Data
7
- class Schema < Swagger::Object #https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#schemaObject
8
-
7
+ class Schema < Swagger::Object # https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#schemaObject
9
8
  attr_swagger :discriminator, :readOnly, :xml, :externalDocs, :example,
10
9
  :format, :title, :description, :default,
11
10
  :multipleOf, :maximum, :exclusiveMaximum, :minimum,
@@ -20,7 +19,7 @@ module Swagger::Data
20
19
  return nil if schema.nil?
21
20
 
22
21
  sc = Swagger::Data::Schema.new.bulk_set(schema)
23
- sc.ref= schema['$ref']
22
+ sc.ref = schema['$ref']
24
23
  sc
25
24
  end
26
25
 
@@ -33,7 +32,7 @@ module Swagger::Data
33
32
  def externalDocs=(new_doc)
34
33
  return nil unless new_doc
35
34
 
36
- if !new_doc.is_a?(Swagger::Data::ExternalDocumentation)
35
+ unless new_doc.is_a?(Swagger::Data::ExternalDocumentation)
37
36
  new_doc = Swagger::Data::ExternalDocumentation.parse(new_doc)
38
37
  end
39
38
 
@@ -43,7 +42,7 @@ module Swagger::Data
43
42
  def xml=(new_xml)
44
43
  return nil unless new_xml
45
44
 
46
- if !new_xml.is_a?(Swagger::Data::XMLObject)
45
+ unless new_xml.is_a?(Swagger::Data::XMLObject)
47
46
  new_xml = Swagger::Data::XMLObject.parse(new_xml)
48
47
  end
49
48
 
@@ -51,11 +50,11 @@ module Swagger::Data
51
50
  end
52
51
 
53
52
  def []=(attrib, value)
54
- self.send("#{attrib}=", value)
53
+ send("#{attrib}=", value)
55
54
  end
56
55
 
57
56
  def [](attrib)
58
- self.send("#{attrib}")
57
+ send("#{attrib}")
59
58
  end
60
59
 
61
60
  def as_swagger
@@ -63,6 +62,5 @@ module Swagger::Data
63
62
  res['$ref'] = @ref if @ref
64
63
  res
65
64
  end
66
-
67
65
  end
68
- end
66
+ end
@@ -1,8 +1,7 @@
1
1
  require 'ruby-swagger/object'
2
2
 
3
3
  module Swagger::Data
4
- class Scopes < Swagger::Object #https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#scopesObject
5
-
4
+ class Scopes < Swagger::Object # https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#scopesObject
6
5
  def initialize
7
6
  @scopes = {}
8
7
  end
@@ -20,8 +19,8 @@ module Swagger::Data
20
19
  end
21
20
 
22
21
  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
22
+ raise ArgumentError.new('Swagger::Data::Scopes#add_scope - scope_name is nil') unless scope_name
23
+ raise ArgumentError.new('Swagger::Data::Scopes#add_scope - scope_value is nil') unless scope_value
25
24
 
26
25
  @scopes[scope_name] = scope_value
27
26
  end
@@ -39,6 +38,5 @@ module Swagger::Data
39
38
 
40
39
  swagger_scopes
41
40
  end
42
-
43
41
  end
44
- end
42
+ end
@@ -2,8 +2,7 @@ require 'ruby-swagger/object'
2
2
  require 'ruby-swagger/data/security_scheme'
3
3
 
4
4
  module Swagger::Data
5
- class SecurityDefinitions < Swagger::Object #https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#securityDefinitionsObject
6
-
5
+ class SecurityDefinitions < Swagger::Object # https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#securityDefinitionsObject
7
6
  def initialize
8
7
  @security = {}
9
8
  end
@@ -21,10 +20,10 @@ module Swagger::Data
21
20
  end
22
21
 
23
22
  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
23
+ raise ArgumentError.new('Swagger::Data::SecurityDefinitions#add_param - parameter name is nil') unless pname
24
+ raise ArgumentError.new('Swagger::Data::SecurityDefinitions#add_param - parameter value is nil') unless pvalue
26
25
 
27
- if !pvalue.is_a?(Swagger::Data::SecurityScheme)
26
+ unless pvalue.is_a?(Swagger::Data::SecurityScheme)
28
27
  pvalue = Swagger::Data::SecurityScheme.parse(pvalue)
29
28
  end
30
29
 
@@ -44,6 +43,5 @@ module Swagger::Data
44
43
 
45
44
  swagger_params
46
45
  end
47
-
48
46
  end
49
- end
47
+ end