Skip to content

Commit

Permalink
fix: load schema paths from location of schema config file
Browse files Browse the repository at this point in the history
  • Loading branch information
ronaldtse committed May 13, 2024
1 parent def8998 commit 88a1e3d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
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

0 comments on commit 88a1e3d

Please sign in to comment.