Module: OpenapiFirst::ValidationFormat
- Defined in:
- lib/openapi_first/validation_format.rb
Constant Summary collapse
- SIMPLE_TYPES =
%w[string integer].freeze
Class Method Summary collapse
-
.error_details(error) ⇒ Object
rubocop:disable Metrics/MethodLength rubocop:disable Metrics/AbcSize rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/PerceivedComplexity.
Class Method Details
.error_details(error) ⇒ Object
rubocop:disable Metrics/MethodLength rubocop:disable Metrics/AbcSize rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/PerceivedComplexity
11 12 13 14 15 16 17 18 19 20 21 22 23 24 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 |
# 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 |