raml_ruby 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -0
  3. data/README.md +1 -9
  4. data/Rakefile +7 -0
  5. data/lib/raml.rb +6 -26
  6. data/lib/raml/exceptions.rb +1 -0
  7. data/lib/raml/mixin/bodies.rb +3 -3
  8. data/lib/raml/mixin/documentable.rb +3 -8
  9. data/lib/raml/mixin/global.rb +14 -10
  10. data/lib/raml/mixin/headers.rb +1 -1
  11. data/lib/raml/mixin/merge.rb +4 -4
  12. data/lib/raml/mixin/secured_by.rb +27 -0
  13. data/lib/raml/mixin/validation.rb +27 -27
  14. data/lib/raml/node.rb +22 -80
  15. data/lib/raml/node/abstract_method.rb +7 -7
  16. data/lib/raml/node/abstract_resource.rb +17 -7
  17. data/lib/raml/node/body.rb +12 -10
  18. data/lib/raml/node/documentation.rb +0 -8
  19. data/lib/raml/node/method.rb +5 -7
  20. data/lib/raml/node/parameter/abstract_parameter.rb +22 -24
  21. data/lib/raml/node/parametized_reference.rb +3 -3
  22. data/lib/raml/node/resource.rb +0 -2
  23. data/lib/raml/node/resource_type.rb +9 -9
  24. data/lib/raml/node/resource_type_reference.rb +2 -2
  25. data/lib/raml/node/response.rb +0 -2
  26. data/lib/raml/node/root.rb +66 -57
  27. data/lib/raml/node/schema.rb +3 -9
  28. data/lib/raml/node/schema_reference.rb +2 -2
  29. data/lib/raml/node/security_scheme.rb +47 -0
  30. data/lib/raml/node/security_scheme_reference.rb +5 -0
  31. data/lib/raml/node/trait.rb +8 -8
  32. data/lib/raml/node/trait_reference.rb +2 -2
  33. data/lib/raml/parser.rb +25 -16
  34. data/lib/raml/version.rb +1 -1
  35. data/raml_ruby.gemspec +3 -7
  36. data/test/apis/box-api.raml +1447 -1447
  37. data/test/apis/instagram-api.raml +48 -48
  38. data/test/apis/stripe-api.raml +4266 -4266
  39. data/test/apis/twilio-rest-api.raml +47 -47
  40. data/test/apis/twitter-rest-api.raml +1883 -1883
  41. data/test/raml/body_spec.rb +22 -39
  42. data/test/raml/documentation_spec.rb +2 -12
  43. data/test/raml/method_spec.rb +112 -93
  44. data/test/raml/parameter/abstract_parameter_spec.rb +9 -34
  45. data/test/raml/parameter/query_parameter_spec.rb +0 -15
  46. data/test/raml/parameter/uri_parameter_spec.rb +1 -16
  47. data/test/raml/resource_spec.rb +59 -41
  48. data/test/raml/resource_type_spec.rb +13 -13
  49. data/test/raml/response_spec.rb +23 -36
  50. data/test/raml/root_spec.rb +85 -18
  51. data/test/raml/security_scheme_spec.rb +71 -0
  52. data/test/raml/spec_helper.rb +2 -1
  53. data/test/raml/template_spec.rb +92 -92
  54. data/test/raml/trait_spec.rb +7 -7
  55. metadata +14 -74
  56. data/templates/abstract_parameter.slim +0 -68
  57. data/templates/body.slim +0 -15
  58. data/templates/collapse.slim +0 -10
  59. data/templates/documentation.slim +0 -2
  60. data/templates/method.slim +0 -38
  61. data/templates/resource.slim +0 -33
  62. data/templates/response.slim +0 -13
  63. data/templates/root.slim +0 -39
  64. data/templates/style.sass +0 -119
@@ -9,6 +9,7 @@ module Raml
9
9
  include Validation
10
10
  include Bodies
