metaschema 0.2.0 → 0.2.1

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.
@@ -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,82 @@
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
+
25
+ # String subtypes
26
+ "uuid" => :string,
27
+ "uri" => :string,
28
+ "email" => :string,
29
+ "hostname" => :string,
30
+ "ip-address" => :string,
31
+
32
+ # Markup types — use Metaschema's own types
33
+ "markup-line" => Metaschema::MarkupLineDatatype,
34
+ "markup-multiline" => Metaschema::MarkupLineDatatype,
35
+ }.freeze
36
+
37
+ MARKUP_TYPES = %w[markup-line markup-multiline].freeze
38
+
39
+ class << self
40
+ def map(as_type)
41
+ TYPE_MAP[as_type.to_s] || :string
42
+ end
43
+
44
+ def markup?(as_type)
45
+ MARKUP_TYPES.include?(as_type.to_s)
46
+ end
47
+
48
+ def multiline?(as_type)
49
+ as_type.to_s == "markup-multiline"
50
+ end
51
+
52
+ # Register format-specific serializers for types that lutaml-model
53
+ # doesn't handle correctly out of the box.
54
+ def register_serializers!
55
+ # Decimal JSON — BigDecimal#to_s defaults to scientific
56
+ # notation ("0.11e1"); JSON needs plain notation (1.1)
57
+ Lutaml::Model::Type::Value.register_format_type_serializer(
58
+ :json, Lutaml::Model::Type::Decimal,
59
+ to: lambda { |inst|
60
+ return nil unless inst.value
61
+
62
+ v = inst.value
63
+ v = Lutaml::Model::Type::Decimal.cast(v) unless v.is_a?(BigDecimal)
64
+ v.to_f
65
+ }
66
+ )
67
+
68
+ # Decimal XML — same scientific notation issue
69
+ Lutaml::Model::Type::Value.register_format_type_serializer(
70
+ :xml, Lutaml::Model::Type::Decimal,
71
+ to: lambda { |inst|
72
+ return nil unless inst.value
73
+
74
+ v = inst.value
75
+ v = Lutaml::Model::Type::Decimal.cast(v) unless v.is_a?(BigDecimal)
76
+ v.to_s("F")
77
+ }
78
+ )
79
+ end
80
+ end
81
+ end
82
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Metaschema
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.1"
5
5
  end
data/lib/metaschema.rb CHANGED
@@ -97,4 +97,12 @@ module Metaschema
97
97
  autoload :FormalName, "metaschema/formal_name"
98
98
  autoload :SchemaVersion, "metaschema/schema_version"
99
99
  autoload :ShortName, "metaschema/short_name"
100
+ autoload :AugmentType, "metaschema/augment_type"
101
+ autoload :ConstraintValidator, "metaschema/constraint_validator"
102
+ autoload :JsonSchemaGenerator, "metaschema/json_schema_generator"
103
+ autoload :MarkdownDocGenerator, "metaschema/markdown_doc_generator"
104
+ autoload :MetapathEvaluator, "metaschema/metapath_evaluator"
105
+ autoload :ModelGenerator, "metaschema/model_generator"
106
+ autoload :RubySourceEmitter, "metaschema/ruby_source_emitter"
107
+ autoload :TypeMapper, "metaschema/type_mapper"
100
108
  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.0
4
+ version: 0.2.1
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-14 00:00:00.000000000 Z
11
+ date: 2026-04-23 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,19 @@ 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
116
120
  - lib/metaschema/matches_constraint_type.rb
121
+ - lib/metaschema/metapath_evaluator.rb
117
122
  - lib/metaschema/metaschema_constraints.rb
118
123
  - lib/metaschema/metaschema_import_type.rb
124
+ - lib/metaschema/model_generator.rb
119
125
  - lib/metaschema/namespace.rb
120
126
  - lib/metaschema/namespace_binding_type.rb
121
127
  - lib/metaschema/namespace_value.rb
@@ -125,6 +131,7 @@ files:
125
131
  - lib/metaschema/remarks_type.rb
126
132
  - lib/metaschema/root.rb
127
133
  - lib/metaschema/root_name.rb
134
+ - lib/metaschema/ruby_source_emitter.rb
128
135
  - lib/metaschema/schema_version.rb
129
136
  - lib/metaschema/scope.rb
130
137
  - lib/metaschema/short_name.rb
@@ -138,6 +145,7 @@ files:
138
145
  - lib/metaschema/targeted_index_has_key_constraint_type.rb
139
146
  - lib/metaschema/targeted_key_constraint_type.rb
140
147
  - lib/metaschema/targeted_matches_constraint_type.rb
148
+ - lib/metaschema/type_mapper.rb
141
149
  - lib/metaschema/use_name_type.rb
142
150
  - lib/metaschema/version.rb
143
151
  - sig/metaschema.rbs