Class: JSON::SchemaGeneratorCLI
- Inherits:
-
Object
- Object
- JSON::SchemaGeneratorCLI
- Defined in:
- lib/json/schema_generator_cli.rb
Instance Method Summary collapse
- #execute! ⇒ Object
-
#initialize(argv, stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = Kernel) ⇒ SchemaGeneratorCLI
constructor
A new instance of SchemaGeneratorCLI.
Constructor Details
#initialize(argv, stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = Kernel) ⇒ SchemaGeneratorCLI
Returns a new instance of SchemaGeneratorCLI.
6 7 8 |
# File 'lib/json/schema_generator_cli.rb', line 6 def initialize(argv, stdin=STDIN, stdout=STDOUT, stderr=STDERR, kernel=Kernel) @argv, @stdin, @stdout, @stderr, @kernel = argv, stdin, stdout, stderr, kernel end |
Instance Method Details
#execute! ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/json/schema_generator_cli.rb', line 10 def execute! default_version = 'draft4' supported_versions = ['draft4'] = { :schema_version => default_version, :defaults => false } OptionParser.new do |opts| opts.on("--defaults", "Record default values in the generated schema") { [:defaults] = true } opts.on("--schema-version draft4", [:draft4], "Version of json-schema to generate (#{supported_versions.join ', '}). Default: #{default_version}") do |schema_version| [:schema_version] = schema_version end opts.on("--allow-null", "Includes 'null' as an allow type for all properties in the schema") { [:allow_null] = true } opts.parse! end file = ARGV.shift schema = JSON.parse(JSON::SchemaGenerator.generate file, File.read(file), ) @stdout.puts JSON.pretty_generate schema @kernel.exit(0) end |