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.

Raises:


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

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


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

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.


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

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.

Raises:


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

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