Class: SwaggerYard::Type

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

Constant Summary collapse

MODEL_PATH =

Default model location path

'#/definitions/'.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ Type

Returns a new instance of Type.



12
13
14
15
# File 'lib/swagger_yard/type.rb', line 12

def initialize(string)
  @source  = string
  @name    = nil
end

Instance Attribute Details

#sourceObject (readonly)

Returns the value of attribute source.



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

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

#nameObject



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

def name
  return @name if @name
  @name = name_for(schema)
  @name = name_for(schema['items']) if @name == 'array'
  @name
end

#schemaObject



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

def schema
  @schema ||= TypeParser.new.json_schema(source)
end

#schema_with(options = {}) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/swagger_yard/type.rb', line 28

def schema_with(options = {})
  model_path = options && options[:model_path] || MODEL_PATH
  if model_path != MODEL_PATH
    TypeParser.new(model_path).json_schema(source)
  else
    schema
  end
end