11
11
  include Headers
12
+ include SecuredBy
12
13
 
13
14
  # @!attribute [rw] protocols
14
15
  # @return [Array<String>, nil] the supported protocols. Nil or an array of up to two string
@@ -28,9 +29,14 @@ module Raml
28
29
 
29
30
  children_by :query_parameters , :name , Parameter::QueryParameter
30
31
  children_by :responses , :name , Response
32
+ children_by :secured_by , :name , SecuritySchemeReference
31
33
 
32
34
  private
33
-
35
+
36
+ def validate
37
+ _validate_secured_by
38
+ end
39
+
34
40
  def validate_protocols
35
41
  if @protocols
36
42
  validate_array :protocols, @protocols, String
@@ -51,11 +57,5 @@ module Raml
51
57
  validate_hash 'responses', value, [Integer, String], Hash
52
58
  value.map { |r_name, r_data| Response.new r_name, r_data, self }
53
59
  end
54
-
55
- def parse_secured_by(data)
56
- # XXX ignored for now
57
- []
58
- end
59
-
60
60
  end
61
61
  end
@@ -7,6 +7,7 @@ module Raml
7
7
  include Merge
8
8
  include Parent
9
9
  include Validation
10
+ include SecuredBy
10
11
 
11
12
  # @!attribute [r] base_uri_parameters
12
13
  # @return [Hash<String, Raml::Parameter::BaseUriParameter>] the base URI parameters, keyed
@@ -28,6 +29,7 @@ module Raml
28
29
  children_by :methods , :name, Raml::Method
29
30
  children_by :base_uri_parameters, :name, Parameter::BaseUriParameter, true
30
31
  children_by :uri_parameters , :name, Parameter::UriParameter , true
32
+ children_by :secured_by , :name, SecuritySchemeReference
31
33
 
32
34
  children_of :traits, [ Raml::Trait, Raml::TraitReference ]
33
35
 
@@ -77,8 +79,21 @@ module Raml
77
79
  @parent.resource_path + self.name
78
80
  end
79
81
 
82
+
83
+ # Returns the last non regex resource name
84
+ # @return [String] the last non request resource name
85
+ def resource_path_name
86
+ resource_path.split('/').reverse.detect do |pathPart|
87
+ !pathPart.match(/[{}]/)
88
+ end || ""
89
+ end
90
+
80
91
  private
81
-
92
+
93
+ def validate
94
+ _validate_secured_by
95
+ end
96
+
82
97
  def validate_parent
83
98
  raise InvalidParent, "Parent of resource cannot be nil." if @parent.nil?
84
99
  end
@@ -145,15 +160,10 @@ module Raml
145
160
  end
146
161
  end
147
162
 
148
- def parse_secured_by(data)
149
- # XXX ignored for now
150
- []
151
- end
152
-
153
163
  def instantiate_resource_type
154
164
  reserved_params = {
155
165
  'resourcePath' => resource_path,
156
- 'resourcePathName' => resource_path.split('/')[-1]
166
+ 'resourcePathName' => resource_path_name
157
167
  }
158
168
  if ResourceTypeReference === type
159
169
  resource_type_declarations[type.name].instantiate type.parameters.merge reserved_params
@@ -1,7 +1,7 @@
1
1
  module Raml
2
2
  class Body < PropertiesNode
3
3
  inherit_class_attributes
4
-
4
+
5
5
  include Global
6
6
  include Merge
7
7
  include Parent
@@ -25,15 +25,13 @@ module Raml
25
25
  # @!attribute [r] media\_type
26
26
  # @return [String] media type of the of body. An alias for #name.
27
27
 
28
- scalar_property :example
28
+ scalar_property :example
29
29
  non_scalar_property :form_parameters, :schema
30
30
 
31
31
  alias_method :media_type, :name
32
-
33
- self.doc_template = relative_path 'body.slim'
34
-
32
+
35
33
  children_by :form_parameters, :name, Parameter::FormParameter
