Class: OpenapiRuby::Generator::SchemaWriter
- Inherits:
-
Object
- Object
- OpenapiRuby::Generator::SchemaWriter
- Defined in:
- lib/openapi_ruby/generator/schema_writer.rb
Class Method Summary collapse
Instance Method Summary collapse
- #build_document ⇒ Object
-
#initialize(schema_name, schema_config) ⇒ SchemaWriter
constructor
A new instance of SchemaWriter.
- #write! ⇒ Object
Constructor Details
#initialize(schema_name, schema_config) ⇒ SchemaWriter
Returns a new instance of SchemaWriter.
19 20 21 22 |
# File 'lib/openapi_ruby/generator/schema_writer.rb', line 19 def initialize(schema_name, schema_config) @schema_name = schema_name @schema_config = schema_config end |
Class Method Details
.generate_all! ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/openapi_ruby/generator/schema_writer.rb', line 6 def self.generate_all! config = OpenapiRuby.configuration if config.schemas.empty? warn "[openapi_ruby] No schemas configured, skipping generation" return end config.schemas.each do |name, schema_config| new(name, schema_config).write! end end |
Instance Method Details
#build_document ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/openapi_ruby/generator/schema_writer.rb', line 33 def build_document builder = Core::DocumentBuilder.new(@schema_config) # Merge paths from DSL metadata DSL::MetadataStore.contexts_for(@schema_name).each do |context| builder.add_path(context.path_template, context.to_openapi) end # Merge components from registry scope = @schema_config[:component_scope] components = Components::Registry.instance.to_openapi_hash(scope: scope) builder.merge_components(components) builder.build end |
#write! ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/openapi_ruby/generator/schema_writer.rb', line 24 def write! document = build_document validate_document!(document) if OpenapiRuby.configuration.strict_reference_validation output_path = File.join(output_dir, filename) FileUtils.mkdir_p(output_dir) File.write(output_path, format_output(document)) output_path end |