lutaml-xsd 1.0.9 → 1.1.0
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 +4 -4
- data/.rubocop_todo.yml +26 -68
- data/lib/lutaml/xsd/spa/schema_serializer.rb +112 -8
- data/lib/lutaml/xsd/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: da358b1ca55e63cb442380477680417cdff4627d23f83732a787713fdd1979bf
|
|
4
|
+
data.tar.gz: d717c30574106c682a448f390c5db3f8708e0132f56462f2cfd0789255d7b222
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 14debf574d626ee36acdbb03377abe472918989252a09aec7a56434cf6d138b5996a88b087c25347fc3383e59b7bd27367ae954be7d15891ba26c1ae7f10729b
|
|
7
|
+
data.tar.gz: 26e1958238b0f1f973f57429e7c0a1b86c56fddd214c813f8be1e1b00dd8c38b3d8e24e3d887e848fba77658e7591e95ad1a731a3b2b55e78f12fa0c59fcc7aa
|
data/.rubocop_todo.yml
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# This configuration was generated by
|
|
2
2
|
# `rubocop --auto-gen-config`
|
|
3
|
-
# on 2026-04-
|
|
3
|
+
# on 2026-04-27 11:46:52 UTC using RuboCop version 1.86.1.
|
|
4
4
|
# The point is for the user to remove these configuration records
|
|
5
5
|
# one by one as the offenses are removed from the code base.
|
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
|
@@ -11,56 +11,21 @@ Gemspec/RequiredRubyVersion:
|
|
|
11
11
|
Exclude:
|
|
12
12
|
- 'lutaml-xsd.gemspec'
|
|
13
13
|
|
|
14
|
-
# Offense count: 2
|
|
15
|
-
# This cop supports safe autocorrection (--autocorrect).
|
|
16
|
-
# Configuration parameters: EnforcedStyle, IndentationWidth.
|
|
17
|
-
# SupportedStyles: with_first_element, with_fixed_indentation
|
|
18
|
-
Layout/ArrayAlignment:
|
|
19
|
-
Exclude:
|
|
20
|
-
- 'lib/lutaml/xsd/spa/schema_serializer.rb'
|
|
21
|
-
- 'lib/lutaml/xsd/spa/utils/extract_enumeration.rb'
|
|
22
|
-
|
|
23
|
-
# Offense count: 4
|
|
24
|
-
# This cop supports safe autocorrection (--autocorrect).
|
|
25
|
-
# Configuration parameters: IndentationWidth.
|
|
26
|
-
Layout/AssignmentIndentation:
|
|
27
|
-
Exclude:
|
|
28
|
-
- 'lib/lutaml/xsd/commands/package_command.rb'
|
|
29
|
-
- 'lib/lutaml/xsd/spa/schema_serializer.rb'
|
|
30
|
-
|
|
31
|
-
# Offense count: 7
|
|
32
|
-
# This cop supports safe autocorrection (--autocorrect).
|
|
33
|
-
Layout/ClosingParenthesisIndentation:
|
|
34
|
-
Exclude:
|
|
35
|
-
- 'lib/lutaml/xsd/spa/schema_serializer.rb'
|
|
36
|
-
|
|
37
14
|
# Offense count: 1
|
|
38
15
|
# This cop supports safe autocorrection (--autocorrect).
|
|
39
16
|
# Configuration parameters: EnforcedStyleAlignWith.
|
|
40
|
-
# SupportedStylesAlignWith:
|
|
41
|
-
Layout/
|
|
17
|
+
# SupportedStylesAlignWith: either, start_of_block, start_of_line
|
|
18
|
+
Layout/BlockAlignment:
|
|
42
19
|
Exclude:
|
|
43
20
|
- 'lib/lutaml/xsd/spa/schema_serializer.rb'
|
|
44
21
|
|
|
45
22
|
# Offense count: 1
|
|
46
23
|
# This cop supports safe autocorrection (--autocorrect).
|
|
47
|
-
|
|
48
|
-
# SupportedStyles: consistent, consistent_relative_to_receiver, special_for_inner_method_call, special_for_inner_method_call_in_parentheses
|
|
49
|
-
Layout/FirstArgumentIndentation:
|
|
50
|
-
Exclude:
|
|
51
|
-
- 'lib/lutaml/xsd/spa/schema_serializer.rb'
|
|
52
|
-
|
|
53
|
-
# Offense count: 3
|
|
54
|
-
# This cop supports safe autocorrection (--autocorrect).
|
|
55
|
-
# Configuration parameters: AllowMultipleStyles, EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle.
|
|
56
|
-
# SupportedHashRocketStyles: key, separator, table
|
|
57
|
-
# SupportedColonStyles: key, separator, table
|
|
58
|
-
# SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit
|
|
59
|
-
Layout/HashAlignment:
|
|
24
|
+
Layout/BlockEndNewline:
|
|
60
25
|
Exclude:
|
|
61
26
|
- 'lib/lutaml/xsd/spa/schema_serializer.rb'
|
|
62
27
|
|
|
63
|
-
# Offense count:
|
|
28
|
+
# Offense count: 2
|
|
64
29
|
# This cop supports safe autocorrection (--autocorrect).
|
|
65
30
|
# Configuration parameters: Width, EnforcedStyleAlignWith, AllowedPatterns.
|
|
66
31
|
# SupportedStylesAlignWith: start_of_line, relative_to_receiver
|
|
@@ -68,30 +33,20 @@ Layout/IndentationWidth:
|
|
|
68
33
|
Exclude:
|
|
69
34
|
- 'lib/lutaml/xsd/spa/schema_serializer.rb'
|
|
70
35
|
|
|
71
|
-
# Offense count:
|
|
36
|
+
# Offense count: 722
|
|
72
37
|
# This cop supports safe autocorrection (--autocorrect).
|
|
73
38
|
# Configuration parameters: Max, AllowHeredoc, AllowURI, AllowQualifiedName, URISchemes, AllowRBSInlineAnnotation, AllowCopDirectives, AllowedPatterns, SplitStrings.
|
|
74
39
|
# URISchemes: http, https
|
|
75
40
|
Layout/LineLength:
|
|
76
41
|
Enabled: false
|
|
77
42
|
|
|
78
|
-
# Offense count:
|
|
79
|
-
# This cop supports safe autocorrection (--autocorrect).
|
|
80
|
-
# Configuration parameters: EnforcedStyle.
|
|
81
|
-
# SupportedStyles: symmetrical, new_line, same_line
|
|
82
|
-
Layout/MultilineMethodCallBraceLayout:
|
|
83
|
-
Exclude:
|
|
84
|
-
- 'lib/lutaml/xsd/spa/schema_serializer.rb'
|
|
85
|
-
|
|
86
|
-
# Offense count: 11
|
|
43
|
+
# Offense count: 1
|
|
87
44
|
# This cop supports safe autocorrection (--autocorrect).
|
|
88
|
-
# Configuration parameters:
|
|
89
|
-
|
|
45
|
+
# Configuration parameters: EnforcedStyle, IndentationWidth.
|
|
46
|
+
# SupportedStyles: aligned, indented
|
|
47
|
+
Layout/MultilineOperationIndentation:
|
|
90
48
|
Exclude:
|
|
91
|
-
- 'lib/lutaml/xsd/commands/package_command.rb'
|
|
92
49
|
- 'lib/lutaml/xsd/spa/schema_serializer.rb'
|
|
93
|
-
- 'lib/lutaml/xsd/spa/utils/extract_enumeration.rb'
|
|
94
|
-
- 'lib/lutaml/xsd/spa/xml_instance_generator.rb'
|
|
95
50
|
|
|
96
51
|
# Offense count: 11
|
|
97
52
|
# Configuration parameters: IgnoreLiteralBranches, IgnoreConstantBranches, IgnoreDuplicateElseBranch.
|
|
@@ -126,7 +81,7 @@ Lint/UselessRescue:
|
|
|
126
81
|
Exclude:
|
|
127
82
|
- 'lib/lutaml/xsd/validation/rule_engine.rb'
|
|
128
83
|
|
|
129
|
-
# Offense count:
|
|
84
|
+
# Offense count: 269
|
|
130
85
|
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes, Max.
|
|
131
86
|
Metrics/AbcSize:
|
|
132
87
|
Enabled: false
|
|
@@ -142,12 +97,12 @@ Metrics/BlockLength:
|
|
|
142
97
|
Metrics/BlockNesting:
|
|
143
98
|
Max: 5
|
|
144
99
|
|
|
145
|
-
# Offense count:
|
|
100
|
+
# Offense count: 201
|
|
146
101
|
# Configuration parameters: AllowedMethods, AllowedPatterns, Max.
|
|
147
102
|
Metrics/CyclomaticComplexity:
|
|
148
103
|
Enabled: false
|
|
149
104
|
|
|
150
|
-
# Offense count:
|
|
105
|
+
# Offense count: 373
|
|
151
106
|
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
|
|
152
107
|
Metrics/MethodLength:
|
|
153
108
|
Max: 90
|
|
@@ -157,12 +112,12 @@ Metrics/MethodLength:
|
|
|
157
112
|
Metrics/ParameterLists:
|
|
158
113
|
Max: 9
|
|
159
114
|
|
|
160
|
-
# Offense count:
|
|
115
|
+
# Offense count: 151
|
|
161
116
|
# Configuration parameters: AllowedMethods, AllowedPatterns, Max.
|
|
162
117
|
Metrics/PerceivedComplexity:
|
|
163
118
|
Enabled: false
|
|
164
119
|
|
|
165
|
-
# Offense count:
|
|
120
|
+
# Offense count: 25
|
|
166
121
|
# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
|
|
167
122
|
# AllowedNames: as, at, by, cc, db, id, if, in, io, ip, of, on, os, pp, to
|
|
168
123
|
Naming/MethodParameterName:
|
|
@@ -222,6 +177,17 @@ Security/MarshalLoad:
|
|
|
222
177
|
Exclude:
|
|
223
178
|
- 'lib/lutaml/xsd/package_builder.rb'
|
|
224
179
|
|
|
180
|
+
# Offense count: 1
|
|
181
|
+
# This cop supports safe autocorrection (--autocorrect).
|
|
182
|
+
# Configuration parameters: EnforcedStyle, ProceduralMethods, FunctionalMethods, AllowedMethods, AllowedPatterns, AllowBracesOnProceduralOneLiners, BracesRequiredMethods.
|
|
183
|
+
# SupportedStyles: line_count_based, semantic, braces_for_chaining, always_braces
|
|
184
|
+
# ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object
|
|
185
|
+
# FunctionalMethods: let, let!, subject, watch
|
|
186
|
+
# AllowedMethods: lambda, proc, it
|
|
187
|
+
Style/BlockDelimiters:
|
|
188
|
+
Exclude:
|
|
189
|
+
- 'lib/lutaml/xsd/spa/schema_serializer.rb'
|
|
190
|
+
|
|
225
191
|
# Offense count: 6
|
|
226
192
|
Style/DocumentDynamicEvalDefinition:
|
|
227
193
|
Exclude:
|
|
@@ -248,14 +214,6 @@ Style/IdenticalConditionalBranches:
|
|
|
248
214
|
Exclude:
|
|
249
215
|
- 'lib/lutaml/xsd/package_tree_formatter.rb'
|
|
250
216
|
|
|
251
|
-
# Offense count: 3
|
|
252
|
-
# This cop supports safe autocorrection (--autocorrect).
|
|
253
|
-
Style/MultilineIfModifier:
|
|
254
|
-
Exclude:
|
|
255
|
-
- 'lib/lutaml/xsd/commands/package_command.rb'
|
|
256
|
-
- 'lib/lutaml/xsd/spa/schema_serializer.rb'
|
|
257
|
-
- 'lib/lutaml/xsd/spa/utils/extract_enumeration.rb'
|
|
258
|
-
|
|
259
217
|
# Offense count: 1
|
|
260
218
|
Style/OpenStructUse:
|
|
261
219
|
Exclude:
|
|
@@ -4,6 +4,9 @@ require "json"
|
|
|
4
4
|
require "moxml"
|
|
5
5
|
require "tmpdir"
|
|
6
6
|
require "fileutils"
|
|
7
|
+
require "tempfile"
|
|
8
|
+
require "nokogiri"
|
|
9
|
+
require "xsdvi"
|
|
7
10
|
require_relative "xml_instance_generator"
|
|
8
11
|
require_relative "utils/extract_enumeration"
|
|
9
12
|
|
|
@@ -355,23 +358,48 @@ module Lutaml
|
|
|
355
358
|
element_data
|
|
356
359
|
end
|
|
357
360
|
|
|
358
|
-
def gen_element_diagram(name, file_path)
|
|
361
|
+
def gen_element_diagram(name, file_path, component_type = :element)
|
|
359
362
|
if !file_path || !File.exist?(file_path)
|
|
360
363
|
warn "xsdvi: XSD file '#{file_path}' not found" if config[:verbose]
|
|
361
364
|
return nil
|
|
362
365
|
end
|
|
363
366
|
|
|
364
|
-
|
|
367
|
+
actual_file_path = file_path
|
|
368
|
+
wrapper_name = name
|
|
365
369
|
|
|
366
|
-
|
|
367
|
-
|
|
370
|
+
if component_type == :type
|
|
371
|
+
# For types, create a temporary XSD with a synthetic wrapper element
|
|
372
|
+
# so xsdvi can treat the type as a root element
|
|
373
|
+
actual_file_path = create_type_wrapper_xsd(name, file_path)
|
|
374
|
+
wrapper_name = "_diagram_root_#{name}"
|
|
375
|
+
end
|
|
368
376
|
|
|
377
|
+
output_folder = Dir.mktmpdir("xsdvi-")
|
|
369
378
|
svg_file = File.join(output_folder, "#{name}.svg")
|
|
370
|
-
|
|
379
|
+
|
|
380
|
+
# Use xsdvi Ruby API directly instead of CLI
|
|
381
|
+
builder = Xsdvi::Tree::Builder.new
|
|
382
|
+
xsd_handler = Xsdvi::XsdHandler.new(builder)
|
|
383
|
+
writer_helper = Xsdvi::Utils::Writer.new
|
|
384
|
+
svg_generator = Xsdvi::SVG::Generator.new(writer_helper)
|
|
385
|
+
|
|
386
|
+
svg_generator.hide_menu_buttons = true
|
|
387
|
+
svg_generator.embody_style = true
|
|
388
|
+
|
|
389
|
+
xsd_handler.root_node_name = wrapper_name
|
|
390
|
+
xsd_handler.one_node_only = true
|
|
391
|
+
xsd_handler.process_file(actual_file_path)
|
|
392
|
+
|
|
393
|
+
unless builder.root
|
|
371
394
|
warn "xsdvi: SVG not generated for '#{name}'" if config[:verbose]
|
|
372
395
|
return nil
|
|
373
396
|
end
|
|
374
397
|
|
|
398
|
+
writer_helper.new_writer(svg_file)
|
|
399
|
+
svg_generator.draw(builder.root)
|
|
400
|
+
|
|
401
|
+
return nil unless File.exist?(svg_file)
|
|
402
|
+
|
|
375
403
|
# read generated SVG content
|
|
376
404
|
svg_content = File.read(svg_file)
|
|
377
405
|
|
|
@@ -384,8 +412,84 @@ module Lutaml
|
|
|
384
412
|
.gsub(/<a[^>]*>(.*?)<\/a>/im, '\1') # Remove links but keep content
|
|
385
413
|
|
|
386
414
|
svg_content
|
|
415
|
+
rescue StandardError => e
|
|
416
|
+
warn "xsdvi: Failed to generate diagram for '#{name}': #{e.message}" if config[:verbose]
|
|
417
|
+
nil
|
|
387
418
|
ensure
|
|
388
419
|
FileUtils.rm_rf(output_folder) if output_folder
|
|
420
|
+
if component_type == :type && actual_file_path && actual_file_path != file_path
|
|
421
|
+
FileUtils.rm_f(actual_file_path)
|
|
422
|
+
end
|
|
423
|
+
end
|
|
424
|
+
|
|
425
|
+
# Create a temporary XSD file that wraps a complexType/simpleType
|
|
426
|
+
# in a synthetic root element, so xsdvi can generate a diagram for it.
|
|
427
|
+
#
|
|
428
|
+
# @param type_name [String] The type name
|
|
429
|
+
# @param original_file_path [String] Path to the original XSD file
|
|
430
|
+
# @return [String] Path to the temporary XSD file
|
|
431
|
+
def create_type_wrapper_xsd(type_name, original_file_path)
|
|
432
|
+
doc = Nokogiri::XML(File.read(original_file_path))
|
|
433
|
+
ns = { "xs" => "http://www.w3.org/2001/XMLSchema" }
|
|
434
|
+
schema = doc.at_xpath("//xs:schema", ns)
|
|
435
|
+
|
|
436
|
+
unless schema
|
|
437
|
+
warn "xsdvi: No xs:schema found in '#{original_file_path}'" if config[:verbose]
|
|
438
|
+
return original_file_path
|
|
439
|
+
end
|
|
440
|
+
|
|
441
|
+
wrapper_name = "_diagram_root_#{type_name}"
|
|
442
|
+
|
|
443
|
+
# Check if this type might need a namespace prefix
|
|
444
|
+
# Look for how the type is referenced in the original schema
|
|
445
|
+
type_ref = resolve_type_prefix(type_name, doc, ns)
|
|
446
|
+
|
|
447
|
+
# Create element with proper XSD namespace from the schema
|
|
448
|
+
xsd_ns = "http://www.w3.org/2001/XMLSchema"
|
|
449
|
+
xsd_ns_decl = schema.namespace_definitions.find do |nd|
|
|
450
|
+
nd.href == xsd_ns
|
|
451
|
+
end
|
|
452
|
+
|
|
453
|
+
element_node = doc.create_element("element")
|
|
454
|
+
element_node.namespace = xsd_ns_decl
|
|
455
|
+
element_node["name"] = wrapper_name
|
|
456
|
+
element_node["type"] = type_ref
|
|
457
|
+
|
|
458
|
+
schema.add_child(element_node)
|
|
459
|
+
|
|
460
|
+
tmp = Tempfile.new(["xsdvi-wrapper-", ".xsd"])
|
|
461
|
+
tmp.write(doc.to_xml)
|
|
462
|
+
tmp.close
|
|
463
|
+
tmp.path
|
|
464
|
+
end
|
|
465
|
+
|
|
466
|
+
# Determine the correct type reference prefix for a type in the schema.
|
|
467
|
+
# If the type is defined in the targetNamespace, use the same prefix
|
|
468
|
+
# that the schema uses internally for its targetNamespace.
|
|
469
|
+
#
|
|
470
|
+
# @param type_name [String] The type name
|
|
471
|
+
# @param doc [Nokogiri::Document] The parsed XSD document
|
|
472
|
+
# @param ns [Hash] Namespace mapping
|
|
473
|
+
# @return [String] The type reference string (possibly prefixed)
|
|
474
|
+
def resolve_type_prefix(type_name, doc, ns)
|
|
475
|
+
schema = doc.at_xpath("//xs:schema", ns)
|
|
476
|
+
target_ns = schema["targetNamespace"]
|
|
477
|
+
|
|
478
|
+
# Check if the type is defined in this schema's targetNamespace
|
|
479
|
+
type_in_schema = doc.xpath("//xs:complexType[@name='#{type_name}']",
|
|
480
|
+
ns).any? ||
|
|
481
|
+
doc.xpath("//xs:simpleType[@name='#{type_name}']",
|
|
482
|
+
ns).any?
|
|
483
|
+
|
|
484
|
+
return type_name unless type_in_schema && target_ns
|
|
485
|
+
|
|
486
|
+
# Find what prefix maps to the targetNamespace
|
|
487
|
+
ns_decls = schema.namespace_definitions
|
|
488
|
+
tns_prefix = ns_decls.find do |nd|
|
|
489
|
+
nd.href == target_ns && nd.prefix
|
|
490
|
+
end
|
|
491
|
+
|
|
492
|
+
tns_prefix ? "#{tns_prefix.prefix}:#{type_name}" : type_name
|
|
389
493
|
end
|
|
390
494
|
|
|
391
495
|
# Serialize complex types from schema
|
|
@@ -1459,17 +1563,17 @@ source = nil)
|
|
|
1459
1563
|
schema
|
|
1460
1564
|
end
|
|
1461
1565
|
|
|
1462
|
-
# Generate SVG diagram for a component using xsdvi
|
|
1566
|
+
# Generate SVG diagram for a component using xsdvi Ruby API
|
|
1463
1567
|
#
|
|
1464
1568
|
# @param component_data [Hash] Serialized component data
|
|
1465
1569
|
# @param component_type [Symbol] Component type (:element or :type)
|
|
1466
1570
|
# @param file_path [String, nil] XSD file path for xsdvi
|
|
1467
1571
|
# @return [String, nil] SVG diagram markup
|
|
1468
|
-
def generate_diagram(component_data,
|
|
1572
|
+
def generate_diagram(component_data, component_type, file_path = nil)
|
|
1469
1573
|
name = component_data[:name] || component_data["name"]
|
|
1470
1574
|
return nil unless name && file_path
|
|
1471
1575
|
|
|
1472
|
-
gen_element_diagram(name, file_path)
|
|
1576
|
+
gen_element_diagram(name, file_path, component_type)
|
|
1473
1577
|
rescue StandardError => e
|
|
1474
1578
|
warn "Warning: Failed to generate SVG diagram: #{e.message}" if ENV["DEBUG"]
|
|
1475
1579
|
nil
|
data/lib/lutaml/xsd/version.rb
CHANGED