Class: Skit::JsonSchema::SchemaAnalyzer
- Inherits:
-
Object
- Object
- Skit::JsonSchema::SchemaAnalyzer
- Extended by:
- T::Sig
- Defined in:
- lib/skit/json_schema/schema_analyzer.rb
Instance Method Summary collapse
- #analyze ⇒ Object
-
#initialize(schema, config) ⇒ SchemaAnalyzer
constructor
A new instance of SchemaAnalyzer.
Constructor Details
#initialize(schema, config) ⇒ SchemaAnalyzer
Returns a new instance of SchemaAnalyzer.
12 13 14 15 16 17 18 19 20 |
# File 'lib/skit/json_schema/schema_analyzer.rb', line 12 def initialize(schema, config) @schema = schema @schemer = T.let(JSONSchemer.schema(@schema), T.untyped) @nested_structs = T.let({}, T::Hash[String, Definitions::Struct]) @const_types = T.let({}, T::Hash[String, Definitions::ConstType]) @enum_types = T.let({}, T::Hash[String, Definitions::EnumType]) @config = config @ref_stack = T.let([], T::Array[String]) end |
Instance Method Details
#analyze ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/skit/json_schema/schema_analyzer.rb', line 23 def analyze validate_schema # Only object type is supported at the top level raise Skit::Error, "Only object type schemas are supported at the top level" unless @schema["type"] == "object" root_class_name_path = determine_root_class_name root_struct = build_struct(@schema, root_class_name_path) Definitions::Module.new( root_struct: root_struct, nested_structs: @nested_structs.values, const_types: @const_types.values, enum_types: @enum_types.values ) end |