Class: Swagger::Blocks::RootNode

Inherits:
Node
  • Object
show all
Defined in:
lib/swagger/blocks.rb

Instance Attribute Summary

Attributes inherited from Node

#name, #version

Instance Method Summary collapse

Methods inherited from Node

#as_json, call, #data, #is_swagger_1_2?, #is_swagger_2_0?, #key, #keys

Constructor Details

#initialize(*args) ⇒ RootNode

Returns a new instance of RootNode.



281
282
283
284
285
286
287
# File 'lib/swagger/blocks.rb', line 281

def initialize(*args)
  # An internal list of the user-defined names that uniquely identify each API tree.
  # Only used in Swagger 1.2, but when initializing a root node we haven't seen the
  # swaggerVersion/swagger key yet
  @api_paths = []
  super
end

Instance Method Details

#api(inline_keys = nil, &block) ⇒ Object

Raises:



308
309
310
311
312
313
# File 'lib/swagger/blocks.rb', line 308

def api(inline_keys = nil, &block)
  raise NotSupportedError unless is_swagger_1_2?

  self.data[:apis] ||= []
  self.data[:apis] << Swagger::Blocks::ResourceNode.call(version: version, inline_keys: inline_keys ,&block)
end

#authorization(name, inline_keys = nil, &block) ⇒ Object

Raises:



296
297
298
299
300
301
302
# File 'lib/swagger/blocks.rb', line 296

def authorization(name, inline_keys = nil, &block)
  raise NotSupportedError unless is_swagger_1_2?

  self.data[:authorizations] ||= Swagger::Blocks::ResourceListingAuthorizationsNode.new
  self.data[:authorizations].version = version
  self.data[:authorizations].authorization(name, inline_keys, &block)
end

#has_api_path?(api_path) ⇒ Boolean

Returns:

  • (Boolean)

Raises:



289
290
291
292
293
294
# File 'lib/swagger/blocks.rb', line 289

def has_api_path?(api_path)
  raise NotSupportedError unless is_swagger_1_2?

  api_paths = self.data[:apis].map { |x| x.data[:path] }
  api_paths.include?(api_path)
end

#info(inline_keys = nil, &block) ⇒ Object



304
305
306
# File 'lib/swagger/blocks.rb', line 304

def info(inline_keys = nil, &block)
  self.data[:info] = Swagger::Blocks::InfoNode.call(version: version, inline_keys: inline_keys, &block)
end

#parameter(param, inline_keys = nil, &block) ⇒ Object

Raises:



315
316
317
318
319
320
321
# File 'lib/swagger/blocks.rb', line 315

def parameter(param, inline_keys = nil, &block)
  raise NotSupportedError unless is_swagger_2_0?

  # TODO validate 'param' is as per spec
  self.data[:parameters] ||= {}
  self.data[:parameters][param] = Swagger::Blocks::ParameterNode.call(version: version, inline_keys: inline_keys, &block)
end

#response(resp, inline_keys = nil, &block) ⇒ Object

Raises:



323
324
325
326
327
328
329
# File 'lib/swagger/blocks.rb', line 323

def response(resp, inline_keys = nil, &block)
  raise NotSupportedError unless is_swagger_2_0?

  # TODO validate 'resp' is as per spec
  self.data[:responses] ||= {}
  self.data[:responses][resp] = Swagger::Blocks::ResponseNode.call(version: version, inline_keys: inline_keys, &block)
end

#security(inline_keys = nil, &block) ⇒ Object

Raises:



338
339
340
341
342
343
# File 'lib/swagger/blocks.rb', line 338

def security(inline_keys = nil, &block)
  raise NotSupportedError unless is_swagger_2_0?

  self.data[:security] ||= []
  self.data[:security] << Swagger::Blocks::SecurityRequirementNode.call(version: version, inline_keys: inline_keys, &block)
end

#security_definition(name, inline_keys = nil, &block) ⇒ Object

Raises:



331
332
333
334
335
336
# File 'lib/swagger/blocks.rb', line 331

def security_definition(name, inline_keys = nil, &block)
  raise NotSupportedError unless is_swagger_2_0?

  self.data[:securityDefinitions] ||= {}
  self.data[:securityDefinitions][name] = Swagger::Blocks::SecuritySchemeNode.call(version: version, inline_keys: inline_keys, &block)
end

#tag(inline_keys = nil, &block) ⇒ Object Also known as: tags

Raises:



345
346
347
348
349
350
# File 'lib/swagger/blocks.rb', line 345

def tag(inline_keys = nil, &block)
  raise NotSupportedError unless is_swagger_2_0?

  self.data[:tags] ||= []
  self.data[:tags] << Swagger::Blocks::TagNode.call(version: version, inline_keys: inline_keys, &block)
end