Class: SwaggerYard::Type

Inherits:
Object
  • Object
show all
Defined in:
lib/swagger_yard/type.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ Type

Returns a new instance of Type.



9
10
11
12
13
14
# File 'lib/swagger_yard/type.rb', line 9

def initialize(string)
  @source  = string
  @schema  = TypeParser.new.json_schema(string)
  @name    = name_for(@schema)
  @name    = name_for(@schema['items']) if @name == 'array'
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/swagger_yard/type.rb', line 7

def name
  @name
end

#schemaObject (readonly)

Returns the value of attribute schema.



7
8
9
# File 'lib/swagger_yard/type.rb', line 7

def schema
  @schema
end

#sourceObject (readonly)

Returns the value of attribute source.



7
8
9
# File 'lib/swagger_yard/type.rb', line 7

def source
  @source
end

Class Method Details

.from_type_list(types) ⇒ Object



3
4
5
# File 'lib/swagger_yard/type.rb', line 3

def self.from_type_list(types)
  new(types.first)
end

Instance Method Details

#model_nameObject



21
22
23
# File 'lib/swagger_yard/type.rb', line 21

def model_name
  ref? ? name : nil
end

#ref?Boolean

TODO: have this look at resource listing?

Returns:

  • (Boolean)


17
18
19
# File 'lib/swagger_yard/type.rb', line 17

def ref?
  schema["$ref"]
end

#to_hObject



25
26
27
# File 'lib/swagger_yard/type.rb', line 25

def to_h
  schema
end