Class: RailsOpenapiGen::Generators::YamlGenerator
- Inherits:
-
Object
- Object
- RailsOpenapiGen::Generators::YamlGenerator
- Defined in:
- lib/rails-openapi-gen/generators/yaml_generator.rb
Instance Attribute Summary collapse
-
#components ⇒ Object
readonly
Returns the value of attribute components.
-
#schemas ⇒ Object
readonly
Returns the value of attribute schemas.
Instance Method Summary collapse
-
#generate ⇒ void
Generates OpenAPI YAML files from schemas.
-
#initialize(schemas, components: {}) ⇒ YamlGenerator
constructor
Initializes YAML generator with schemas data.
Constructor Details
#initialize(schemas, components: {}) ⇒ YamlGenerator
Initializes YAML generator with schemas data
15 16 17 18 19 20 |
# File 'lib/rails-openapi-gen/generators/yaml_generator.rb', line 15 def initialize(schemas, components: {}) @schemas = schemas @components = components @config = RailsOpenapiGen.configuration @base_path = @config.output_directory end |
Instance Attribute Details
#components ⇒ Object (readonly)
Returns the value of attribute components.
10 11 12 |
# File 'lib/rails-openapi-gen/generators/yaml_generator.rb', line 10 def components @components end |
#schemas ⇒ Object (readonly)
Returns the value of attribute schemas.
10 11 12 |
# File 'lib/rails-openapi-gen/generators/yaml_generator.rb', line 10 def schemas @schemas end |
Instance Method Details
#generate ⇒ void
This method returns an undefined value.
Generates OpenAPI YAML files from schemas
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rails-openapi-gen/generators/yaml_generator.rb', line 24 def generate setup_directories paths_data = {} @schemas.each do |route, data| next if data.nil? || data[:schema].nil? || should_skip_schema?(data[:schema]) path_key = normalize_path(route[:path]) method = route[:method].downcase paths_data[path_key] ||= {} paths_data[path_key][method] = build_operation(route, data[:schema], data[:parameters], data[:operation]) end if @config.split_files? write_endpoint_files(paths_data) write_component_files if @components && @components.any? write_main_openapi_file else write_single_file(paths_data) end end |