Class: Swagger::V2::Example
- Inherits:
-
Object
- Object
- Swagger::V2::Example
- Extended by:
- Forwardable
- Defined in:
- lib/swagger/v2/example.rb
Overview
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.
Instance Attribute Summary collapse
-
#raw ⇒ Object
readonly
The example as it appears in the Swagger document.
Instance Method Summary collapse
-
#initialize(sample) ⇒ Example
constructor
A new instance of Example.
- #inspect ⇒ Object
-
#parse(media_type = 'application/json') ⇒ Object
The example after it has been parsed to match the
media_type
.
Constructor Details
#initialize(sample) ⇒ Example
Returns a new instance of Example.
14 15 16 |
# File 'lib/swagger/v2/example.rb', line 14 def initialize(sample) @raw = sample end |
Instance Attribute Details
#raw ⇒ Object (readonly)
The example as it appears in the Swagger document.
12 13 14 |
# File 'lib/swagger/v2/example.rb', line 12 def raw @raw end |
Instance Method Details
#inspect ⇒ Object
27 28 29 |
# File 'lib/swagger/v2/example.rb', line 27 def inspect @raw.inspect end |
#parse(media_type = 'application/json') ⇒ Object
The example after it has been parsed to match the media_type
.
21 22 23 24 25 |
# 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 |