Class: Synthra::CLI::Commands::Import
- Inherits:
-
Object
- Object
- Synthra::CLI::Commands::Import
- Defined in:
- lib/synthra/cli/commands/import.rb
Overview
CLI command for importing schemas from external formats
Constant Summary collapse
- EXIT_SUCCESS =
0- EXIT_ERROR =
1
Instance Method Summary collapse
- #call(input_path, options) ⇒ Object
- #detect_format(path) ⇒ Object private
- #import_json_schema(input_path, output_dir) ⇒ Object private
- #import_openapi(input_path, output_dir) ⇒ Object private
-
#initialize ⇒ Import
constructor
A new instance of Import.
Constructor Details
#initialize ⇒ Import
Returns a new instance of Import.
15 16 17 |
# File 'lib/synthra/cli/commands/import.rb', line 15 def initialize # No args needed for this command end |
Instance Method Details
#call(input_path, options) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/synthra/cli/commands/import.rb', line 19 def call(input_path, ) unless File.exist?(input_path) $stderr.puts "✗ Input file not found: #{input_path}" return EXIT_ERROR end output_dir = [:output] || "schemas" format = detect_format(input_path) case format when :openapi import_openapi(input_path, output_dir) when :json_schema import_json_schema(input_path, output_dir) else $stderr.puts "✗ Unsupported format: #{format}" EXIT_ERROR end end |
#detect_format(path) ⇒ Object (private)
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/synthra/cli/commands/import.rb', line 41 def detect_format(path) content = File.read(path) if content.include?("openapi:") || content.include?('"openapi"') :openapi elsif content.include?("swagger:") || content.include?('"swagger"') :openapi elsif content.include?('"$schema"') || content.include?("$schema:") :json_schema else :unknown end end |
#import_json_schema(input_path, output_dir) ⇒ Object (private)
70 71 72 73 74 75 76 |
# File 'lib/synthra/cli/commands/import.rb', line 70 def import_json_schema(input_path, output_dir) # TODO: Implement JSON Schema import puts "📥 JSON Schema import not yet implemented" puts " Use OpenAPI format for now" EXIT_ERROR end |
#import_openapi(input_path, output_dir) ⇒ Object (private)
55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/synthra/cli/commands/import.rb', line 55 def import_openapi(input_path, output_dir) require_relative "../../openapi_importer" puts "📥 Importing from OpenAPI: #{input_path}" importer = OpenAPIImporter.new(input_path) created = importer.import_to_directory(output_dir) puts "" puts "✅ Successfully imported #{created.count} schemas:" created.each { |path| puts " #{path}" } EXIT_SUCCESS end |