Module: Tamara::JsonSchemas::Address

Defined in:
lib/tamara/json_schemas/address.rb

Class Method Summary collapse

Class Method Details

.schema(allows_null: false) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/tamara/json_schemas/address.rb', line 4

def self.schema(allows_null: false)
  {
    "$schema": "http://json-schema.org/draft-06/schema",
    type: ["object", (allows_null ? "null" : nil)].compact,
    properties: {
      city: Types::String.schema,
      country_code: Types::Enum.schema(values: COUNTRY_CODES, default: "SA"),
      first_name: Types::String.schema,
      last_name: Types::String.schema,
      line1: Types::String.schema,
      line2: Types::String.schema(allows_null: true),
      phone_number: Types::String.schema(allows_null: true),
      region: Types::String.schema(allows_null: true)
    },
    required: %w[city country_code first_name last_name line1]
  }
end