Class: Swagger::V2::API

Inherits:
API show all
Defined in:
lib/swagger/v2/api.rb

Overview

Class representing the top level “Swagger Object”

See Also:

Instance Attribute Summary

Attributes inherited from SwaggerObject

#parent

Instance Method Summary collapse

Methods inherited from API

build, #initialize

Methods inherited from SwaggerObject

field, #initialize, required_field

Methods included from Attachable

#attach_parent, #attach_to_children, #root

Constructor Details

This class inherits a constructor from Swagger::API

Instance Method Details

#fully_validatetrue

Validates this object against the Swagger specification and returns all detected errors. Slower than #validate.

Returns:

  • (true)

    if the object fully complies with the Swagger specification.

Raises:



58
59
60
61
62
63
# File 'lib/swagger/v2/api.rb', line 58

def fully_validate
  # NOTE: fully_validate is ideal, but very slow with the current schema/validator
  errors = JSON::Validator.fully_validate(swagger_schema, to_json)
  fail Swagger::InvalidDefinition, errors unless errors.empty?
  true
end

#operationsArray<Operation>

All operations under all paths

Returns:



41
42
43
44
45
46
# File 'lib/swagger/v2/api.rb', line 41

def operations
  # Perhaps not the best way...
  paths.values.map do | path |
    path.operations.values
  end.flatten
end

#uri_templateSwagger::URITemplate

A complete (including host) URI Template for the basePath.



50
51
52
# File 'lib/swagger/v2/api.rb', line 50

def uri_template
  Swagger::URITemplate.new("#{host}#{basePath}")
end

#validatetrue

Validates this object against the Swagger specification and returns the first detected error. Faster than #fully_validate.

Returns:

  • (true)

    if the object fully complies with the Swagger specification.

Raises:



69
70
71
72
73
# File 'lib/swagger/v2/api.rb', line 69

def validate
  JSON::Validator.validate!(swagger_schema, to_json)
rescue JSON::Schema::ValidationError => e
  raise Swagger::InvalidDefinition, e.message
end