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.
Class Method Details
.error_details(error) ⇒ Object
rubocop:disable Metrics/MethodLength rubocop:disable Metrics/AbcSize
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/openapi_first/validation_format.rb', line 9 def self.error_details(error) if error['type'] == 'pattern' { title: 'is not valid', detail: "does not match pattern '#{error['schema']['pattern']}'" } elsif error['type'] == 'required' missing_keys = error['details']['missing_keys'] { title: "is missing required properties: #{missing_keys.join(', ')}" } 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 |