36
-
34
+
37
35
  child_of :schema, [ Schema, SchemaReference ]
38
36
 
39
37
  # Returns whether the body is a web form. Returns true for "application/x-www-form-urlencoded" and
@@ -42,11 +40,11 @@ module Raml
42
40
  def web_form?
43
41
  [ 'application/x-www-form-urlencoded', 'multipart/form-data' ].include? media_type
44
42
  end
45
-
43
+
46
44
  # @private
47
45
  def merge(other)
48
46
  raise MergeError, "Media types don't match." if media_type != other.media_type
49
-
47
+
50
48
  super
51
49
 
52
50
  merge_properties other, :form_parameters
@@ -60,9 +58,13 @@ module Raml
60
58
  end
61
59
 
62
60
  private
63
-
61
+
64
62
  def validate_name
65
- raise InvalidMediaType, 'body media type is invalid' unless media_type =~ Body::MEDIA_TYPE_RE
63
+ raise InvalidMediaType, 'body media type is invalid' unless valid_media_type?
64
+ end
65
+
66
+ def valid_media_type?
67
+ media_type =~ Body::MEDIA_TYPE_RE || media_type == '*/*'
66
68
  end
67
69
 
68
70
  def parse_form_parameters(value)
@@ -1,5 +1,3 @@
1
- require 'kramdown'
2
-
3
1
  module Raml
4
2
  class Documentation < PropertiesNode
5
3
 
@@ -12,17 +10,11 @@ module Raml
12
10
  scalar_property :content
13
11
  alias_method :title, :name
14
12
 
15
- self.doc_template = relative_path 'documentation.slim'
16
-
17
13
  private
18
14
 
19
15
  def validate
20
16
  raise InvalidProperty, 'document title cannot be empty.' if title.nil? or title.empty?
21
17
  raise InvalidProperty, 'document content cannot be empty.' if content.nil? or content.empty?
22
18
  end
23
-
24
- def html_content
25
- Kramdown::Document.new(content, input: :GFM).to_html
26
- end
27
19
  end
28
20
  end
@@ -1,7 +1,7 @@
1
1
  module Raml
2
2
  class Method < AbstractMethod
3
3
  inherit_class_attributes
4
-
4
+
5
5
  NAMES = %w(options get head post put delete trace connect patch)
6
6
 
7
7
  # @!attribute [r] traits
@@ -11,8 +11,6 @@ module Raml
11
11
 
12
12
  children_of :traits, [ Trait, TraitReference ]
13
13
 
14
- self.doc_template = relative_path 'method.slim'
15
-
16
14
  # @private
17
15
  def apply_traits
18
16
  # We apply resource traits before method traits, and apply traits at each level in
@@ -48,8 +46,8 @@ module Raml
48
46
  false
49
47
  else # TraitReference
50
48
  self.traits.any? do |self_trait|
51
- self_trait.is_a?(TraitReference) &&
52
- self_trait.name == other_trait.name &&
49
+ self_trait.is_a?(TraitReference) &&
50
+ self_trait.name == other_trait.name &&
53
51
  self_trait.parameters == other_trait.parameters
54
52
  end
55
53
  end
@@ -76,7 +74,7 @@ module Raml
76
74
  value.map do |trait|
77
75
  if trait.is_a? Hash
78
76
  if trait.keys.size == 1 and trait_declarations.include? trait.keys.first
79
- raise InvalidProperty, 'is property with map of trait name but params are not a map' unless
77
+ raise InvalidProperty, 'is property with map of trait name but params are not a map' unless
80
78
  trait.values[0].is_a? Hash
81
79
  TraitReference.new( *trait.first, self )
82
80
  else
@@ -93,7 +91,7 @@ module Raml
93
91
  def instantiate_trait(trait)
