Class: Openapi2ruby::Generator
- Inherits:
-
Object
- Object
- Openapi2ruby::Generator
- Defined in:
- lib/openapi2ruby/generator.rb
Constant Summary collapse
- TEMPLATE_PATH =
File.('../templates/serializer.rb.erb', __FILE__)
Class Method Summary collapse
-
.generate(schema, output_path, template_path) ⇒ Object
Generate ruby class from OpenAPI schema.
Instance Method Summary collapse
-
#generate(output_path, template_path) ⇒ Object
Generate ruby class from OpenAPI schema.
-
#initialize(schema) ⇒ Generator
constructor
A new instance of Generator.
Constructor Details
#initialize(schema) ⇒ Generator
Returns a new instance of Generator.
17 18 19 |
# File 'lib/openapi2ruby/generator.rb', line 17 def initialize(schema) @schema = schema end |
Class Method Details
.generate(schema, output_path, template_path) ⇒ Object
Generate ruby class from OpenAPI schema
13 14 15 |
# File 'lib/openapi2ruby/generator.rb', line 13 def self.generate(schema, output_path, template_path) new(schema).generate(output_path, template_path) end |
Instance Method Details
#generate(output_path, template_path) ⇒ Object
Generate ruby class from OpenAPI schema
24 25 26 27 28 29 30 31 32 |
# File 'lib/openapi2ruby/generator.rb', line 24 def generate(output_path, template_path) template_path = TEMPLATE_PATH if template_path.nil? template = File.read(template_path) generated_class = ERB.new(template, nil, '-').result(binding) output_file = Pathname.new(output_path).join("#{@schema.name.underscore}_serializer.rb") File.open(output_file.to_s, 'w') { |file| file << generated_class } output_file.to_s end |