module PortalConfigSchema extend ActiveSupport::Concern # Per-locale overrides for portal level fields. Any locale present in # `allowed_locales` may carry its own `name`, `page_title` and `header_text`. # Missing values fall back to the default locale and finally to the base column. LOCALE_TRANSLATION_SCHEMA = { 'type' => 'object', 'properties' => { 'name' => { 'type' => %w[string null] }, 'page_title' => { 'type' => %w[string null] }, 'header_text' => { 'type' => %w[string null] } }, 'additionalProperties' => false }.freeze # Per-locale recommended content for the portal home page: an ordered list of # `category_ids` (the hero's "Recommended topics" pills) and `article_ids` (the # "Recommended" articles section). When empty, the portal uses its defaults. POPULAR_CONTENT_SCHEMA = { 'type' => 'object', 'properties' => { 'category_ids' => { 'type' => %w[array null], 'items' => { 'type' => 'integer' } }, 'article_ids' => { 'type' => %w[array null], 'items' => { 'type' => 'integer' } } }, 'additionalProperties' => false }.freeze CONFIG_PARAMS_SCHEMA = { 'type' => 'object', 'properties' => { 'allowed_locales' => { 'type' => %w[array null], 'items' => { 'type' => 'string' } }, 'default_locale' => { 'type' => %w[string null] }, 'draft_locales' => { 'type' => %w[array null], 'items' => { 'type' => 'string' } }, 'layout' => { 'type' => %w[string null], 'enum' => ['classic', 'documentation', nil] }, # TODO: unused reserved key; remove with a migration that scrubs it from existing portals' config 'website_token' => { 'type' => %w[string null] }, 'social_profiles' => { 'type' => %w[object null] }, 'locale_translations' => { 'type' => %w[object null], 'additionalProperties' => LOCALE_TRANSLATION_SCHEMA }, 'popular_content' => { 'type' => %w[object null], 'additionalProperties' => POPULAR_CONTENT_SCHEMA } }, 'required' => [], 'additionalProperties' => true }.to_json.freeze end