Class: JSON::SchemaDsl::Renderers::Alias

Inherits:
Base
  • Object
show all
Defined in:
lib/json/schema_dsl/renderers/alias.rb

Overview

Aliases certain attributes and camel-cases all others. The only exception are property names which are set by the user and will not be camel-cased.

Constant Summary collapse

ALIASES =
{
  'ref' => '$ref'
}.freeze

Instance Attribute Summary

Attributes inherited from Base

#scope

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from JSON::SchemaDsl::Renderers::Base

Instance Method Details

#visit(entity) ⇒ Object

Camel-case and/or alias the attribute names of the given structure.



15
16
17
18
19
# File 'lib/json/schema_dsl/renderers/alias.rb', line 15

def visit(entity)
  traverse(entity
    .transform_keys { |key| ALIASES[key.to_s]&.to_sym || key }
    .transform_keys { |key| camelize_snake_cased(key) })
end