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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8430ee05ae7a85561689c25a0404d06ec3484b6ce006fad3ac194fee3bf909ed
4
- data.tar.gz: 986832e20e5a6c492b766187183f88f498ab62f04d914c25b1853ff01791420e
3
+ metadata.gz: 13c76286aac4a084b992310573e600bff798224156cbbfb1ec5a27b80fdf9ec8
4
+ data.tar.gz: 509b4a6032bec02787b65783e7ff253133b16ffebc1398bc9470f96a53403258
5
5
  SHA512:
6
- metadata.gz: a9e6dfbf033a45d9ab7d92db610a4afd2a74c3e2101bc2ce47522dbf77207762122356fddc3390267679a5e45ac3a1e478bc8162b1dedd8e24737fb05502c47d
7
- data.tar.gz: 6cff0e8d3fd500ad980ae84d2a1b7f1f5db53f76151004c84dc55c4b06e038fd21f9beccfddbab567cacd04855db62250807764439fbaa47492fdf40af5ccd5a
6
+ metadata.gz: 6920a39f399434cbb2634f0395ae346af06bd80d95bebfba2cceba3ff08f4421cf483bc5b3078672d596b2df5b05c0d3a33afe595859e8df22052fc08b327c53
7
+ data.tar.gz: deaba8e56599fdab8902215b520eb7ba057b2fb82aab57126c5acea59a39b3916286dbd54d6563e4f7da7764b3a39a60c21b4f2f1d913b43d893980bf9acedb1
data/.rubocop_todo.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2026-04-14 10:25:31 UTC using RuboCop version 1.86.1.
3
+ # on 2026-04-24 02:52:57 UTC using RuboCop version 1.86.1.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
@@ -11,48 +11,144 @@ Gemspec/RequiredRubyVersion:
11
11
  Exclude:
12
12
  - 'metaschema.gemspec'
13
13
 
14
- # Offense count: 14
15
- # This cop supports safe autocorrection (--autocorrect).
16
- # Configuration parameters: EnforcedStyle, IndentationWidth.
17
- # SupportedStyles: with_first_argument, with_fixed_indentation
18
- Layout/ArgumentAlignment:
19
- Exclude:
20
- - 'lib/metaschema.rb'
21
-
22
14
  # Offense count: 1
23
15
  # This cop supports safe autocorrection (--autocorrect).
24
- # Configuration parameters: EnforcedStyle.
25
- # SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines
26
- Layout/EmptyLinesAroundModuleBody:
16
+ # Configuration parameters: EnforcedStyleAlignWith.
17
+ # SupportedStylesAlignWith: either, start_of_block, start_of_line
18
+ Layout/BlockAlignment:
27
19
  Exclude:
28
- - 'lib/metaschema.rb'
20
+ - 'lib/metaschema/model_generator/assembly_factory.rb'
29
21
 
30
- # Offense count: 16
22
+ # Offense count: 92
31
23
  # This cop supports safe autocorrection (--autocorrect).
32
24
  # Configuration parameters: Max, AllowHeredoc, AllowURI, AllowQualifiedName, URISchemes, AllowRBSInlineAnnotation, AllowCopDirectives, AllowedPatterns, SplitStrings.
33
25
  # URISchemes: http, https
34
26
  Layout/LineLength:
35
27
  Exclude:
36
- - 'lib/metaschema.rb'
28
+ - 'lib/metaschema/constraint_validator.rb'
29
+ - 'lib/metaschema/json_schema_generator.rb'
30
+ - 'lib/metaschema/markdown_doc_generator.rb'
31
+ - 'lib/metaschema/metapath_evaluator.rb'
32
+ - 'lib/metaschema/model_generator.rb'
33
+ - 'lib/metaschema/model_generator/assembly_factory.rb'
34
+ - 'lib/metaschema/model_generator/field_factory.rb'
35
+ - 'lib/metaschema/model_generator/services/field_deserializer.rb'
36
+ - 'lib/metaschema/ruby_source_emitter.rb'
37
37
  - 'spec/metaschema_spec.rb'
38
+ - 'spec/model_generator_spec.rb'
39
+ - 'spec/ruby_source_emitter_spec.rb'
38
40
 
