lutaml-lml 0.3.4 → 0.3.5

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: 3d2253a295aed1a2d3218c34818aa1fddf38ca68be9830695175a52ba777719b
4
- data.tar.gz: 6a070753dfcf0acf67b5196c8f8fca550f8b7ae41f01a15ad969f8d3e423de4f
3
+ metadata.gz: 30cbd708d890192c751f7fa14cc3eb87ba0e3ee344c636bb9581623de04ab639
4
+ data.tar.gz: 5a89263d3bedb5d4aaf587c9644f2479f135e6fd0b3aca923931dc24de001002
5
5
  SHA512:
6
- metadata.gz: f1190e583a4ed9f86af817b45863ab26a40668dc38f4f1d17458f5df869e47e409c2454a7282d60ba2a601896e53697a852a263ab6148390f972c29519a8af61
7
- data.tar.gz: ec32fdc80d72afa8a7173655c3f47115acbab0c1b14535126954e0edd0bd2c809b218884c8e98287beb53bd740f225ec552f741171f5fded67dadeaced305ca5
6
+ metadata.gz: fa80e98551690a86dfd630e6ad09e5b2965508c8462f01aff53e06e5d8fee8affa0e50af39a31888c6231685638b965dead7390b4cc25b50f968dc8b5faf976e
7
+ data.tar.gz: 462a67af964daef324c0cacf8b4591aad300a7c923f74a747d756286e7a285b6c527872210f5df438510fe48ea6c467139fadc770924fecba2f83abd102d9377
@@ -167,6 +167,7 @@ module Lutaml
167
167
  desc: 'Schema output path (file for one model, directory for many)'
168
168
  def compile(path)
169
169
  raise Thor::Error, "File does not exist: #{path}" unless File.exist?(path)
170
+ raise Thor::Error, "Expected a file, got directory: #{path}" if File.directory?(path)
170
171
 
171
172
  ns = options[:namespace] || (::Lutaml::Lml::ModelCompiler::DEFAULT_NAMESPACE if options[:schema])
172
173
  result = File.open(path) { |file| Lutaml::Lml::ModelCompiler.new(namespace: ns).compile(file) }
@@ -402,6 +402,7 @@ module Lutaml
402
402
  if (section = hash.delete(:default_string_formats))
403
403
  model.default_string_formats << build_string_format(section)
404
404
  end
405
+ expand_class_namespace(model, hash)
405
406
  return unless (derived = hash.delete(:derived_field))
406
407
 
407
408
  model.derived_fields << build(:derived_field,
@@ -409,6 +410,15 @@ module Lutaml
409
410
  type: unquote(derived[:type]))
410
411
  end
411
412
 
413
+ # Issue #49: an in-class `namespace "uri" [prefix "p"]` line
414
+ def expand_class_namespace(model, hash)
415
+ decl = hash.delete(:class_namespace) or return
416
+
417
+ model.xml_namespace = build(:namespace,
418
+ uri: unquote(decl[:uri]),
419
+ prefix: unquote(decl[:prefix]))
420
+ end
421
+
412
422
  # L7a: from_table declares the enum's members as an artifact table
413
423
  # { from_table_name:, from_table_artifact? } — expansion happens at
414
424
  # compile time (deterministic materialization, no runtime data dep)
@@ -140,6 +140,7 @@ module Lutaml
140
140
  render_block(class_header(klass)) do
141
141
  render_comments(klass.comments)
142
142
  member { render_definition(klass.definition) } if definition_present?(klass.definition)
143
+ member { render_class_namespace(klass.xml_namespace) } if klass.xml_namespace&.uri
143
144
  Array(klass.attributes).each { |attribute| member { render_attribute(attribute) } }
144
145
  Array(klass.operations).each { |operation| member { render_operation(operation) } }
145
146
  Array(klass.derived_fields).each do |field|
@@ -152,6 +153,12 @@ module Lutaml
152
153
  end
153
154
  end
154
155
 
156
+ def render_class_namespace(namespace)
157
+ text = "namespace #{quote_always(namespace.uri)}"
158
+ text += " prefix #{quote_always(namespace.prefix)}" if namespace.prefix
159
+ line(text)
160
+ end
161
+
155
162
  def class_header(klass)
156
163
  text = "#{declaration_visibility(klass.visibility)}#{class_modifier(klass)}"
157
164
  text += "class #{klass.name}"
@@ -304,6 +311,8 @@ module Lutaml
304
311
  def render_attribute(attribute)
305
312
  return if attribute.name.to_s.empty?
306
313
 
314
+ return render_attribute_block(attribute) if attribute.xml_role && attribute_block_options?(attribute)
315
+
307
316
  if terse_attribute?(attribute)
308
317
  line("attribute #{attribute.name}, #{attribute.type}")
309
318
  elsif naked_attribute?(attribute)
@@ -315,6 +324,11 @@ module Lutaml
315
324
  end
316
325
  end
317
326
 
327
+ def attribute_block_options?(attribute)
328
+ Array(attribute.value_set).any? || Array(attribute.properties).any? ||
329
+ !attribute.pattern.nil? || !attribute.default.nil?
330
+ end
331
+
318
332
  def terse_attribute?(attribute)
319
333
  public_visibility?(attribute.visibility) &&
320
334
  bare_name?(attribute.name) &&
@@ -324,7 +338,7 @@ module Lutaml
324
338
  Array(attribute.properties).empty? &&
325
339
  attribute.pattern.nil? && attribute.default.nil? &&
326
340
  Array(attribute.stereotype).empty? && !attribute.literal &&
327
- !definition_present?(attribute.definition)
341
+ attribute.xml_role.nil? && !definition_present?(attribute.definition)
328
342
  end
329
343
 
330
344
  def naked_attribute?(attribute)
@@ -335,14 +349,14 @@ module Lutaml
335
349
  Array(attribute.properties).empty? &&
336
350
  attribute.pattern.nil? && attribute.default.nil? &&
337
351
  Array(attribute.stereotype).empty? && !attribute.literal &&
338
- !definition_present?(attribute.definition)
352
+ attribute.xml_role.nil? && !definition_present?(attribute.definition)
339
353
  end
340
354
 
341
355
  def bare_attribute?(attribute)
342
356
  !public_visibility?(attribute.visibility) ||
343
357
  !bare_name?(attribute.name) ||
344
358
  Array(attribute.stereotype).any? || attribute.literal ||
345
- definition_present?(attribute.definition)
359
+ !attribute.xml_role.nil? || definition_present?(attribute.definition)
346
360
  end
347
361
 
348
362
  def render_bare_attribute(attribute)
@@ -351,6 +365,7 @@ module Lutaml
351
365
  header += ": #{type}" if type != ''
352
366
  cardinality = attribute_cardinality(attribute)
353
367
  header += " [#{cardinality}]" if cardinality
368
+ header += " as :#{attribute.xml_role}" if attribute.xml_role
354
369
 
355
370
  if definition_present?(attribute.definition)
356
371
  render_block(header) { render_definition(attribute.definition) }
@@ -376,7 +391,9 @@ module Lutaml
376
391
  end
377
392
 
378
393
  def render_attribute_block(attribute)
379
- render_block("attribute #{attribute_name_text(attribute.name)}") do
394
+ header = "attribute #{attribute_name_text(attribute.name)}"
395
+ header += " as :#{attribute.xml_role}" if attribute.xml_role
396
+ render_block(header) do
380
397
  line("type #{attribute.type}") if attribute.type.to_s != ''
381
398
  cardinality = attribute_cardinality(attribute)
382
399
  line("cardinality #{cardinality}") if cardinality