Skip to content

Commit

Permalink
feat: initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ronaldtse committed Oct 19, 2024
0 parents commit ba2c83f
Show file tree
Hide file tree
Showing 81 changed files with 2,569 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/rake.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: rake

on:
push:
branches: [ master, main ]
tags: [ v* ]
pull_request:
workflow_dispatch:

jobs:
rake:
uses: metanorma/ci/.github/workflows/graphviz-rake.yml@main
22 changes: 22 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: release

on:
workflow_dispatch:
inputs:
next_version:
description: |
Next release version. Possible values: x.y.z, major, minor, patch or pre|rc|etc
required: true
default: 'skip'
push:
tags: [ v* ]

jobs:
release:
uses: metanorma/ci/.github/workflows/rubygems-release.yml@main
with:
next_version: ${{ github.event.inputs.next_version }}
secrets:
rubygems-api-key: ${{ secrets.LUTAML_CI_RUBYGEMS_API_KEY }}
pat_token: ${{ secrets.LUTAML_CI_PAT_TOKEN }}

3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "spec/fixtures/metaschema"]
path = spec/fixtures/metaschema
url = [email protected]:metaschema-framework/metaschema.git
12 changes: 12 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

source "https://rubygems.org"

# Specify your gem's dependencies in metaschema.gemspec
gemspec

gem "rake", "~> 13.0"

gem "rspec", "~> 3.0"

gem "rubocop", "~> 1.21"
128 changes: 128 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
= Metaschema

image:https://img.shields.io/gem/v/metaschema.svg["Gem Version", link="https://rubygems.org/gems/metaschema"]
image:https://github.com/lutaml/metaschema/workflows/rake/badge.svg["Build Status", link="https://github.com/lutaml/metaschema/actions?workflow=rake"]
image:https://codeclimate.com/github/lutaml/metaschema/badges/gpa.svg["Code Climate", link="https://codeclimate.com/github/lutaml/metaschema"]

== Purpose

This Ruby gem implements a parser and generator for the
https://pages.nist.gov/metaschema[NIST Metaschema Information Modeling Framework].

Metaschema is a specification for defining information models in a structured
format (currently via XML). It provides a way to define and manage information
model schemas that can be converted into XML and JSON Schemas.

This library can be used to parse and generate information schemas defined in
the Metaschema XML format.

This library can also be used to generate XML schemas and JSON Schemas from
Metaschema XML files.

NOTE: The Metaschema gem is a work in progress and may not yet support all
features of the Metaschema specification.

NOTE: The Metaschema gem will support the generation of data accessors for
Metaschema-defined information models in the future.


== Features

TODO: This list is a TODO list. None of them have been completed.

. Parse, build and round-trip Metaschema XML files
. Validate Metaschema XML files against the Metaschema XML Schema
. Generate XML (XSD) and JSON Schemas from Metaschema XML files
. Generate Lutaml::Model (Ruby) classes that allow access and manipulation of
Metaschema-defined information models.
. Validate Metaschema-defined information models against the Metaschema XML
Schema

== Installation

To install the metaschema gem, use one of the following methods.

Add this line to your application's Gemfile:

[source,ruby]
----
gem 'metaschema'
----

Then execute:

[source,sh]
----
$ bundle install
----

Or install it directly using:

[source,sh]
----
$ gem install metaschema
----

After installation, you can start using the metaschema gem in your Ruby projects
or via the command-line interface.


== Ruby API

[source,ruby]
----
require 'metaschema'
# Load a Metaschema file
# Sample at spec/fixtures/metaschema/examples/computer-example.xml
ms = Metaschema::Root.from_file("computer-example.xml")
ms.to_xml
# <METASCHEMA xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
# xsi:schemaLocation="http://csrc.nist.gov/ns/oscal/metaschema/1.0 ../schema/xml/metaschema.xsd"
# xmlns="http://csrc.nist.gov/ns/oscal/metaschema/1.0">
# <schema-name>Computer Model</schema-name>
# <schema-version>0.0.5</schema-version>
ms.schema_name
# "Computer Model"
ms.schema_version
# "0.0.5"
ms.assemblies
# [Vendor, Computer, ...]
----


== Tests

The `spec/fixtures` folder contains tests that the Metaschema gem needs to
comply with.

Including:

`spec/fixtures/metaschema`:: the submoduled repository from the
https://github.com/usnistgov/metaschema[Metaschema project]

`spec/fixtures/metaschema/examples`:: examples of Metaschema XML files
(for us to test round-tripping)

`spec/fixtures/metaschema/test-suite`:: the test suite for the Metaschema
project. TODO: This library is to be tested against these files.

`spec/fixtures/metaschema/test-suite/schema-generation`:: these files test
against individual features of Metaschema. TODO: This library needs to run RSpecs
against every directory here each representing a separate feature.

`spec/fixtures/metaschema/test-suite/worked-examples`:: these files are complete
Metaschema XML examples that exercises all features of Metaschema. TODO: This
library needs to run RSpecs against each of these files.



== License

Copyright Ribose.

BSD-3 license.
12 changes: 12 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

require "bundler/gem_tasks"
require "rspec/core/rake_task"

RSpec::Core::RakeTask.new(:spec)

require "rubocop/rake_task"

RuboCop::RakeTask.new