39
- # Offense count: 14
40
- # This cop supports safe autocorrection (--autocorrect).
41
- # Configuration parameters: AllowInHeredoc.
42
- Layout/TrailingWhitespace:
41
+ # Offense count: 2
42
+ # Configuration parameters: IgnoreLiteralBranches, IgnoreConstantBranches, IgnoreDuplicateElseBranch.
43
+ Lint/DuplicateBranch:
44
+ Exclude:
45
+ - 'lib/metaschema/constraint_validator.rb'
46
+ - 'lib/metaschema/model_generator/assembly_factory.rb'
47
+
48
+ # Offense count: 1
49
+ Lint/IneffectiveAccessModifier:
43
50
  Exclude:
44
- - 'lib/metaschema.rb'
51
+ - 'lib/metaschema/constraint_validator.rb'
45
52
 
46
53
  # Offense count: 1
54
+ # This cop supports safe autocorrection (--autocorrect).
55
+ # Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods, IgnoreNotImplementedMethods, NotImplementedExceptions.
56
+ # NotImplementedExceptions: NotImplementedError
57
+ Lint/UnusedMethodArgument:
58
+ Exclude:
59
+ - 'lib/metaschema/markdown_doc_generator.rb'
60
+
61
+ # Offense count: 84
62
+ # Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes, Max.
63
+ Metrics/AbcSize:
64
+ Exclude:
65
+ - 'lib/metaschema/constraint_validator.rb'
66
+ - 'lib/metaschema/json_schema_generator.rb'
67
+ - 'lib/metaschema/markdown_doc_generator.rb'
68
+ - 'lib/metaschema/metapath_evaluator.rb'
69
+ - 'lib/metaschema/model_generator.rb'
70
+ - 'lib/metaschema/model_generator/assembly_factory.rb'
71
+ - 'lib/metaschema/model_generator/field_factory.rb'
72
+ - 'lib/metaschema/model_generator/services/field_serializer.rb'
73
+ - 'lib/metaschema/ruby_source_emitter.rb'
74
+ - 'lib/metaschema/type_mapper.rb'
75
+
76
+ # Offense count: 11
47
77
  # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns, inherit_mode.
48
78
  # AllowedMethods: refine
49
79
  Metrics/BlockLength:
50
- Max: 28
80
+ Max: 46
51
81
 
52
- # Offense count: 2
82
+ # Offense count: 87
83
+ # Configuration parameters: AllowedMethods, AllowedPatterns, Max.
84
+ Metrics/CyclomaticComplexity:
85
+ Exclude:
86
+ - 'lib/metaschema/constraint_validator.rb'
87
+ - 'lib/metaschema/json_schema_generator.rb'
88
+ - 'lib/metaschema/markdown_doc_generator.rb'
89
+ - 'lib/metaschema/metapath_evaluator.rb'
90
+ - 'lib/metaschema/model_generator.rb'
91
+ - 'lib/metaschema/model_generator/assembly_factory.rb'
92
+ - 'lib/metaschema/model_generator/field_factory.rb'
93
+ - 'lib/metaschema/model_generator/services/field_deserializer.rb'
94
+ - 'lib/metaschema/ruby_source_emitter.rb'
95
+
96
+ # Offense count: 104
97
+ # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
98
+ Metrics/MethodLength:
99
+ Max: 212
100
+
101
+ # Offense count: 4
102
+ # Configuration parameters: CountKeywordArgs, MaxOptionalParameters.
103
+ Metrics/ParameterLists:
104
+ Max: 7
105
+
106
+ # Offense count: 74
107
+ # Configuration parameters: AllowedMethods, AllowedPatterns, Max.
108
+ Metrics/PerceivedComplexity:
109
+ Exclude:
110
+ - 'lib/metaschema/constraint_validator.rb'
111
+ - 'lib/metaschema/json_schema_generator.rb'
112
+ - 'lib/metaschema/markdown_doc_generator.rb'
113
+ - 'lib/metaschema/metapath_evaluator.rb'
114
+ - 'lib/metaschema/model_generator.rb'
115
+ - 'lib/metaschema/model_generator/assembly_factory.rb'
116
+ - 'lib/metaschema/model_generator/field_factory.rb'
117
+ - 'lib/metaschema/model_generator/services/field_deserializer.rb'
118
+ - 'lib/metaschema/ruby_source_emitter.rb'
119
+
120
+ # Offense count: 20
121
+ # Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
122
+ # AllowedNames: as, at, by, cc, db, id, if, in, io, ip, of, on, os, pp, to
123
+ Naming/MethodParameterName:
124
+ Exclude:
125
+ - 'lib/metaschema/json_schema_generator.rb'
126
+ - 'lib/metaschema/markdown_doc_generator.rb'
127
+ - 'lib/metaschema/metapath_evaluator.rb'
128
+
129
+ # Offense count: 1
130
+ RSpec/DescribeMethod:
131
+ Exclude:
132
+ - 'spec/model_generator_spec.rb'
133
+
134
+ # Offense count: 15
53
135
  # Configuration parameters: CountAsOne.
