Module: Shale::Schema Private

Defined in:
lib/shale/schema.rb,
lib/shale/schema/xml_compiler.rb,
lib/shale/schema/compiler/date.rb,
lib/shale/schema/compiler/time.rb,
lib/shale/schema/json_compiler.rb,
lib/shale/schema/xml_generator.rb,
lib/shale/schema/compiler/float.rb,
lib/shale/schema/compiler/value.rb,
lib/shale/schema/json_generator.rb,
lib/shale/schema/compiler/string.rb,
lib/shale/schema/compiler/boolean.rb,
lib/shale/schema/compiler/complex.rb,
lib/shale/schema/compiler/integer.rb,
lib/shale/schema/compiler/property.rb,
lib/shale/schema/json_generator/ref.rb,
lib/shale/schema/json_generator/base.rb,
lib/shale/schema/json_generator/date.rb,
lib/shale/schema/json_generator/time.rb,
lib/shale/schema/compiler/xml_complex.rb,
lib/shale/schema/json_generator/float.rb,
lib/shale/schema/json_generator/value.rb,
lib/shale/schema/xml_generator/import.rb,
lib/shale/schema/xml_generator/schema.rb,
lib/shale/schema/compiler/xml_property.rb,
lib/shale/schema/json_generator/object.rb,
lib/shale/schema/json_generator/schema.rb,
lib/shale/schema/json_generator/string.rb,
lib/shale/schema/xml_generator/element.rb,
lib/shale/schema/json_generator/boolean.rb,
lib/shale/schema/json_generator/integer.rb,
lib/shale/schema/xml_generator/attribute.rb,
lib/shale/schema/json_generator/collection.rb,
lib/shale/schema/xml_generator/ref_element.rb,
lib/shale/schema/xml_generator/complex_type.rb,
lib/shale/schema/xml_generator/ref_attribute.rb,
lib/shale/schema/xml_generator/typed_element.rb,
lib/shale/schema/xml_generator/typed_attribute.rb

Overview

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

Module for handling JSON and XML schema

Defined Under Namespace

Modules: Compiler Classes: JSONCompiler, JSONGenerator, XMLCompiler, XMLGenerator

Class Method Summary collapse

Class Method Details

.from_json(schemas, root_name: nil, namespace_mapping: nil) ⇒ Array<String>

Generate Shale model from JSON Schema

Examples:

Shale::Schema.from_json([json_schema1, json_schema2], root_name: 'foobar')
# => [model1, model2, model3]

Parameters:

  • schemas (Array<String>)
  • root_name (String, nil) (defaults to: nil)
  • namespace_mapping (Hash<String, String>, nil) (defaults to: nil)

Returns:

  • (Array<String>)


50
51
52
53
54
55
56
# File 'lib/shale/schema.rb', line 50

def self.from_json(schemas, root_name: nil, namespace_mapping: nil)
  JSONCompiler.new.to_models(
    schemas,
    root_name: root_name,
    namespace_mapping: namespace_mapping
  )
end

.from_xml(schemas, namespace_mapping: nil) ⇒ Array<String>

Generate Shale model from XML Schema

Examples:

Shale::Schema.from_xml([xml_schema1, xml_schema2])
# => [model1, model2, model3]

Parameters:

  • schemas (Array<String>)
  • namespace_mapping (Hash<String, String>, nil) (defaults to: nil)

Returns:

  • (Array<String>)


88
89
90
# File 'lib/shale/schema.rb', line 88

def self.from_xml(schemas, namespace_mapping: nil)
  XMLCompiler.new.to_models(schemas, namespace_mapping: namespace_mapping)
end

.to_json(klass, id: nil, title: nil, description: nil, pretty: false) ⇒ String

Generate JSON Schema from Shale model

Examples:

Shale::Schema.to_json(Person, id: 'My ID', description: 'My description', pretty: true)
# => JSON schema

Parameters:

  • klass (Shale::Mapper)
  • id (String, nil) (defaults to: nil)
  • description (String, nil) (defaults to: nil)
  • pretty (true, false) (defaults to: false)

Returns:

  • (String)


27
28
29
30
31
32
33
34
35
# File 'lib/shale/schema.rb', line 27

def self.to_json(klass, id: nil, title: nil, description: nil, pretty: false)
  JSONGenerator.new.to_schema(
    klass,
    id: id,
    title: title,
    description: description,
    pretty: pretty
  )
end

.to_xml(klass, base_name = nil, pretty: false, declaration: false) ⇒ Hash<String, String>

Generate XML Schema from Shale model

Examples:

Shale::Schema.to_xml(Person, pretty: true, declaration: true)
# => { 'schema0.xsd' => <JSON schema>, 'schema1.xsd' => <JSON schema> }

Parameters:

  • klass (Shale::Mapper)
  • base_name (String, nil) (defaults to: nil)
  • pretty (true, false) (defaults to: false)
  • declaration (true, false) (defaults to: false)

Returns:

  • (Hash<String, String>)


72
73
74
# File 'lib/shale/schema.rb', line 72

def self.to_xml(klass, base_name = nil, pretty: false, declaration: false)
  XMLGenerator.new.to_schemas(klass, base_name, pretty: pretty, declaration: declaration)
end