Module: Scorpio::OpenAPI::SchemaElements

Defined in:
lib/scorpio/openapi/schema_elements.rb,
lib/scorpio/openapi/schema_elements/type_nullable.rb

Constant Summary collapse

TYPE_NULLABLE =
JSI::Schema::Element.new(keywords: ['type', 'nullable']) do |element|
  element.add_action(:validate) do
    next if !keyword?('type')
    if instance.nil?
      validate(
        schema_content['nullable'] == true,
        'validation.keyword.type.not_nullable',
        "instance is null without `nullable` = true",
        keyword: 'nullable',
      )
    else
      if !instance_types.key?(schema_content['type'])
        next # schema error; skip validation
      end
      validate(
        instance_exec(&instance_types[schema_content['type']]),
        'validation.keyword.type.not_match',
        "instance type does not match `type` value",
        keyword: 'type',
      )
    end
  end
end