class Swagger::V2::API
Class representing the top level “Swagger Object” @see github.com/wordnik/swagger-spec/blob/master/versions/2.0.md#swagger-object- Swagger
Object
Public Instance Methods
Validates this object against the Swagger
specification and returns all detected errors. Slower than {#validate}. @return [true] if the object fully complies with the Swagger
specification. @raise [Swagger::InvalidDefinition] if any errors are found.
# 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) raise Swagger::InvalidDefinition, errors unless errors.empty? true end
All operations under all paths @return [Array<Operation>]
# 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
A complete (including host) URI
Template for the basePath. @return [Swagger::URITemplate]
# File lib/swagger/v2/api.rb, line 51 def uri_template Swagger::URITemplate.new("#{host}#{basePath}") end
Validates this object against the Swagger
specification and returns the first detected error. Faster than {#fully_validate}. @return [true] if the object fully complies with the Swagger
specification. @raise [Swagger::InvalidDefinition] if an error is found.
# 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
Private Instance Methods
# File lib/swagger/v2/api.rb, line 78 def swagger_schema @swagger_schema ||= JSON.parse(File.read(SWAGGER_SCHEMA)) # FIXME: Swagger should be able to parse offline. Blocked by json-schema. # Offline workaround # @swagger_schema = JSON.parse(File.read(SWAGGER_SCHEMA) # .gsub('http://json-schema.org/draft-04/schema', "file://#{SWAGGER_SCHEMA}")) # @swagger_schema['$schema'] = 'http://json-schema.org/draft-04/schema#' # @swagger_schema end