{
  "$schema": "http://json-schema.org/draft-07/schema",
  "$id": "http://json.openmrs.org/routes.schema.json",
  "$comment": "This schema is intended to help guide authors. When parsed, the schema may support additional properties added by our tooling, e.g., the version property.",
  "title": "OpenMRS Routes Schema",
  "description": "This schema defines the expected values of routes.json files provided by OpenMRS frontend modules. These files describe the pages, extensions, and requirements of the frontend module so they can be appropriately consumed by the app shell.",
  "type": "object",
  "properties": {
    "$schema": {
      "type": "string",
      "description": "The schema for this JSON document. Should point to the canonical URL for this document.",
      "default": "https://json.openmrs.org/routes.schema.json"
    },
    "backendDependencies": {
      "type": "object",
      "description": "A list of backend modules necessary for this frontend module and the corresponding required versions.",
      "additionalProperties": {
        "type": "string"
      }
    },
    "optionalBackendDependencies": {
      "type": "object",
      "description": "A list of backend modules that may enable optional functionality in this frontend module if available and the corresponding required versions.",
      "additionalProperties": {
        "oneOf": [
          {
            "type": "string"
          },
          {
            "type": "object",
            "properties": {
              "version": {
                "type": "string",
                "description": "A SemVer range specifying the allowed versions"
              },
              "feature": {
                "type": "object",
                "description": "Details of the feature flag to be registered and enabled if this optional dependency is available.",
                "properties": {
                  "flagName": {
                    "type": "string",
                    "description": "A code-friendly name for the flag, which will be used to reference it in code"
                  },
                  "label": {
                    "type": "string",
                    "description": "A human-friendly name for the flag, which will be used when it needs to be displayed"
                  },
                  "description": {
                    "type": "string",
                    "description": "An explanation of what the flag does, which will be displayed in the Implementer Tools"
                  }
                },
                "required": ["flagName", "label", "description"]
              }
            },
            "required": ["version"]
          }
        ]
      }
    },
    "pages": {
      "type": "array",
      "description": "An array of all pages provided by this frontend module. Pages are automatically mounted based on a route.",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "component": {
            "type": "string",
            "description": "The name of the component exported by this frontend module."
          },
          "route": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "boolean"
              }
            ],
            "description": "Either a string or a boolean.\n If a string value, this is used to indicate that this page should be rendered. For example, \"name\" will match when the current page is ${window.spaBase}/name.\n If a boolean, this either indicates that the component should always be rendered or should never be rendered."
          },
          "routeRegex": {
            "type": "string",
            "format": "regex",
            "description": "A regular expression used to match against the current route to determine whether this page should be rendered. Note that ${window.spaBase} will be removed before attempting to match, so setting this to \"^name.+\" will match any route that starts with ${window.spaBase}/name."
          },
          "privilege": {
            "oneOf": [
              {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              {
                "type": "string"
              }
            ],
            "description": "One or more privileges that a user must have in order for this page to be available."
          },
          "online": {
            "type": "boolean",
            "description": "Determines whether the component renders while the browser is connected to the internet. If false, this page will never render while online.",
            "default": true
          },
          "offline": {
            "type": "boolean",
            "description": "Determines whether the component renders while the browser is not connected to the internet. If false, this page will never render while offline.",
            "default": true
          },
          "order": {
            "type": "integer",
            "description": "Determines the order in which the DOM element rendered this page is rendered. This should be used sparingly, but is sometimes necessary to ensure the resulting mark-up is correct.",
            "minimum": 0
          },
          "featureFlag": {
            "type": "string",
            "description": "The name of a feature flag that is defined in the system"
          },
          "containerDomId": {
            "type": "string",
            "description": "The id of the DOM element that this page should be rendered into. This is very rarely a property that's needed outside of the core framework."
          }
        },
        "required": ["component"],
        "oneOf": [
          {
            "required": ["route"]
          },
          {
            "required": ["routeRegex"]
          }
        ]
      }
    },
    "extensions": {
      "type": "array",
      "description": "An array of all extensions provided by this frontend module. Extensions can be mounted in extension slots, either via declarations in this file or configuration.",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "name": {
            "type": "string",
            "description": "The name of this extension. This is used to refer to the extension in configuration."
          },
          "component": {
            "type": "string",
            "description": "The name of the component exported by this frontend module."
          },
          "slot": {
            "type": "string",
            "description": "If supplied, the slot that this extension is rendered into by default. Note that this is overridden by the slots property if that is also specified."
          },
          "slots": {
            "type": "array",
            "description": "If supplied, the slots that this extension is rendered into by default."
          },
          "privilege": {
            "oneOf": [
              {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              {
                "type": "string"
              }
            ],
            "description": "One or more privileges that a user must have in order for this extension to be available."
          },
          "online": {
            "type": "boolean",
            "description": "Determines whether the component renders while the browser is connected to the internet. If false, this page will never render while online.",
            "default": true
          },
          "offline": {
            "type": "boolean",
            "description": "Determines whether the component renders while the browser is not connected to the internet. If false, this page will never render while offline.",
            "default": true
          },
          "order": {
            "type": "integer",
            "description": "Determines the order in which this component renders in its default extension slot. Note that this can be overridden by configuration.",
            "minimum": 0
          },
          "meta": {
            "type": "object",
            "description": "Meta describes any properties that are passed down to the extension when it is loaded"
          },
          "featureFlag": {
            "type": "string",
            "description": "The name of a feature flag that is defined in the system"
          }
        },
        "required": ["component", "name"]
      }
    },
    "featureFlags": {
      "type": "array",
      "description": "An array of feature flags declared by this module.",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "flagName": {
            "type": "string",
            "description": "A code-friendly name for the flag, which will be used to reference it in code"
          },
          "label": {
            "type": "string",
            "description": "A human-friendly name which will be displayed in the Implementer Tools"
          },
          "description": {
            "type": "string",
            "description": "An explanation of what the flag does, which will be displayed in the Implementer Tools"
          }
        }
      },
      "required": ["flagName", "label", "description"]
    },
    "modals": {
      "type": "array",
      "description": "An array of all modals provided by this frontend module. Modals are launched by name using the `showModal` function.",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "name": {
            "type": "string",
            "description": "The name of this modal. This is used to launch the modal."
          },
          "component": {
            "type": "string",
            "description": "The name of the component exported by this frontend module."
          }
        },
        "required": ["component", "name"]
      }
    },
    "workspaces": {
      "type": "array",
      "description": "An array of all workspaces provided by this frontend module. Workspaces are launched by name using the `launchWorkspace` function.",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "name": {
            "type": "string",
            "description": "The name of this workspace. This is used to launch the workspace."
          },
          "title": {
            "type": "string",
            "description": "The title of the workspace. This will be looked up as a key in the translations of the module defining the workspace."
          },
          "component": {
            "type": "string",
            "description": "The name of the component exported by this frontend module."
          },
          "type": {
            "type": "string",
            "description": "The type of the workspace. Only one of each \"type\" of workspace is allowed to be open at a time. The default is \"form\". If the right sidebar is in use, then the type determines which right sidebar icon corresponds to the workspace."
          },
          "canHide": {
            "type": "boolean",
            "description": "Controls whether the workspace, once opened, can be hidden into the side rail."
          },
          "canMaximize": {
            "type": "boolean",
            "description": "Controls whether the workspace can be displayed in full-screen mode on a desktop."
          },
          "width": {
            "type": "string",
            "enum": ["narrow", "wider", "extra-wide"],
            "description": "Controls the width of the workspace. The default is \"narrow\" and this should only be changed to \"wider\" if the workspace itself has internal navigation, like the form editor. The width \"extra-wide\" is for workspaces that contain their own sidebar."
          },
          "preferredWindowSize": {
            "type": "string",
            "enum": ["maximized", "hidden", "normal"],
            "description": "Controls the default \"mode\" that the workspace opens in, either \"maximized\", \"hidden\", or \"normal\"."
          },
          "groups": {
            "type": "array",
            "description": "An array of workspace group names that this workspace belongs to.",
            "default": []
          }
        },
        "required": ["name", "title", "component", "type"]
      }
    },
    "workspaceGroups": {
      "type": "array",
      "description": "An array of all workspace groups provided by this frontend module. Workspace groups are used to group workspaces together in the workspace area.",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "name": {
            "type": "string",
            "description": "The name of this workspace group. This is used to refer to the group in configuration."
          },
          "members": {
            "type": "array",
            "description": "An array of workspace names that belong to this group."
          }
        },
        "required": ["name"]
      }
    },
    "workspaces2": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "description": "The name of this workspace. This string is used to launch the workspace (as the first parameter when calling `launchWorkspace2`)."
          },
          "component": {
            "type": "string",
            "description": "The name of the component exported by this frontend module."
          },
          "window": {
            "type": "string",
            "description": "The name of the workspace window that this workspace belongs to."
          },
          "width": {
            "type": "string",
            "enum": ["narrow", "wider", "extra-wide"],
            "description": "Overrides the window's width while this workspace is the top-most workspace in its window. The whole window, including parent workspaces beneath it, renders at this width. When omitted, the window's width is used, falling back to narrow."
          },
          "meta": {
            "type": "object",
            "additionalProperties": true,
            "description": "Properties passed to the workspace component via workspaceMeta, available through useWorkspace2Context().workspaceMeta."
          }
        },
        "required": ["name", "component", "window"],
        "additionalProperties": false
      }
    },
    "workspaceWindows2": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "description": "The name of the workspace window."
          },
          "icon": {
            "type": "string",
            "description": "Optional. The name of the component exported by this frontend module. This component should render `<ActionMenuButton2>` and is used as an icon in the workspace action menu. A workspace window can be minimized (hidden) if and only if it has an icon defined."
          },
          "canMaximize": {
            "type": "boolean",
            "description": "Whether this workspace window can be maximized to take up the main content area"
          },
          "group": {
            "type": "string",
            "description": "The name of the workspace group that this window belongs to."
          },
          "order": {
            "type": "integer",
            "description": "Determines the order in which this window's icon renders in the workspace action menu."
          },
          "width": {
            "type": "string",
            "enum": ["narrow", "wider", "extra-wide"],
            "description": "Controls the width of the workspace. The default is \"narrow\" and this should only be changed to \"wider\" if the workspace itself has internal navigation, like the form editor."
          }
        },
        "required": ["name", "group"],
        "additionalProperties": false
      }
    },
    "workspaceGroups2": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "description": "The name of this workspace group. This string is used to launch the workspace group (as the first parameter when calling `launchWorkspaceGroup2`)."
          },
          "overlay": {
            "type": "boolean",
            "description": "Whether the group's windows are rendered on top of (overlaying) the main content or takes up horizontal space to the side of the main content."
          },
          "persistence": {
            "type": "string",
            "enum": ["app-wide", "closable"],
            "description": "In app-wide mode, a workspace group renders its action menu without a close button. In closable mode, the action menu has a close button. Defaults to app-wide"
          },
          "closeable": {
            "type": "boolean",
            "description": "Whether the workspace group can be closed by the user."
          },
          "scopePattern": {
            "type": "string",
            "description": "URL pattern that defines the scope where workspaces in this group should persist. If not defined, workspaces close only when navigating to a different app. If defined without capture groups, workspaces close when URL doesn't match pattern. If defined with capture groups, workspaces close when captured values change."
          }
        },
        "required": ["name"],
        "additionalProperties": false
      }
    }
  },
  "additionalProperties": false,
  "additionalItems": false
}
