metaschema 0.2.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +155 -28
- data/README.adoc +54 -4
- data/lib/metaschema/allowed_value_type.rb +1 -1
- data/lib/metaschema/anchor_type.rb +1 -1
- data/lib/metaschema/augment_type.rb +39 -0
- data/lib/metaschema/code_type.rb +1 -1
- data/lib/metaschema/constraint_validator.rb +483 -0
- data/lib/metaschema/inline_markup_type.rb +1 -1
- data/lib/metaschema/json_schema_generator.rb +456 -0
- data/lib/metaschema/list_item_type.rb +1 -1
- data/lib/metaschema/markdown_doc_generator.rb +354 -0
- data/lib/metaschema/markup_line_datatype.rb +1 -1
- data/lib/metaschema/markup_multiline_datatype.rb +41 -0
- data/lib/metaschema/metapath_evaluator.rb +385 -0
- data/lib/metaschema/model_generator/assembly_factory.rb +1583 -0
- data/lib/metaschema/model_generator/field_factory.rb +275 -0
- data/lib/metaschema/model_generator/services/collapsibles_collapser.rb +82 -0
- data/lib/metaschema/model_generator/services/field_deserializer.rb +92 -0
- data/lib/metaschema/model_generator/services/field_serializer.rb +111 -0
- data/lib/metaschema/model_generator/utils.rb +64 -0
- data/lib/metaschema/model_generator.rb +280 -0
- data/lib/metaschema/preformatted_type.rb +1 -1
- data/lib/metaschema/root.rb +2 -0
- data/lib/metaschema/ruby_source_emitter.rb +875 -0
- data/lib/metaschema/table_cell_type.rb +1 -1
- data/lib/metaschema/type_mapper.rb +102 -0
- data/lib/metaschema/version.rb +1 -1
- data/lib/metaschema.rb +9 -0
- metadata +17 -2
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
module Metaschema
|
|
4
4
|
class TableCellType < Lutaml::Model::Serializable
|
|
5
|
-
attribute :content, :string
|
|
5
|
+
attribute :content, :string, collection: true
|
|
6
6
|
attribute :align, :string, default: -> { "left" }
|
|
7
7
|
attribute :a, AnchorType, collection: true
|
|
8
8
|
attribute :insert, InsertType, collection: true
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Metaschema
|
|
4
|
+
class TypeMapper
|
|
5
|
+
TYPE_MAP = {
|
|
6
|
+
# Basic types
|
|
7
|
+
"string" => :string,
|
|
8
|
+
"token" => :string,
|
|
9
|
+
"boolean" => :boolean,
|
|
10
|
+
"integer" => :integer,
|
|
11
|
+
"decimal" => :decimal,
|
|
12
|
+
|
|
13
|
+
# Integer subtypes
|
|
14
|
+
"positive-integer" => :integer,
|
|
15
|
+
"negative-integer" => :integer,
|
|
16
|
+
"non-positive-integer" => :integer,
|
|
17
|
+
"non-negative-integer" => :integer,
|
|
18
|
+
|
|
19
|
+
# Date/time types
|
|
20
|
+
"date" => :date,
|
|
21
|
+
"dateTime" => :date_time,
|
|
22
|
+
"date-with-timezone" => :date,
|
|
23
|
+
"date-time-with-timezone" => :date_time,
|
|
24
|
+
"day-time-duration" => :string,
|
|
25
|
+
|
|
26
|
+
# String subtypes
|
|
27
|
+
"uuid" => :string,
|
|
28
|
+
"uri" => :string,
|
|
29
|
+
"uri-reference" => :string,
|
|
30
|
+
"email" => :string,
|
|
31
|
+
"email-address" => :string,
|
|
32
|
+
"hostname" => :string,
|
|
33
|
+
"ip-address" => :string,
|
|
34
|
+
"ip-v4-address" => :string,
|
|
35
|
+
"ip-v6-address" => :string,
|
|
36
|
+
"base64" => :string,
|
|
37
|
+
|
|
38
|
+
# Markup types — use Metaschema's own types
|
|
39
|
+
"markup-line" => Metaschema::MarkupLineDatatype,
|
|
40
|
+
"markup-multiline" => Metaschema::MarkupMultilineDatatype,
|
|
41
|
+
}.freeze
|
|
42
|
+
|
|
43
|
+
MARKUP_TYPES = %w[markup-line markup-multiline].freeze
|
|
44
|
+
|
|
45
|
+
# Default JSON value key by data type. Determines the JSON property
|
|
46
|
+
# name that holds a field's content value when serialized.
|
|
47
|
+
JSON_VALUE_KEY = {
|
|
48
|
+
"markup-line" => "RICHTEXT",
|
|
49
|
+
"markup-multiline" => "prose",
|
|
50
|
+
}.freeze
|
|
51
|
+
|
|
52
|
+
class << self
|
|
53
|
+
def map(as_type)
|
|
54
|
+
TYPE_MAP[as_type.to_s] || :string
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def markup?(as_type)
|
|
58
|
+
MARKUP_TYPES.include?(as_type.to_s)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def multiline?(as_type)
|
|
62
|
+
as_type.to_s == "markup-multiline"
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Returns the default JSON value key for the given data type.
|
|
66
|
+
# E.g. "markup-line" -> "RICHTEXT", "markup-multiline" -> "prose",
|
|
67
|
+
# everything else -> "STRVALUE".
|
|
68
|
+
def json_value_key(as_type)
|
|
69
|
+
JSON_VALUE_KEY[as_type.to_s] || "STRVALUE"
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# Register format-specific serializers for types that lutaml-model
|
|
73
|
+
# doesn't handle correctly out of the box.
|
|
74
|
+
def register_serializers!
|
|
75
|
+
# Decimal JSON — BigDecimal#to_s defaults to scientific
|
|
76
|
+
# notation ("0.11e1"); JSON needs plain notation (1.1)
|
|
77
|
+
Lutaml::Model::Type::Value.register_format_type_serializer(
|
|
78
|
+
:json, Lutaml::Model::Type::Decimal,
|
|
79
|
+
to: lambda { |inst|
|
|
80
|
+
return nil unless inst.value
|
|
81
|
+
|
|
82
|
+
v = inst.value
|
|
83
|
+
v = Lutaml::Model::Type::Decimal.cast(v) unless v.is_a?(BigDecimal)
|
|
84
|
+
v.to_f
|
|
85
|
+
}
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
# Decimal XML — same scientific notation issue
|
|
89
|
+
Lutaml::Model::Type::Value.register_format_type_serializer(
|
|
90
|
+
:xml, Lutaml::Model::Type::Decimal,
|
|
91
|
+
to: lambda { |inst|
|
|
92
|
+
return nil unless inst.value
|
|
93
|
+
|
|
94
|
+
v = inst.value
|
|
95
|
+
v = Lutaml::Model::Type::Decimal.cast(v) unless v.is_a?(BigDecimal)
|
|
96
|
+
v.to_s("F")
|
|
97
|
+
}
|
|
98
|
+
)
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
data/lib/metaschema/version.rb
CHANGED
data/lib/metaschema.rb
CHANGED
|
@@ -63,6 +63,7 @@ module Metaschema
|
|
|
63
63
|
autoload :ListItemType, "metaschema/list_item_type"
|
|
64
64
|
autoload :ListType, "metaschema/list_type"
|
|
65
65
|
autoload :MarkupLineDatatype, "metaschema/markup_line_datatype"
|
|
66
|
+
autoload :MarkupMultilineDatatype, "metaschema/markup_multiline_datatype"
|
|
66
67
|
autoload :MatchesConstraintType, "metaschema/matches_constraint_type"
|
|
67
68
|
autoload :MetaschemaImportType, "metaschema/metaschema_import_type"
|
|
68
69
|
autoload :MetaschemaConstraints, "metaschema/metaschema_constraints"
|
|
@@ -97,4 +98,12 @@ module Metaschema
|
|
|
97
98
|
autoload :FormalName, "metaschema/formal_name"
|
|
98
99
|
autoload :SchemaVersion, "metaschema/schema_version"
|
|
99
100
|
autoload :ShortName, "metaschema/short_name"
|
|
101
|
+
autoload :AugmentType, "metaschema/augment_type"
|
|
102
|
+
autoload :ConstraintValidator, "metaschema/constraint_validator"
|
|
103
|
+
autoload :JsonSchemaGenerator, "metaschema/json_schema_generator"
|
|
104
|
+
autoload :MarkdownDocGenerator, "metaschema/markdown_doc_generator"
|
|
105
|
+
autoload :MetapathEvaluator, "metaschema/metapath_evaluator"
|
|
106
|
+
autoload :ModelGenerator, "metaschema/model_generator"
|
|
107
|
+
autoload :RubySourceEmitter, "metaschema/ruby_source_emitter"
|
|
108
|
+
autoload :TypeMapper, "metaschema/type_mapper"
|
|
100
109
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: metaschema
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-04-
|
|
11
|
+
date: 2026-04-24 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: lutaml-model
|
|
@@ -74,10 +74,12 @@ files:
|
|
|
74
74
|
- lib/metaschema/assembly.rb
|
|
75
75
|
- lib/metaschema/assembly_model_type.rb
|
|
76
76
|
- lib/metaschema/assembly_reference_type.rb
|
|
77
|
+
- lib/metaschema/augment_type.rb
|
|
77
78
|
- lib/metaschema/block_quote_type.rb
|
|
78
79
|
- lib/metaschema/choice_type.rb
|
|
79
80
|
- lib/metaschema/code_type.rb
|
|
80
81
|
- lib/metaschema/constraint_let_type.rb
|
|
82
|
+
- lib/metaschema/constraint_validator.rb
|
|
81
83
|
- lib/metaschema/define_assembly_constraints_type.rb
|
|
82
84
|
- lib/metaschema/define_field_constraints_type.rb
|
|
83
85
|
- lib/metaschema/define_flag_constraints_type.rb
|
|
@@ -107,15 +109,26 @@ files:
|
|
|
107
109
|
- lib/metaschema/insert_type.rb
|
|
108
110
|
- lib/metaschema/json_base_uri.rb
|
|
109
111
|
- lib/metaschema/json_key_type.rb
|
|
112
|
+
- lib/metaschema/json_schema_generator.rb
|
|
110
113
|
- lib/metaschema/json_value_key.rb
|
|
111
114
|
- lib/metaschema/json_value_key_flag_type.rb
|
|
112
115
|
- lib/metaschema/key_field.rb
|
|
113
116
|
- lib/metaschema/list_item_type.rb
|
|
114
117
|
- lib/metaschema/list_type.rb
|
|
118
|
+
- lib/metaschema/markdown_doc_generator.rb
|
|
115
119
|
- lib/metaschema/markup_line_datatype.rb
|
|
120
|
+
- lib/metaschema/markup_multiline_datatype.rb
|
|
116
121
|
- lib/metaschema/matches_constraint_type.rb
|
|
122
|
+
- lib/metaschema/metapath_evaluator.rb
|
|
117
123
|
- lib/metaschema/metaschema_constraints.rb
|
|
118
124
|
- lib/metaschema/metaschema_import_type.rb
|
|
125
|
+
- lib/metaschema/model_generator.rb
|
|
126
|
+
- lib/metaschema/model_generator/assembly_factory.rb
|
|
127
|
+
- lib/metaschema/model_generator/field_factory.rb
|
|
128
|
+
- lib/metaschema/model_generator/services/collapsibles_collapser.rb
|
|
129
|
+
- lib/metaschema/model_generator/services/field_deserializer.rb
|
|
130
|
+
- lib/metaschema/model_generator/services/field_serializer.rb
|
|
131
|
+
- lib/metaschema/model_generator/utils.rb
|
|
119
132
|
- lib/metaschema/namespace.rb
|
|
120
133
|
- lib/metaschema/namespace_binding_type.rb
|
|
121
134
|
- lib/metaschema/namespace_value.rb
|
|
@@ -125,6 +138,7 @@ files:
|
|
|
125
138
|
- lib/metaschema/remarks_type.rb
|
|
126
139
|
- lib/metaschema/root.rb
|
|
127
140
|
- lib/metaschema/root_name.rb
|
|
141
|
+
- lib/metaschema/ruby_source_emitter.rb
|
|
128
142
|
- lib/metaschema/schema_version.rb
|
|
129
143
|
- lib/metaschema/scope.rb
|
|
130
144
|
- lib/metaschema/short_name.rb
|
|
@@ -138,6 +152,7 @@ files:
|
|
|
138
152
|
- lib/metaschema/targeted_index_has_key_constraint_type.rb
|
|
139
153
|
- lib/metaschema/targeted_key_constraint_type.rb
|
|
140
154
|
- lib/metaschema/targeted_matches_constraint_type.rb
|
|
155
|
+
- lib/metaschema/type_mapper.rb
|
|
141
156
|
- lib/metaschema/use_name_type.rb
|
|
142
157
|
- lib/metaschema/version.rb
|
|
143
158
|
- sig/metaschema.rbs
|