94
92
  reserved_params = {
95
93
  'resourcePath' => @parent.resource_path,
96
- 'resourcePathName' => @parent.resource_path.split('/')[-1],
94
+ 'resourcePathName' => @parent.resource_path_name,
97
95
  'methodName' => self.name
98
96
  }
99
97
  if TraitReference === trait
@@ -48,8 +48,8 @@ module Raml
48
48
  # @return [Hash<String, Raml::Parameter::AbstractParameter>] if the parameter supports multiple types,
49
49
  # the type alternatives, keyed by the type.
50
50
 
51
- scalar_property :type , :enum , :pattern , :min_length ,
52
- :max_length , :minimum , :maximum , :example ,
51
+ scalar_property :type , :enum , :pattern , :min_length ,
52
+ :max_length , :minimum , :maximum , :example ,
53
53
  :repeat , :required , :default
54
54
 
55
55
  attr_reader_default :type , 'string'
@@ -58,8 +58,6 @@ module Raml
58
58
 
59
59
  children_by :types, :type, AbstractParameter
60
60
 
61
- self.doc_template = relative_path 'abstract_parameter.slim'
62
-
63
61
  # @param name [String] the parameter name.
64
62
  # @param parameter_data [Hash, Array<Hash>] the parameter data. If the parameter supports multiple types,
65
63
  # it should be an array of hashes, one hash each for each type.
@@ -80,7 +78,7 @@ module Raml
80
78
  def has_multiple_types?
81
79
  not children.empty?
82
80
  end
83
-
81
+
84
82
  # @private
85
83
  def merge(other)
86
84
  raise MergeError, "#{self.class} names don't match." if name != other.name
@@ -124,7 +122,7 @@ module Raml
124
122
  end
125
123
 
126
124
  private
127
-
125
+
128
126
  def validate_type
129
127
  raise InvalidParameterType unless VALID_TYPES.include? type
130
128
  end
@@ -139,7 +137,7 @@ module Raml
139
137
  end
140
138
  end
141
139
  end
142
-
140
+
143
141
  def validate_pattern
144
142
  if pattern
145
143
  if type == 'string'
@@ -153,10 +151,10 @@ module Raml
153
151
  end
154
152
  else
155
153
  raise InapplicableParameterAttribute, 'pattern attribute is only applicable to string parameters.'
156
- end
154
+ end
157
155
  end
158
156
  end
159
-
157
+
160
158
  def validate_min_length
161
159
  if min_length
162
160
  if type != 'string'
@@ -166,7 +164,7 @@ module Raml
166
164
  end
167
165
  end
168
166
  end
169
-
167
+
170
168
  def validate_max_length
171
169
  if max_length
172
170
  if type != 'string'
@@ -176,68 +174,68 @@ module Raml
176
174
  end
177
175
  end
178
176
  end
179
-
177
+
180
178
  def validate_minimum
181
179
  if minimum
182
180
  if %w(integer number).include? type
183
181
  raise InvalidParameterAttribute, 'minimum attribute must be numeric' unless minimum.is_a? Numeric
184
182
  else
185
- raise InapplicableParameterAttribute,
183
+ raise InapplicableParameterAttribute,
186
184
  'minimum attribute applicable only to number or integer parameters.'
187
185
  end
188
186
  end
189
187
  end
190
-
188
+
191
189
  def validate_maximum
192
190
  if maximum
193
191
  if %w(integer number).include? type
194
192
  raise InvalidParameterAttribute, 'maximum attribute must be numeric' unless maximum.is_a? Numeric
195
193
  else
196
- raise InapplicableParameterAttribute,
194
+ raise InapplicableParameterAttribute,
197
195
  'maximum attribute applicable only to number or integer parameters.'
198
196
  end
199
197
  end
200
198
  end
201
-
199
+
202
200
  def validate_example
203
201
  validate_value :example
204
202
  end
205
-
203
+
206
204
  def validate_repeat
207
205
  unless [true, false].include?(repeat)
208
206
  raise InvalidParameterAttribute, 'repeat attribute must be true or false.'
