Class: Archsight::Import::Handlers::RestApi

Inherits:
Archsight::Import::Handler show all
Defined in:
lib/archsight/import/handlers/rest_api.rb

Overview

REST API handler - downloads OpenAPI spec and generates ApplicationInterface and DataObject resources

Configuration (passed from rest_api_index handler):

import/config/name - API name (e.g., "compute")
import/config/version - API version (e.g., "6.0")
import/config/visibility - API visibility (e.g., "private")
import/config/specUrl - Full URL to OpenAPI spec (http, https, or file://)
import/config/htmlUrl - Full URL to HTML documentation (optional)
import/config/gate - Release gate (e.g., "GA", "BETA")
import/config/interfaceOutputPath - Output path for ApplicationInterface resources
import/config/dataObjectOutputPath - Output path for DataObject resources

Output:

- ApplicationInterface resource with annotations
- DataObject resources extracted from OpenAPI schemas

Constant Summary collapse

GATE_ALIASES =
{
  "GA" => "General-Availability",
  "EA" => "Early-Access",
  "DEV" => "Development"
}.freeze

Instance Attribute Summary

Attributes inherited from Archsight::Import::Handler

#database, #import_resource, #progress, #resources_dir, #shared_writer

Instance Method Summary collapse

Methods inherited from Archsight::Import::Handler

#compute_config_hash, #config, #config_all, #import_yaml, #initialize, #resource_yaml, #resources_to_yaml, #self_marker, #write_generates_meta, #write_yaml

Constructor Details

This class inherits a constructor from Archsight::Import::Handler

Instance Method Details

#executeObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/archsight/import/handlers/rest_api.rb', line 28

def execute
  @name = config("name")
  raise "Missing required config: name" unless @name

  @version = config("version", default: "1.0")
  @visibility = config("visibility", default: "private")
  @spec_url = config("specUrl")
  raise "Missing required config: specUrl" unless @spec_url

  @html_url = config("htmlUrl")
  @gate = normalize_gate(config("gate", default: "GA"))

  @interface_output_path = config("interfaceOutputPath")
  @data_object_output_path = config("dataObjectOutputPath")

  # Download and parse OpenAPI spec
  progress.update("Downloading OpenAPI spec for #{@name}")
  openapi_doc = fetch_openapi_spec(@spec_url)

  # Parse schemas and generate DataObjects first (needed for interface relations)
  progress.update("Extracting DataObjects from #{@name} schemas")
  parser = Archsight::Import::Handlers::OpenAPISchemaParser.new(openapi_doc)
  parsed_objects = parser.parse
  data_objects = generate_data_objects(parsed_objects)

  # Generate ApplicationInterface with references to DataObjects
  progress.update("Generating ApplicationInterface for #{@name}")
  data_object_names = data_objects.map { |obj| obj.dig("metadata", "name") }
  interface_resource = generate_interface(openapi_doc, data_object_names: data_object_names)

  # Write outputs
  if @interface_output_path
    write_yaml(YAML.dump(interface_resource), filename: nil, sort_key: "#{@name}-interface")
  else
    write_yaml(YAML.dump(interface_resource), filename: "#{safe_api_name}-interface.yaml")
  end

  if data_objects.any?
    data_yaml = data_objects.map { |r| YAML.dump(r) }.join("\n")
    if @data_object_output_path
      # Use shared output path - write each object with a sort key
      data_objects.each do |obj|
        write_data_object(obj)
      end
    else
      write_yaml(data_yaml, filename: "#{safe_api_name}-data-objects.yaml")
    end
  end

  progress.update("Generated #{data_objects.size} DataObjects for #{@name}")

  write_generates_meta
end