class Swagger::V2::Example

A class to represent example objects in the Swagger schema. Usually used to represent example request or responses. Provides access to both the raw example or a parsed representation.

Attributes

raw[R]

The example as it appears in the Swagger document. @return Object the example

Public Class Methods

new(sample) click to toggle source
# File lib/swagger/v2/example.rb, line 14
def initialize(sample)
  @raw = sample
end

Public Instance Methods

parse(media_type = 'application/json') click to toggle source

The example after it has been parsed to match the media_type. @param media_type [String] the target media_type @return [Object] an object according to the media_type

# File lib/swagger/v2/example.rb, line 21
def parse(media_type = 'application/json')
  return @raw unless @raw.is_a? String
  parser = Swagger::MimeType.parser_for(media_type)
  parser.parse(@raw)
end