54
136
  RSpec/ExampleLength:
55
- Max: 10
137
+ Max: 20
138
+
139
+ # Offense count: 1
140
+ RSpec/MultipleDescribes:
141
+ Exclude:
142
+ - 'spec/services_spec.rb'
143
+
144
+ # Offense count: 13
145
+ RSpec/MultipleExpectations:
146
+ Max: 2
147
+
148
+ # Offense count: 4
149
+ # Configuration parameters: AllowSubject.
150
+ RSpec/MultipleMemoizedHelpers:
151
+ Max: 7
56
152
 
57
153
  # Offense count: 1
58
154
  # Configuration parameters: AllowedPatterns.
@@ -62,9 +158,40 @@ RSpec/NoExpectationExample:
62
158
  - 'spec/metaschema_spec.rb'
63
159
 
64
160
  # Offense count: 2
65
- # This cop supports safe autocorrection (--autocorrect).
66
- # Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
67
- # SupportedStyles: single_quotes, double_quotes
68
- Style/StringLiterals:
161
+ RSpec/RepeatedDescription:
162
+ Exclude:
163
+ - 'spec/type_mapper_spec.rb'
164
+
165
+ # Offense count: 2
166
+ RSpec/RepeatedExample:
167
+ Exclude:
168
+ - 'spec/type_mapper_spec.rb'
169
+
170
+ # Offense count: 3
171
+ # Configuration parameters: CustomTransform, IgnoreMethods, IgnoreMetadata, InflectorPath, EnforcedInflector.
172
+ # SupportedInflectors: default, active_support
173
+ RSpec/SpecFilePathFormat:
174
+ Exclude:
175
+ - 'spec/model_generator_spec.rb'
176
+ - 'spec/ruby_source_emitter_spec.rb'
177
+ - 'spec/type_mapper_spec.rb'
178
+
179
+ # Offense count: 1
180
+ Style/DocumentDynamicEvalDefinition:
181
+ Exclude:
182
+ - 'lib/metaschema/model_generator/utils.rb'
183
+
184
+ # Offense count: 1
185
+ # Configuration parameters: AllowedMethods.
186
+ # AllowedMethods: respond_to_missing?
187
+ Style/OptionalBooleanParameter:
188
+ Exclude:
189
+ - 'lib/metaschema/model_generator/field_factory.rb'
190
+
191
+ # Offense count: 2
192
+ # This cop supports unsafe autocorrection (--autocorrect-all).
193
+ # Configuration parameters: Mode.
194
+ Style/StringConcatenation:
69
195
  Exclude:
70
- - 'lib/metaschema.rb'
196
+ - 'lib/metaschema/model_generator/utils.rb'
197
+ - 'lib/metaschema/ruby_source_emitter.rb'
data/README.adoc CHANGED
@@ -28,15 +28,16 @@ Metaschema-defined information models in the future.
28
28
 
29
29
  == Features
30
30
 
31
- TODO: This list is a TODO list. None of them have been completed.
32
-
33
31
  . Parse, build and round-trip Metaschema XML files
34
32
  . Validate Metaschema XML files against the Metaschema XML Schema
35
33
  . Generate XML (XSD) and JSON Schemas from Metaschema XML files
36
- . Generate Lutaml::Model (Ruby) classes that allow access and manipulation of
37
- Metaschema-defined information models.
34
+ . Generate `Lutaml::Model::Serializable` Ruby classes from Metaschema XML
35
+ definitions, with full XML and JSON round-trip fidelity
38
36
  . Validate Metaschema-defined information models against the Metaschema XML
39
37
  Schema
38
+ . Support for SINGLETON_OR_ARRAY field patterns via service object pipeline
39
+ (FieldSerializer / FieldDeserializer)
40
+ . UNWRAPPED XML field handling with delegate mappings
40
41
 
41
42
  == Installation
42
43
 
@@ -94,6 +95,55 @@ ms.assemblies
94
95
  # [Vendor, Computer, ...]
95
96
  ----
96
97
 