209
207
  end
210
208
  end
211
-
209
+
212
210
  def validate_required
213
211
  unless [true, false].include?(required)
214
212
  raise InvalidParameterAttribute, "required attribute must be true or false: #{required} (#{required.class})"
215
213
  end
216
214
  end
217
-
215
+
218
216
  def validate_default
219
217
  validate_value :default
220
218
  end
221
-
219
+
222
220
  def validate_value(which)
223
221
  val = send which
224
222
  if val
225
223
  err_msg = "#{which} attribute for a %s parameter must be a %s: #{val} (#{val.class})"
226
224
  case type
227
225
  when 'string'
228
- raise InvalidParameterAttribute,
226
+ raise InvalidParameterAttribute,
229
227
  ( err_msg % [ 'string' , 'string' ] ) unless val.is_a? String
230
228
  when 'number'
231
- raise InvalidParameterAttribute,
229
+ raise InvalidParameterAttribute,
232
230
  ( err_msg % [ 'number' , 'number' ] ) unless val.is_a? Numeric
233
231
  when 'integer'
234
- raise InvalidParameterAttribute,
232
+ raise InvalidParameterAttribute,
235
233
  ( err_msg % [ 'integer', 'integer' ] ) unless val.is_a? Integer
236
234
  when 'date'
237
- raise InvalidParameterAttribute,
235
+ raise InvalidParameterAttribute,
238
236
  ( err_msg % [ 'date' , 'string' ] ) unless val.is_a? String
239
237
  when 'boolean'
240
- raise InvalidParameterAttribute,
238
+ raise InvalidParameterAttribute,
241
239
  ( err_msg % [ 'boolean', 'boolean' ] ) unless [TrueClass, FalseClass].include? val.class
242
240
  end
243
241
  end
@@ -8,8 +8,8 @@ module Raml
8
8
  # @param parameters [Hash<String,String>] parameters to interpolate when instantiating the resouce type or trait.
9
9
  # @param parent [Raml::Node] the parent node.
10
10
  def initialize(name, parameters={}, parent)
11
- super name, parent
12
- @parameters = parameters
11
+ super name, parent
12
+ @parameters = parameters
13
13
  end
14
14
  end
15
- end
15
+ end
@@ -9,8 +9,6 @@ module Raml
9
9
 
10
10
  children_by :resources, :name, Resource
11
11
 
12
- self.doc_template = relative_path 'resource.slim'
13
-
14
12
  # @private
15
13
  def apply_resource_type
16
14
  super
@@ -1,20 +1,20 @@
1
1
  module Raml
2
2
  class ResourceType < Template
3
- class Instance < AbstractResource
4
- inherit_class_attributes
3
+ class Instance < AbstractResource
4
+ inherit_class_attributes
5
5
 
6
6
  # @!attribute [rw] usage
7
7
  # @return [String,nil] how the resource type should be used.
8
- scalar_property :usage
9
- end
8
+ scalar_property :usage
9
+ end
10
10
 
11
11
  # Instantiate a new resource type with the given parameters.
12
12
  # @param params [Hash] the parameters to interpolate in the resource type.
13
13
  # @return [Raml::ResourceType::Instance] the instantiated resouce type.
14
- def instantiate(params)
15
- instance = Instance.new( *interpolate(params), @parent )
16
- instance.apply_resource_type
17
- instance
18
- end
14
+ def instantiate(params)
15
+ instance = Instance.new( *interpolate(params), @parent )
16
+ instance.apply_resource_type
17
+ instance
18
+ end
19
19
  end
20
20
  end
@@ -1,5 +1,5 @@
1
1
  module Raml
2
- # A reference to a resource type defined in the root node.
2
+ # A reference to a resource type defined in the root node.
3
3
  class ResourceTypeReference < ParametizedReference
4
4
  end
5
- end
5
+ end
@@ -10,8 +10,6 @@ module Raml
10
10
  include Bodies
