Class: Apipie::Generator::Swagger::TypeExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/apipie/generator/swagger/type_extractor.rb

Constant Summary collapse

TYPES =
{
  numeric: 'number',
  hash: 'object',
  array: 'array',
  enum: 'enum',

  # see https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#data-types
  integer: Apipie::Generator::Swagger::Type.new('integer', 'int32'),
  long: Apipie::Generator::Swagger::Type.new('integer', 'int64'),
  number: Apipie::Generator::Swagger::Type.new('number'),
  float: Apipie::Generator::Swagger::Type.new('number', 'float'),
  double: Apipie::Generator::Swagger::Type.new('number', 'double'),
  string: Apipie::Generator::Swagger::Type.new('string'),
  byte: Apipie::Generator::Swagger::Type.new('string', 'byte'),
  binary: Apipie::Generator::Swagger::Type.new('string', 'binary'),
  boolean: Apipie::Generator::Swagger::Type.new('boolean'),
  date: Apipie::Generator::Swagger::Type.new('string', 'date'),
  dateTime: Apipie::Generator::Swagger::Type.new('string', 'date-time'),
  password: Apipie::Generator::Swagger::Type.new('string', 'password')
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(validator) ⇒ TypeExtractor

Returns a new instance of TypeExtractor.



24
25
26
# File 'lib/apipie/generator/swagger/type_extractor.rb', line 24

def initialize(validator)
  @validator = validator
end

Instance Method Details

#extractObject



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/apipie/generator/swagger/type_extractor.rb', line 28

def extract
  expected_type =
    if string?
      :string
    elsif enum?
      :enum
    else
      @validator.expected_type.to_sym
    end

  TYPES[expected_type] || @validator.expected_type
end