Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load schemas from relative path of config #111

Merged
merged 2 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/metanorma/plugin/lutaml/lutaml_uml_class_preprocessor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ def processed_lines(document, input_lines)
entity_name = match[2]
options = parse_options_to_hash(match[3])

result.push(*parse_marco(lutaml_path, entity_name, document,
result.push(*parse_macro(lutaml_path, entity_name, document,
options))
else
result.push(line)
end
end
end

def parse_marco(lutaml_path, entity_name, document, options)
def parse_macro(lutaml_path, entity_name, document, options)
lutaml_document = lutaml_document_from_file(document, lutaml_path)
.serialized_document
entities = [lutaml_document["classes"], lutaml_document["enums"]]
Expand Down
28 changes: 20 additions & 8 deletions lib/metanorma/plugin/lutaml/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,30 @@ def load_express_from_folder(folder)
::Lutaml::Parser.parse(files)
end

# TODO: Refactor this using Suma::SchemaConfig
def load_express_from_index(document, path)
yaml_content = YAML.safe_load(File.read(path))
root_path = yaml_content["path"]
schemas_paths = yaml_content["schemas"]
.map do |(schema_name, schema_values)|
schema_values["path"] || File.join(root_path.to_s,
"#{schema_name}.exp")
schema_yaml_base_path = Pathname.new(File.dirname(path))

# If there is a global root path set, all subsequent paths are
# relative to it.
if yaml_content['path']
root_schema_path = Pathname.new(yaml_content['path'])
schema_yaml_base_path = schema_yaml_base_path + root_schema_path
end

files_to_load = schemas_paths.map do |path|
File.new(Utils.relative_file_path(document, path),
encoding: "UTF-8")
files_to_load = yaml_content["schemas"].map do |key, value|

# If there is no path: set for a schema, we assume it uses the
# schema name as the #{filename}.exp.
schema_path = if value['path']
Pathname.new(value['path'])
else
Pathname.new("#{key}.exp")
end

real_schema_path = schema_yaml_base_path + schema_path
File.new(real_schema_path.cleanpath.to_s, encoding: "UTF-8")
end

::Lutaml::Parser.parse(files_to_load)
Expand Down
8 changes: 4 additions & 4 deletions spec/fixtures/lutaml/lutaml_exp_index.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
---
schemas:
arm_svgmap:
path: spec/fixtures/lutaml/expressir_index_1/arm_svgmap.exp
path: expressir_index_1/arm_svgmap.exp
diagrams:
- action_schema/action_schemaexpg1.svg
- action_schema/action_schemaexpg2.svg
mim_annotated:
path: spec/fixtures/lutaml/expressir_index_1/mim_annotated.exp
path: expressir_index_1/mim_annotated.exp
diagrams:
- application_context_schema/application_context_schemaexpg1.svg
- application_context_schema/application_context_schemaexpg2.svg
approval_schema:
path: spec/fixtures/lutaml/expressir_index_2/arm_annotated.exp
path: expressir_index_2/arm_annotated.exp
diagrams:
- approval_schema/approval_schemaexpg1.svg
- approval_schema/approval_schemaexpg2.svg
mim:
path: spec/fixtures/lutaml/expressir_index_2/mim.exp
path: expressir_index_2/mim.exp
diagrams:
- basic_attribute_schema/basic_attribute_schemaexpg1.svg
- basic_attribute_schema/basic_attribute_schemaexpg2.svg
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/lutaml/lutaml_exp_index_2.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
schemas:
arm:
path: spec/fixtures/lutaml/expressir_index_1/arm.exp
path: expressir_index_1/arm.exp
diagrams:
- action_schema/action_schemaexpg1.svg
- action_schema/action_schemaexpg2.svg
Loading