Class: SexyJSONSchemas::Properties::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/sexy_json_schemas/properties/base.rb

Direct Known Subclasses

Any, Array, Boolean, Null, Number, Object, Ref, String, Union

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ Base

Returns a new instance of Base.



6
7
8
9
# File 'lib/sexy_json_schemas/properties/base.rb', line 6

def initialize(name, options = {})
  @name = name
  @options = options
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/sexy_json_schemas/properties/base.rb', line 4

def name
  @name
end

Instance Method Details

#as_jsonObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/sexy_json_schemas/properties/base.rb', line 15

def as_json
  json = { }

  json["type"] = type if type

  if @options[:required]
    json['required'] = true
  end

  if @options[:enum]
    json['enum'] = @options[:enum]
  end

  if @options[:format]
    json['format'] = @options[:format]
  end

  if @options[:description]
    json['description'] = @options[:description]
  end

  json
end

#typeObject



11
12
13
# File 'lib/sexy_json_schemas/properties/base.rb', line 11

def type
  nil
end