Class: Shale::Schema::JSONGenerator::Base Private

Inherits:
Object
  • Object
show all
Defined in:
lib/shale/schema/json_generator/base.rb

Overview

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

Base class for JSON Schema types

Direct Known Subclasses

Boolean, Date, Float, Integer, Object, Ref, String, Time, Value

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, default: nil, schema: nil) ⇒ Base

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.

Returns a new instance of Base.



25
26
27
28
29
30
# File 'lib/shale/schema/json_generator/base.rb', line 25

def initialize(name, default: nil, schema: nil)
  @name = name.gsub('::', '_')
  @default = default
  @schema = schema || {}
  @nullable = !schema&.[](:required)
end

Instance Attribute Details

#nameObject (readonly)

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.

Return name



13
14
15
# File 'lib/shale/schema/json_generator/base.rb', line 13

def name
  @name
end

#nullable=(value) ⇒ Object (writeonly)

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.

Set nullable



23
24
25
# File 'lib/shale/schema/json_generator/base.rb', line 23

def nullable=(value)
  @nullable = value
end

#schemaObject (readonly)

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.

Return schema hash



18
19
20
# File 'lib/shale/schema/json_generator/base.rb', line 18

def schema
  @schema
end

Instance Method Details

#as_jsonHash

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.

Return JSON Schema fragment as Ruby Hash

Returns:

  • (Hash)


37
38
39
40
41
42
43
# File 'lib/shale/schema/json_generator/base.rb', line 37

def as_json
  type = as_type
  type['type'] = [*type['type'], 'null'] if type['type'] && @nullable
  type['default'] = @default unless @default.nil?

  type
end