task default: %i[spec rubocop]
11 changes: 11 additions & 0 deletions bin/console
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require "bundler/setup"
require "metaschema"

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.

require "irb"
IRB.start(__FILE__)
8 changes: 8 additions & 0 deletions bin/setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
set -vx

bundle install

# Do any other automated setup that you need to do here
7 changes: 7 additions & 0 deletions exe/metaschema
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require_relative "../lib/metaschema"
require_relative "../lib/metaschema/cli"

Metaschema::Cli::Commands.start(ARGV)
20 changes: 20 additions & 0 deletions lib/metaschema.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

require "lutaml/model"

Lutaml::Model::Config.configure do |config|
require "lutaml/model/xml_adapter/nokogiri_adapter"
config.xml_adapter = Lutaml::Model::XmlAdapter::NokogiriAdapter
end

require_relative "metaschema/version"
require_relative "metaschema/root"

module Metaschema
class Error < StandardError; end

def self.validate(file_path)
root = Root.from_file(file_path)
root.validate_verbose
end
end
48 changes: 48 additions & 0 deletions lib/metaschema/allowed_value_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
require "lutaml/model"

require_relative "anchor_type"
require_relative "code_type"
require_relative "image_type"
require_relative "inline_markup_type"
require_relative "insert_type"

module Metaschema
class AllowedValueType < Lutaml::Model::Serializable
attribute :content, :string
attribute :value, :string
attribute :deprecated, :string
attribute :a, AnchorType, collection: true
attribute :insert, InsertType, collection: true
attribute :br, :string, collection: true
attribute :code, CodeType, collection: true
attribute :em, InlineMarkupType, collection: true
attribute :i, InlineMarkupType, collection: true
attribute :b, InlineMarkupType, collection: true
attribute :strong, InlineMarkupType, collection: true
attribute :sub, InlineMarkupType, collection: true
attribute :sup, InlineMarkupType, collection: true
attribute :q, InlineMarkupType, collection: true
attribute :img, ImageType, collection: true

xml do
root "AllowedValueType"
namespace "http://csrc.nist.gov/ns/oscal/metaschema/1.0", "xmlns"

map_content to: :content
map_attribute "value", to: :value
map_attribute "deprecated", to: :deprecated
map_element "a", to: :a
map_element "insert", to: :insert
map_element "br", to: :br
map_element "code", to: :code
map_element "em", to: :em
map_element "i", to: :i
map_element "b", to: :b
map_element "strong", to: :strong
map_element "sub", to: :sub
map_element "sup", to: :sup
map_element "q", to: :q
map_element "img", to: :img
end
end
end
35 changes: 35 additions & 0 deletions lib/metaschema/allowed_values_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
require "lutaml/model"

require_relative "allowed_value_type"
require_relative "markup_line_datatype"
require_relative "property_type"
require_relative "remarks_type"

module Metaschema
class AllowedValuesType < Lutaml::Model::Serializable
attribute :id, :string
attribute :level, :string, default: -> { "ERROR" }
attribute :allow_other, :string, default: -> { "no" }
attribute :extensible, :string, default: -> { "external" }
attribute :formal_name, :string
attribute :description, MarkupLineDatatype
attribute :prop, PropertyType, collection: true
attribute :enum, AllowedValueType, collection: true
attribute :remarks, RemarksType

xml do
root "AllowedValuesType"
namespace "http://csrc.nist.gov/ns/oscal/metaschema/1.0", "xmlns"

map_attribute "id", to: :id
map_attribute "level", to: :level
map_attribute "allow-other", to: :allow_other
map_attribute "extensible", to: :extensible
map_element "formal-name", to: :formal_name
map_element "description", to: :description
map_element "prop", to: :prop
map_element "enum", to: :enum
map_element "remarks", to: :remarks
end
end
end
40 changes: 40 additions & 0 deletions lib/metaschema/anchor_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
require "lutaml/model"

require_relative "code_type"
require_relative "image_type"
require_relative "inline_markup_type"

module Metaschema
class AnchorType < Lutaml::Model::Serializable
attribute :content, :string
attribute :href, :string
attribute :title, :string
attribute :code, CodeType, collection: true
attribute :em, InlineMarkupType, collection: true
attribute :i, InlineMarkupType, collection: true
attribute :b, InlineMarkupType, collection: true
attribute :strong, InlineMarkupType, collection: true
attribute :sub, InlineMarkupType, collection: true
attribute :sup, InlineMarkupType, collection: true
attribute :q, InlineMarkupType, collection: true
attribute :img, ImageType, collection: true

xml do
root "anchorType"
namespace "http://csrc.nist.gov/ns/oscal/metaschema/1.0", "xmlns"

map_content to: :content
map_attribute "href", to: :href
map_attribute "title", to: :title
map_element "code", to: :code
map_element "em", to: :em
map_element "i", to: :i
map_element "b", to: :b
map_element "strong", to: :strong
map_element "sub", to: :sub
map_element "sup", to: :sup
map_element "q", to: :q
map_element "img", to: :img
end
end
end
10 changes: 10 additions & 0 deletions lib/metaschema/any_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require "lutaml/model"

module Metaschema
class AnyType < Lutaml::Model::Serializable
xml do
root "AnyType"
namespace "http://csrc.nist.gov/ns/oscal/metaschema/1.0", "xmlns"
end
end
end
Loading

0 comments on commit ba2c83f

Please sign in to comment.