Class: Swagger::SwaggerObject

Inherits:
Hashie::Dash
  • Object
show all
Includes:
Hashie::Extensions::Coercion, Hashie::Extensions::IndifferentAccess, Attachable
Defined in:
lib/swagger/swagger_object.rb

Overview

A class that represents an Object defined in the Swagger specification. Provides methods for defining fields in the object.

Constant Summary collapse

CUSTOM_PROPERTY_PREFIX =
/^x\-/

Instance Attribute Summary collapse

Attributes included from Attachable

#children

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Attachable

#attach_parent, #attach_to_children, #root

Constructor Details

#initialize(hash) ⇒ SwaggerObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initializes a Swagger object, using Hashie::Dash, and attaches to children objects so navigation via parent and root is possible.



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

def initialize(hash)
  super
  attach_to_children
end

Instance Attribute Details

#parentObject

Returns the value of attribute parent.



16
17
18
# File 'lib/swagger/swagger_object.rb', line 16

def parent
  @parent
end

Class Method Details

.field(name, type, opts = {}) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Defines a Swagger field on a class.



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

def self.field(name, type, opts = {})
  property name, opts
  coerce_key name, type
end

.property?(name) ⇒ Boolean

Swagger allows any properties starting with x-

Returns:



12
13
14
# File 'lib/swagger/swagger_object.rb', line 12

def self.property?(name)
  super(name) || name.to_s =~ CUSTOM_PROPERTY_PREFIX
end

.required_field(name, type, opts = {}) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Defines a required Swagger field on a class.



44
45
46
47
# File 'lib/swagger/swagger_object.rb', line 44

def self.required_field(name, type, opts = {})
  opts[:required] = true
  field(name, type, opts)
end