11
11
  include Headers
12
12
 
13
- self.doc_template = relative_path 'response.slim'
14
-
15
13
  def initialize(name, properties, parent)
16
14
  super
17
15
  @name = name.to_i
@@ -1,4 +1,3 @@
1
- require 'sass'
2
1
  require 'uri'
3
2
  require 'uri_template'
4
3
 
@@ -9,6 +8,7 @@ module Raml
9
8
 
10
9
  include Parent
11
10
  include Validation
11
+ include SecuredBy
12
12
 
13
13
  # @!attribute [rw] title
14
14
  # @return [String] API title.
@@ -31,7 +31,7 @@ module Raml
31
31
 
32
32
  # @!attribute [r] base_uri_parameters
33
33
  # @return [Hash<String, Raml::Parameter::BaseUriParameter>] the base URI parameters, keyed
34
- # by the parameter name.
34
+ # by the parameter name.
35
35
 
36
36
  # @!attribute [r] schemas
37
37
  # @return [Hash<String, Raml::Schema>] the schema definitions, keyed by the schema name.
@@ -45,28 +45,33 @@ module Raml
45
45
  # @!attribute [r] resource_types
46
46
  # @return [Hash<String, Raml::ResourceType>] the resource type definitions, keyed by the resource type name.
47
47
 
48
+ # @!attribute [r] security_schemes
49
+ # @return [Hash<String, Raml::SecurityScheme>] the security scheme definitions, keyed by the security scheme name.
50
+
48
51
  scalar_property :title , :version , :base_uri ,
49
52
  :protocols , :media_type
50
53
 
51
- non_scalar_property :base_uri_parameters, :documentation , :schemas, :secured_by,
52
- :security_schemes , :resource_types, :traits
54
+ non_scalar_property :base_uri_parameters, :documentation , :schemas, :secured_by,
55
+ :security_schemes , :resource_types, :traits, :security_schemes
53
56
 