98
+ == Model Generation
99
+
100
+ The `Metaschema::ModelGenerator` generates Ruby classes from Metaschema XML
101
+ definitions. It uses a factory-based architecture:
102
+
103
+ [horizontal]
104
+ `ModelGenerator`:: Orchestrator — handles imports, augments, and delegates to factories
105
+ `FieldFactory`:: Creates field classes from Metaschema field definitions
106
+ `AssemblyFactory`:: Creates assembly classes with XML and JSON mappings
107
+ `FieldSerializer`:: Service object for normalizing field values to JSON
108
+ `FieldDeserializer`:: Service object for denormalizing JSON values to field instances
109
+ `CollapsiblesCollapser`:: Groups collapsible fields by shared flag values
110
+ `Utils`:: Shared naming and utility helpers
111
+
112
+ === Generating Ruby source
113
+
114
+ [source,ruby]
115
+ ----
116
+ # Generate a single Ruby file with all classes
117
+ source = Metaschema::ModelGenerator.to_ruby_source(
118
+ "oscal_complete_metaschema.xml",
119
+ module_name: "Oscal"
120
+ )
121
+
122
+ # Generate split files (one per class)
123
+ files = Metaschema::ModelGenerator.to_ruby_source(
124
+ "oscal_complete_metaschema.xml",
125
+ module_name: "Oscal",
126
+ split: true
127
+ )
128
+ ----
129
+
130
+ === Type System
131
+
132
+ The `TypeMapper` maps Metaschema data types to Ruby/Lutaml::Model types:
133
+
134
+ [horizontal]
135
+ `string`, `token`, `uri`, etc.:: `:string`
136
+ `integer`:: `:integer`
137
+ `boolean`:: `:boolean`
138
+ `date`, `date-time`:: `:date`, `:date_time`
139
+ `markup-line`:: `Metaschema::MarkupLineDatatype`
140
+ `markup-multiline`:: `Metaschema::MarkupMultilineDatatype`
141
+
142
+ === Dependencies
143
+
144
+ * `lutaml-model ~> 0.8.0` — serialization framework
145
+ * `moxml >= 0.1.15` — XML adapter (uses `namespace_validation_mode=` API)
146
+
97
147
 
98
148
  == Tests
99
149
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Metaschema
4
4
  class AllowedValueType < Lutaml::Model::Serializable
5
- attribute :content, :string
5
+ attribute :content, :string, collection: true
6
6
  attribute :value, :string
7
7
  attribute :deprecated, :string
8
8
  attribute :a, AnchorType, collection: true
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Metaschema
4
4
  class AnchorType < Lutaml::Model::Serializable
5
- attribute :content, :string
5
+ attribute :content, :string, collection: true
6
6
  attribute :href, :string
7
7
  attribute :title, :string
8
8
  attribute :code, CodeType, collection: true
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Metaschema
4
+ # Represents an <augment> element in a metaschema document.
5
+ # Augments add documentation, flags, or properties to definitions
6
+ # from imported modules without modifying the original module.
7
+ #
8
+ # Example:
9
+ # <augment name="metadata">
10
+ # <formal-name>Document Metadata</formal-name>
11
+ # <description>Provides information about the document.</description>
12
+ # <flag ref="document-id" />
13
+ # </augment>
14
+ class AugmentType < Lutaml::Model::Serializable
15
+ attribute :name, :string
16
+ attribute :formal_name, FormalName
17
+ attribute :description, MarkupLineDatatype
18
+ attribute :prop, PropertyType, collection: true
19
+ attribute :remarks, RemarksType
20
+ attribute :example, ExampleType, collection: true
21
+ attribute :flag, FlagReferenceType, collection: true
22
+ attribute :define_flag, InlineFlagDefinitionType, collection: true
23
+
24
+ xml do
25
+ element "augment"
26
+ ordered
27
+ namespace ::Metaschema::Namespace
28
+
29
+ map_attribute "name", to: :name
30
+ map_element "formal-name", to: :formal_name
31
+ map_element "description", to: :description
32
+ map_element "prop", to: :prop
33
+ map_element "remarks", to: :remarks
34
+ map_element "example", to: :example
35
+ map_element "flag", to: :flag
36
+ map_element "define-flag", to: :define_flag
37
+ end
38
+ end
39
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Metaschema
4
4
  class CodeType < Lutaml::Model::Serializable
5
- attribute :content, :string
5
+ attribute :content, :string, collection: true
6
6
  attribute :klass, :string
7
7
  attribute :a, AnchorType, collection: true
8
8
  attribute :insert, InsertType, collection: true