Module: SpecForge::CLI::Docs::Generate

Included in:
Serve
Defined in:
lib/spec_forge/cli/docs/generate.rb

Overview

Shared functionality for generating OpenAPI documentation

This module contains the core logic for running tests, extracting endpoint data, and generating OpenAPI specifications. It's used by both the Docs and Serve commands to avoid duplication.

Instance Method Summary collapse

Instance Method Details

#generate_documentation(base_path: nil) ⇒ Pathname

Generates OpenAPI documentation from blueprint test results

Runs blueprints with the configured verbosity level, extracts endpoint data, validates the specification (unless skipped), and writes the output file in the specified format.

Parameters:

  • base_path (String, Pathname, nil) (defaults to: nil)

    Optional base path for blueprints

Returns:

  • (Pathname)

    Path to the generated documentation file



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/spec_forge/cli/docs/generate.rb', line 25

def generate_documentation(base_path: nil)
  document = Documentation::Builder.create_document!(
    base_path:,
    use_cache: !options.fresh,
    verbosity_level: determine_verbosity_level
  )
  generator_class = Documentation::OpenAPI["3.0"]
  output = generator_class.new(document).generate

  generator_class.validate!(output) unless options.skip_validation

  # Determine output format and path
  file_format = determine_file_format
  file_path = determine_output_path(file_format)

  content =
    if file_format == "json"
      JSON.pretty_generate(output)
    else
      output.to_yaml(stringify_names: true)
    end

  ::File.write(file_path, content)

  file_path
end