Module: Swagger

Defined in:
lib/swagger.rb,
lib/swagger/uri.rb,
lib/swagger/api.rb,
lib/swagger/v2/api.rb,
lib/swagger/v2/tag.rb,
lib/swagger/schema.rb,
lib/swagger/parsers.rb,
lib/swagger/version.rb,
lib/swagger/boolean.rb,
lib/swagger/builder.rb,
lib/swagger/v2/info.rb,
lib/swagger/v2/path.rb,
lib/swagger/v2/header.rb,
lib/swagger/mime_type.rb,
lib/swagger/v2/example.rb,
lib/swagger/attachable.rb,
lib/swagger/v2/response.rb,
lib/swagger/v2/parameter.rb,
lib/swagger/v2/operation.rb,
lib/swagger/uri_template.rb,
lib/swagger/swagger_object.rb,
lib/swagger/v2/security_scheme.rb,
lib/swagger/v2/security_requirement.rb,
lib/swagger/v2/deterministic_json_schema.rb

Overview

Provides loading and building capabilities for Swagger.

See Also:

Defined Under Namespace

Modules: Attachable, Bash, Builder, Parsers, V2 Classes: API, Boolean, InvalidDefinition, MimeType, Schema, SwaggerObject, URI, URITemplate

Constant Summary collapse

RESOURCES_DIR =
File.expand_path '../../resources/', __FILE__
VERSION =
'0.2.2'

Class Method Summary collapse

Class Method Details

.build(content, opts = {}) ⇒ Object

Instantiates a Swagger::API from the content.

Parameters:

  • opts (Hash) (defaults to: {})

    the build options

Options Hash (opts):

  • :version (String)

    the target Swagger specification version



21
22
23
24
25
# File 'lib/swagger.rb', line 21

def self.build(content, opts = {})
  parser ||= Swagger::Parsers.parser_for(opts[:format])
  content = parser.parse(content) unless parser.nil?
  Swagger::API.build(content)
end

.builder(opts = {}) ⇒ Object

Creates a Swagger::Builder that can be used to create a Swagger document.

Parameters:

  • opts (Hash) (defaults to: {})

    the build options

Options Hash (opts):

  • :version (String)

    the target Swagger specification version



42
43
44
# File 'lib/swagger.rb', line 42

def self.builder(opts = {})
  Swagger::Builder.builder(opts)
end

.load(file, opts = {}) ⇒ Object

Load a Swagger document from a file.

Parameters:

  • opts (Hash) (defaults to: {})

    the load options

Options Hash (opts):

  • :format (String)

    the format (yaml or json). Detected by file extension if omitted.



31
32
33
34
35
36
# File 'lib/swagger.rb', line 31

def self.load(file, opts = {})
  ext = File.extname file
  opts[:format] = ext
  content = File.read(file)
  build(content, opts)
end