Class: SpecForge::Documentation::OpenAPI::V30::ErrorFormatter
- Inherits:
-
Object
- Object
- SpecForge::Documentation::OpenAPI::V30::ErrorFormatter
- Defined in:
- lib/spec_forge/documentation/openapi/v3_0/error_formatter.rb
Overview
Formats OpenAPI validation errors into human-readable messages
Takes validation errors from OpenAPI parsers and transforms them into structured, easy-to-understand error messages with context information and suggestions for resolution.
Constant Summary collapse
- PATHS_REGEX =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Regular expression for matching path-related validation errors
Captures path, HTTP method, and response code from OpenAPI error contexts to provide meaningful location information in error messages.
%r{#/paths/(.+?)/(get|post|put|patch|delete|head|options)/responses/(.+)}i- SCHEMA_REGEX =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Regular expression for matching schema-related validation errors
Captures schema name and field path from OpenAPI error contexts to identify specific schema validation failures.
%r{#/components/schemas/(.+?)/(.+)}i
Class Method Summary collapse
-
.format(errors) ⇒ String?
Formats an array of validation errors into a readable string.
Instance Method Summary collapse
-
#format ⇒ String?
Formats the errors into a structured, readable message.
-
#initialize(errors) ⇒ ErrorFormatter
constructor
Creates a new error formatter.
Constructor Details
#initialize(errors) ⇒ ErrorFormatter
Creates a new error formatter
58 59 60 |
# File 'lib/spec_forge/documentation/openapi/v3_0/error_formatter.rb', line 58 def initialize(errors) @errors = errors end |
Class Method Details
.format(errors) ⇒ String?
Formats an array of validation errors into a readable string
47 48 49 |
# File 'lib/spec_forge/documentation/openapi/v3_0/error_formatter.rb', line 47 def self.format(errors) new(errors).format end |
Instance Method Details
#format ⇒ String?
Formats the errors into a structured, readable message
Groups errors by type (unexpected vs validation), formats each error with context and location information, and returns a comprehensive error report with resolution guidance.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/spec_forge/documentation/openapi/v3_0/error_formatter.rb', line 71 def format return if @errors.blank? unexpected_errors, errors = @errors.partition { |e| e..include?("Unexpected") } unexpected_errors = format_errors(unexpected_errors) errors = format_errors(errors, start_index: unexpected_errors.size) if unexpected_errors.size > 0 = <<~STRING Field errors (resolve these first): #{unexpected_errors.join("\n\n")} ------- Other validation errors: STRING end <<~STRING ======================================== 🚨 Validation Errors ======================================== #{} #{errors.join("\n\n")} Total errors: #{errors.size} STRING end |