module OpenapiFirst::ValidationFormat
Constants
- SIMPLE_TYPES
Public Class Methods
error_details(error)
click to toggle source
rubocop:disable Metrics/MethodLength rubocop:disable Metrics/AbcSize rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/PerceivedComplexity
# File lib/openapi_first/validation_format.rb, line 11 def self.error_details(error) if error['type'] == 'pattern' { title: 'is not valid', detail: "does not match pattern '#{error['schema']['pattern']}'" } elsif error['type'] == 'format' { title: "has not a valid #{error.dig('schema', 'format')} format", detail: "#{error['data'].inspect} is not a valid #{error.dig('schema', 'format')} format" } elsif error['type'] == 'enum' { title: "value #{error['data'].inspect} is not defined in enum", detail: "value can be one of #{error.dig('schema', 'enum')&.join(', ')}" } elsif error['type'] == 'required' missing_keys = error['details']['missing_keys'] { title: "is missing required properties: #{missing_keys.join(', ')}" } elsif error['type'] == 'readOnly' { title: 'appears in request, but is read-only' } elsif error['type'] == 'writeOnly' { title: 'write-only field appears in response:' } elsif SIMPLE_TYPES.include?(error['type']) { title: "should be a #{error['type']}" } elsif error['schema'] == false { title: 'unknown fields are not allowed' } else { title: "is not valid: #{error['data'].inspect}" } end end