Module: Modern::DocGenerator::OpenAPI3::SchemaDefaultTypes

Included in:
Schemas
Defined in:
lib/modern/doc_generator/open_api3/schema_default_types.rb

Instance Method Summary collapse

Instance Method Details

#_register_default_types!Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/modern/doc_generator/open_api3/schema_default_types.rb', line 7

def _register_default_types!
  # TODO: handle all default types
  #       This misses a few types, mostly because I don't yet know how to
  #       handle them:
  #         - I don't understand the Types::Form set of types well enough.
  #         - I have not provided a DateTime mapping because you shouldn't
  #           use DateTime and I have no idea how to do so sanely.
  #         - We can't coerce Symbols, so those are out.
  [Types::String, Types::Strict::String, Types::Coercible::String].each do |t|
    register_literal_type(t, type: "string")
  end

  [Types::Integer, Types::Strict::Integer, Types::Coercible::Integer].each do |t|
    register_literal_type(t, type: "integer", format: "int64")
  end

  [
    Types::Bool, Types::Strict::Bool,
    Types::True, Types::Strict::True,
    Types::False, Types::Strict::False
  ].each do |t|
    register_literal_type(t, type: "boolean")
  end

  [Types::Float, Types::Strict::Float, Types::Coercible::Float].each do |t|
    register_literal_type(t, type: "number", format: "double")
  end

  [Types::Date, Types::Strict::Date, Types::JSON::Date].each do |t|
    register_literal_type(t, type: "string", format: "date")
  end

  [Types::Time, Types::Strict::Time, Types::JSON::Time].each do |t|
    register_literal_type(t, type: "string", format: "date")
  end

  [Types::Decimal, Types::Strict::Decimal, Types::Coercible::Decimal].each do |t|
    register_literal_type(t, type: "number")
  end
end