Class: Generator::Report

Inherits:
Object
  • Object
show all
Includes:
FileWriter, SchemaGenerator, SchemaHelpers
Defined in:
lib/generator/report.rb

Overview

Generates Ruby type classes for SP-API report schemas from JSON Schema files

Constant Summary

Constants included from Formatter

Formatter::MAX_LINE_LENGTH

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SchemaGenerator

#generate, #generate_main_file!, #generate_supplementary_files, included, #main_template, #needs_money?, #output_file_path, #sorted_properties

Methods included from SchemaHelpers

#api_name_for_type_resolver, #attribute_name_for, #format_property_comment, #generate_nested_types!, #generate_rbs!, #generic_placeholder?, #needs_money?, #nested_type_files, #ruby_type_for, #type_resolver

Methods included from Formatter

#convert_doc_links_to_full_url, #convert_html_links_to_yard, #format_method_definition, #split_long_comment_line

Methods included from FileWriter

#format_files, #write_file

Constructor Details

#initialize(file_path) ⇒ Report

Returns a new instance of Report.



33
34
35
36
# File 'lib/generator/report.rb', line 33

def initialize(file_path)
  @file_path = file_path
  @schema = JSON.parse(File.read(file_path))
end

Instance Attribute Details

#file_pathObject (readonly)

Returns the value of attribute file_path.



25
26
27
# File 'lib/generator/report.rb', line 25

def file_path
  @file_path
end

#schemaObject (readonly)

Returns the value of attribute schema.



25
26
27
# File 'lib/generator/report.rb', line 25

def schema
  @schema
end

Class Method Details

.schema_typeObject



28
29
30
# File 'lib/generator/report.rb', line 28

def schema_type
  "reports"
end

Instance Method Details

#class_nameObject

Class name for the report (e.g., "EndUserData", "AccountHealth_2020_11_18")



59
60
61
62
# File 'lib/generator/report.rb', line 59

def class_name
  # Underscore first to ensure ActiveSupport::Inflector applies acronym rules correctly
  report_name.underscore.camelize
end

#generate_schema_types(written_files, all_types) ⇒ Object



38
39
40
41
42
43
# File 'lib/generator/report.rb', line 38

def generate_schema_types(written_files, all_types)
  # Generate main report type
  report_result = generate_report_type!
  written_files << report_result[:file]
  all_types << report_result[:type]
end

#raw_descriptionObject

Raw description from schema (will be formatted by Type class)



76
77
78
79
80
81
# File 'lib/generator/report.rb', line 76

def raw_description
  return unless schema["description"]
  return if generic_placeholder?(schema["description"])

  schema["description"]
end

#report_nameObject

Extract report name from filename Examples: "endUserDataReport.json" => "EndUserData" "accountHealthReport-2020-11-18.json" => "AccountHealth_2020_11_18" "b2bProductOpportunitiesNotYetOnAmazonReport-2020-11-19.json" => "B2bProductOpportunitiesNotYetOnAmazon_2020_11_19"



50
51
52
53
54
55
56
# File 'lib/generator/report.rb', line 50

def report_name
  base_name = File.basename(file_path, ".json")
  # Remove "Report" suffix
  name = base_name.sub(/Report$/, "")
  # Convert dashes to underscores for valid Ruby identifiers
  name.tr("-", "_")
end

#root_propertiesObject

Root properties from schema (excluding reportSpecification which is metadata)



65
66
67
68
# File 'lib/generator/report.rb', line 65

def root_properties
  props = schema["properties"] || {}
  sorted_properties(props)
end

#root_required_propertiesObject

Required properties from root level



71
72
73
# File 'lib/generator/report.rb', line 71

def root_required_properties
  schema["required"] || []
end