Class: JsonSchemaView::JsonWorldExtensions::EnumType

Inherits:
Object
  • Object
show all
Defined in:
lib/json_schema_view/json_world_extensions/enum_type.rb

Overview

This module allows JsonWorld::DSL::ClassMethods#property to define enum values. Defined constant values are reflect to JSON Schema.

Examples:

class Zoo
  include JsonWorld::DSL
  include JsonSchemaView::JsonWorldExtensions::EnumType::DSL
  property(
    :animal,
    type: enum_type("Dog", "Cat"),
  )
end

See Also:

Defined Under Namespace

Modules: DSL

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*candidates) ⇒ EnumType

Returns a new instance of EnumType.

Parameters:



32
33
34
# File 'lib/json_schema_view/json_world_extensions/enum_type.rb', line 32

def initialize(*candidates)
  @candidates = candidates
end

Instance Attribute Details

#candidatesObject (readonly)

Returns the value of attribute candidates.



28
29
30
# File 'lib/json_schema_view/json_world_extensions/enum_type.rb', line 28

def candidates
  @candidates
end

Instance Method Details

#as_json_schemaObject Also known as: as_json_schema_without_links



36
37
38
39
40
# File 'lib/json_schema_view/json_world_extensions/enum_type.rb', line 36

def as_json_schema
  {
    enum: candidates
  }
end