54
57
  regexp_property( /\A\//, ->(key,value) { Resource.new key, value, self } )
55
58
 
56
59
  children_of :documents, Documentation
57
60
 
58
- children_by :base_uri_parameters, :name, Parameter::BaseUriParameter
61
+ children_by :base_uri_parameters, :name, Parameter::BaseUriParameter
59
62
  children_by :resources , :name, Resource
60
63
  children_by :schemas , :name, Schema
61
64
  children_by :traits , :name, Trait
62
65
  children_by :resource_types , :name, ResourceType
66
+ children_by :security_schemes , :name, SecurityScheme
67
+ children_by :secured_by , :name, SecuritySchemeReference
63
68
 
64
- alias :default_media_type :media_type
65
- alias :trait_declarations :traits
66
- alias :resource_type_declarations :resource_types
67
- alias :schema_declarations :schemas
68
-
69
- self.doc_template = relative_path 'root.slim'
69
+ alias :default_media_type :media_type
70
+ alias :trait_declarations :traits
71
+ alias :resource_type_declarations :resource_types
72
+ alias :security_scheme_declarations :security_schemes
73
+ alias :schema_declarations :schemas
74
+ alias :secured_by_declarations :secured_by
70
75
 
71
76
  def initialize(root_data)
72
77
  super nil, root_data, self
@@ -79,7 +84,7 @@ module Raml
79
84
  resources.values.each(&:apply_resource_type)
80
85
  resources.values.each(&:apply_traits)
81
86
  inline_reference SchemaReference, schemas, @children
82
- @expanded = true
87
+ @expanded = true
83
88
  end
84
89
  end
85
90
 
@@ -94,104 +99,113 @@ module Raml
94
99
  raise RequiredPropertyMissing, 'Missing root title property.' if title.nil?
95
100
  raise RequiredPropertyMissing, 'Missing root baseUri property' if base_uri.nil?
96
101
  _validate_base_uri
102
+ _validate_secured_by
97
103
  end
98
104
 
99
105
  def validate_title
100
106
  validate_string :title, title
101
107
  end
102
-
108
+
103
109
  def _validate_base_uri
104
110
  validate_string :base_uri, base_uri
105
-
111
+
106
112
  # Check whether its a URL.
107
113
  uri = parse_uri base_uri
108
-
114
+
109
115
  # If the parser doesn't think its a URL or the URL is not for HTTP or HTTPS,
110
116
  # try to parse it as a URL template.
111
117
  if uri.nil? and not uri.kind_of? URI::HTTP
112
118
  template = parse_template
113
-
119
+
114
120
  # The template parser did not complain, but does it generate valid URLs?
115
121
  uri = template.expand Hash[ template.variables.map {|var| [ var, 'a'] } ]
116
122
  uri = parse_uri uri
117
123
  raise InvalidProperty, 'baseUri property is not a URL or a URL template.' unless
118
124
  uri and uri.kind_of? URI::HTTP
119
-
125
+
120
126
  raise RequiredPropertyMissing, 'version property is required when baseUri template has version parameter' if
121
127
  template.variables.include? 'version' and version.nil?
122
128
  end
123
129
  end
124
-
130
+
125
131
  def validate_protocols
126
132
  if protocols
127
133
  validate_array :protocols, protocols, String
128
-
134
+
129
135
  @protocols.map!(&:upcase)
130
-
131
- raise InvalidProperty, 'protocols property elements must be HTTP or HTTPS' unless
136
+
137
+ raise InvalidProperty, 'protocols property elements must be HTTP or HTTPS' unless
132
138
  protocols.all? { |p| [ 'HTTP', 'HTTPS'].include? p }
133
139
  end
134
140
  end
135
-
141
+
136
142
  def validate_media_type
137
143
  if media_type
138
144
  validate_string :media_type, media_type
139
145
  raise InvalidProperty, 'mediaType property is malformed' unless media_type =~ Body::MEDIA_TYPE_RE
140
146
  end
141
147
  end
142
-
148
+
143
149
  def parse_schemas(schemas)
144
150
  validate_array :schemas, schemas, Hash
145
-
146
- raise InvalidProperty, 'schemas property must be an array of maps with string keys' unless
151
+
152
+ raise InvalidProperty, 'schemas property must be an array of maps with string keys' unless
147
153
  schemas.all? {|s| s.keys.all? {|k| k.is_a? String }}
148
-
149
- raise InvalidProperty, 'schemas property must be an array of maps with string values' unless
154
+
155
+ raise InvalidProperty, 'schemas property must be an array of maps with string values' unless
150
156
  schemas.all? {|s| s.values.all? {|v| v.is_a? String }}
151
-
152
- raise InvalidProperty, 'schemas property contains duplicate schema names' unless
157
+
158
+ raise InvalidProperty, 'schemas property contains duplicate schema names' unless
153
159
  schemas.map(&:keys).flatten.uniq!.nil?
154
160
 
155
161
  schemas.reduce({}) { |memo, map | memo.merge! map }.
156
162
  map { |name, data| Schema.new name, data, self }
157
163
  end
158
-
164
+
159
165
  def parse_base_uri_parameters(base_uri_parameters)
160
166
  validate_hash :base_uri_parameters, base_uri_parameters, String, Hash
161
-
167
+
162
168
  raise InvalidProperty, 'baseUriParameters property can\'t contain reserved "version" parameter' if
163
169
  base_uri_parameters.include? 'version'
164
170
 
165
171
  base_uri_parameters.map { |name, data| Parameter::BaseUriParameter.new name, data, self }
166
172
  end
167
-
173
+
168
174
  def parse_documentation(documentation)
169
175
  validate_array :documentation, documentation
170
-
171
- raise InvalidProperty, 'documentation property must include at least one document or not be included' if
176
+
177
+ raise InvalidProperty, 'documentation property must include at least one document or not be included' if
172
178
  documentation.empty?
173
179
 
174
180
  documentation.map { |doc| doc = doc.dup; Documentation.new doc.delete("title"), doc, self }
175
181
  end
176
-
177
- def parse_secured_by(data)
178
- # XXX ignored for now
179
- end
180
182
 
181
183
  def parse_security_schemes(data)
182
- # XXX ignored for now
184
+ validate_array :security_schemes, data, Hash
185
+
186
+ raise InvalidProperty, 'securitySchemes property must be an array of maps with string keys' unless
187
+ data.all? {|t| t.keys.all? {|k| k.is_a? String }}
188
+
189
+ raise InvalidProperty, 'securitySchemes property must be an array of maps with map values' unless
190
+ data.all? {|t| t.values.all? {|v| v.is_a? Hash }}
191
+
192
+ raise InvalidProperty, 'securitySchemes property contains duplicate type names' unless
193
+ data.map(&:keys).flatten.uniq!.nil?
194
+
195
+ data.reduce({}) { |memo, map | memo.merge! map }.
196
+ map { |name, data| SecurityScheme.new name, data, self }
183
197
  end
184
198
 
185
199
  def parse_resource_types(types)
186
200
  validate_array :resource_types, types, Hash
187
-
188
- raise InvalidProperty, 'resourceTypes property must be an array of maps with string keys' unless
201
+
202
+ raise InvalidProperty, 'resourceTypes property must be an array of maps with string keys' unless
189
203
  types.all? {|t| t.keys.all? {|k| k.is_a? String }}
190
-
191
- raise InvalidProperty, 'resourceTypes property must be an array of maps with map values' unless
204
+
205
+ raise InvalidProperty, 'resourceTypes property must be an array of maps with map values' unless
192
206
  types.all? {|t| t.values.all? {|v| v.is_a? Hash }}
193
-
194
- raise InvalidProperty, 'resourceTypes property contains duplicate type names' unless
207
+
208
+ raise InvalidProperty, 'resourceTypes property contains duplicate type names' unless
195
209
  types.map(&:keys).flatten.uniq!.nil?
196
210
 
197
211
  types.reduce({}) { |memo, map | memo.merge! map }.
@@ -200,14 +214,14 @@ module Raml
200
214
 
201
215
  def parse_traits(traits)
202
216
  validate_array :traits, traits, Hash
203
-
204
- raise InvalidProperty, 'traits property must be an array of maps with string keys' unless
217
+
218
+ raise InvalidProperty, 'traits property must be an array of maps with string keys' unless
205
219
  traits.all? {|t| t.keys.all? {|k| k.is_a? String }}
206
-
207
- raise InvalidProperty, 'traits property must be an array of maps with map values' unless
220
+
221
+ raise InvalidProperty, 'traits property must be an array of maps with map values' unless
208
222
  traits.all? {|t| t.values.all? {|v| v.is_a? Hash }}
209
-
210
- raise InvalidProperty, 'traits property contains duplicate trait names' unless
223
+
224
+ raise InvalidProperty, 'traits property contains duplicate trait names' unless
211
225
  traits.map(&:keys).flatten.uniq!.nil?
212
226
 
213
227
  traits.reduce({}) { |memo, map | memo.merge! map }.
@@ -219,7 +233,7 @@ module Raml
219
233
  rescue URI::InvalidURIError
220
234
  nil
221
235
  end
222
-
236
+
223
237
  def parse_template
224
238
  URITemplate::RFC6570.new base_uri
225
239
  rescue URITemplate::RFC6570::Invalid
@@ -237,10 +251,5 @@ module Raml
237
251
  end
238
252
  end
239
253
 
240
- def style_sheet
241
- File.open(self.class.relative_path('style.sass'), 'r') do |file|
242
- Sass::Engine.new(file.read, syntax: :scss).render
243
- end
244
- end
245
254
  end
246
255
  end