Class: Lutaml::Jsonschema::Cli
- Inherits:
-
Thor
- Object
- Thor
- Lutaml::Jsonschema::Cli
- Defined in:
- lib/lutaml/jsonschema/cli.rb
Instance Method Summary collapse
- #combine(*schema_files) ⇒ Object
- #spa(*schema_files) ⇒ Object
- #validate(schema_file) ⇒ Object
- #version ⇒ Object
Instance Method Details
#combine(*schema_files) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/lutaml/jsonschema/cli.rb', line 38 def combine(*schema_files) raise Error, "No schema files provided" if schema_files.empty? schema_set = SchemaSet.load_from_files(*schema_files) combined = Combiner.new.combine(schema_set) json = JSON.pretty_generate(JSON.parse(combined.to_json)) if [:output] == "-" $stdout.write(json) else File.write([:output], json) puts "Combined schema written to #{[:output]}" end rescue Errno::ENOENT => e abort "Error: #{e.}" end |
#spa(*schema_files) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/lutaml/jsonschema/cli.rb', line 18 def spa(*schema_files) raise Error, "No schema files provided" if schema_files.empty? config = load_config([:config]) config.output_path = [:output] if [:output] config.title = [:title] if [:title] config.theme = [:theme] if [:theme] schema_set = SchemaSet.load_from_files(*schema_files) generator = Spa::Generator.new(schema_set, config.output_path, metadata: config.) generator.generate puts "SPA documentation generated at #{config.output_path}/index.html" rescue Errno::ENOENT => e abort "Error: #{e.}" end |
#validate(schema_file) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/lutaml/jsonschema/cli.rb', line 56 def validate(schema_file) data = File.read(schema_file) json = JSON.parse(data) Schema.from_json(data) errors = validate_structure(json) if errors.empty? puts "#{schema_file}: valid" else errors.each { |e| warn " #{e}" } abort "#{schema_file}: #{errors.length} validation error(s)" end rescue JSON::ParserError => e abort "Invalid JSON: #{e.}" rescue Errno::ENOENT => e abort "Error: #{e.}" end |
#version ⇒ Object
75 76 77 |
# File 'lib/lutaml/jsonschema/cli.rb', line 75 def version puts "lutaml-jsonschema #{VERSION}" end |