Module: Swagger

Defined in:
lib/swagger.rb,
lib/swagger/api.rb,
lib/swagger/uri.rb,
lib/swagger/schema.rb,
lib/swagger/v2/api.rb,
lib/swagger/v2/tag.rb,
lib/swagger/boolean.rb,
lib/swagger/builder.rb,
lib/swagger/parsers.rb,
lib/swagger/v2/info.rb,
lib/swagger/v2/path.rb,
lib/swagger/version.rb,
lib/swagger/mime_type.rb,
lib/swagger/v2/header.rb,
lib/swagger/attachable.rb,
lib/swagger/v2/example.rb,
lib/swagger/v2/response.rb,
lib/swagger/uri_template.rb,
lib/swagger/v2/operation.rb,
lib/swagger/v2/parameter.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.3.0'.freeze

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



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

def self.build(content, opts = {})
  parser ||= Swagger::Parsers.parser_for(opts[:format])
  content = parser.parse(content) unless parser.nil?
  Swagger::API.build_api(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



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

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.



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

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