Skip to content

feat: code generation pipeline with doubled method name fix#20

Open
ronaldtse wants to merge 1 commit intomainfrom
rt-metaschema-instance
Open

feat: code generation pipeline with doubled method name fix#20
ronaldtse wants to merge 1 commit intomainfrom
rt-metaschema-instance

Conversation

@ronaldtse
Copy link
Copy Markdown
Contributor

@ronaldtse ronaldtse commented Apr 20, 2026

Summary

  • Restore model_generator.rb, ruby_source_emitter.rb, and supporting classes (TypeMapper, ConstraintValidator, AugmentType, etc.)
  • Fix the doubled method name bug in emit_scalar_from_method where rest.split("_").first incorrectly parsed multi-word attribute names (e.g. last_modifiedlast). Now uses find_attr_for_method to resolve from key-value mappings.
  • Add to_ruby_source class method on ModelGenerator for generating Ruby source from metaschema files
  • Add augment attribute to Root model, all autoload entries

Test plan

  • All 74 tests pass (bundle exec rake spec)
  • Regenerated oscal all_models.rb with fixed emitter — 61 tests pass in oscal repo
  • Verify no regressions in existing metaschema round-trip tests

@ronaldtse ronaldtse force-pushed the rt-metaschema-instance branch from 059ee61 to 6a9dc42 Compare April 21, 2026 03:55
@ronaldtse ronaldtse changed the title feat: metaschema engine, OSCAL integration, and tooling feat: code generation pipeline with doubled method name fix Apr 21, 2026
Add full code generation pipeline: ModelGenerator creates in-memory Ruby
classes from NIST Metaschema definitions, RubySourceEmitter serializes
them to .rb source files.

Key components:
- ModelGenerator: import resolution, class generation with XML/JSON/YAML
  mappings, constraint validation
- RubySourceEmitter: introspects generated classes, emits Ruby source
- TypeMapper: maps metaschema types to lutaml-model types
- ConstraintValidator, JsonSchemaGenerator, MarkdownDocGenerator,
  MetapathEvaluator: supporting tooling

Fixes:
- Doubled method name bug in emit_scalar_from_method (rest.split('_').first
  now uses find_attr_for_method for correct multi-word attribute resolution)
- Mixed content collection enforcement (collection: true on markup fields)
- Singleton object handling in assembly SOA JSON/YAML callbacks
- Reserve 'hash' attribute name to avoid overriding Object#hash
- Add 'augment' support to Root model, DateTime to YAML safe_load

Tests (97, 0 failures):
- 62 metaschema XML round-trip tests
- 12 source code generation tests
- 23 dynamic model creation tests with OSCAL metaschemas
  (class generation, import resolution, XML/JSON/YAML round-trips,
  6 real OSCAL test catalogs)

Adds usnistgov/OSCAL submodule for OSCAL metaschema definitions and
profile-resolution test fixtures.
@ronaldtse ronaldtse force-pushed the rt-metaschema-instance branch from 20da7e5 to 426f156 Compare April 21, 2026 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant