$schema: http://json-schema.org/draft-07/schema
description: Schema defining structure of forms configuration
type: array
items:
  $ref: "#/$defs/component"
$defs:
  children:
    type: array
    items:
      $ref: "#/$defs/component"
  placeholder:
    type: string
    description: A short hint about the input field value
  defaultExpanded:
    type: boolean
    description: Whether the widget should be expanded by default. 
    default: false
  component:
    type: object
    required:
      - path
    properties:
      path:
        description: Jsonata script used to fetch the data
        examples:
          - status.phase
          - metadata.labels
        type: string
      name:
        description: Name of component used for dispaying translations
        type: string
      widget:
        description: Name of a widget that should be used for displaying data defined by path
        type: string
        enum:
          - Alert
          - CodeEditor
          - FormGroup
          - GenericList
          - KeyValuePair
          - Name
          - Resource
          - ResourceRef
          - SimpleList
          - Text
      description:
        type: string
        description:  A string displayed in a tooltip when you hover over a question mark icon, next to the input's label. The default value is taken from the CustomResourceDefintion (CRD).
      required:
        type: boolean
        description: The default value is taken from CRD; if it doesn't exist in CRD, then it defaults to false.
      inputInfo:
        type: string
        description: A string below the input field that shows how to fill in the input
      visibility:
        type: string
        widget: Jsonata
      overwrite:
        type: boolean
      trigger:
        type: array
        widget: SimpleList
        items:
          type: string
      subscription:
        type: object
        widget: KeyValuePair
        value:
          type: string
        additionalProperties:
          type: string
          widget: Jsonata
    allOf:
      - $ref: "#/$widgets/Alert"
      - $ref: "#/$widgets/CodeEditor"
      - $ref: "#/$widgets/FormGroup"
      - $ref: "#/$widgets/GenericList"
      - $ref: "#/$widgets/KeyValuePair"
      - $ref: "#/$widgets/Name"
      - $ref: "#/$widgets/Resource"
      - $ref: "#/$widgets/ResourceRef"
      - $ref: "#/$widgets/SimpleList"
      - $ref: "#/$widgets/Text"
$widgets:
  Alert:
    if:
      properties:
        widget:
          const: Alert
    then:
      required:
        - alert
      properties:
        alert:
          type: string
          description: Information that you want to display
        disableMargin:
          type: boolean
          description: Disables the margin outside the alert body
        severity:
          type: string
          enum: [information, warning, error, success]
  CodeEditor:
    if:
      properties:
        widget:
          const: CodeEditor
    then:
      properties:
        language:
          type: string
          widget: Jsonata
        formatAsString:
          type: boolean
          description: a boolean which specifies if field is saved as string.
          default: false
        defaultExpanded:
          $ref: "#/$defs/defaultExpanded"
  FormGroup:
    if:
      properties:
        widget:
          const: FormGroup
    then:
      properties:
        columns:
          type: string
        defaultExpanded:
          $ref: "#/$defs/defaultExpanded"
        children:
          $ref: "#/$defs/children"
  GenericList:
    if:
      properties:
        widget:
          const: GenericList
    then:
      properties:
        template:
          description: Default structure for a list item
          widget: CodeEditor
          language: "'YAML'"
        placeholder:
          $ref: "#/$defs/placeholder"
        defaultExpanded:
          $ref: "#/$defs/defaultExpanded"
        children:
          $ref: "#/$defs/children"
  KeyValuePair:
    if:
      properties:
        widget:
          const: KeyValuePair
    then:
      properties:
        keyEnum:
          type: array
          description: An array of options to generate a key input field with a dropdown
          items:
            type: string
        value:
          type: object
          properties:
            type:
              description: Type of the value input.
              type: string
              enum: [object, number, text]
            valueEnum:
              type: array
              description: Array of options to generate a value input field with a dropdown.
              items:
                type: string
          if:
            properties:
              type:
                const: object
          then:
            properties:
              keyEnum:
                type: array
                description: Array of options to generate a key input field with a dropdown.
                items:
                  type: string
  Name:
    if:
      properties:
        widget:
          const: Name
    then:
      properties:
        extraPaths:
          type: array
          items:
            type: string
        disableOnEdit:
          type: boolean
  Resource:
    if:
      properties:
        widget:
          const: Resource
    then:
      properties:
        resource:
          type: object
          required:
            - kind
            - version
          properties:
            kind:
              type: string
              description: Kubernetes kind of the resource.
            group:
              type: string
              description: API group used for all requests. Not provided for Kubernetes resources in the core (also called legacy) group.
            version:
              type: string
              description: API version used for all requests.
            scope:
              type: string
              enum: [namespace, cluster]
              description: When set to cluster, namespaced resources are fetched from all Namespaces. Defaults to cluster.
            namespace:
              type: string
              description: Namespace to fetch resources from. Used only when scope is namespace and resources need to be fetched from a specific Namespace. Defaults to the active Namespace when omitted.
        filter:
          type: string
          widget: Jsonata
          description: a JSONata function to filter resources based on a given condition.
        provideVar:
          type: string
          description: when this field is defined, the chosen resource is provided as a variable of this name.
  ResourceRef:
    if:
      properties:
        widget:
          const: ResourceRef
    then:
      properties:
        resource:
          type: object
          required:
            - kind
            - version
          properties:
            kind:
              type: string
              description: Kubernetes kind of the resource.
            group:
              type: string
              description: API group used for all requests. Not provided for Kubernetes resources in the core (also called legacy) group.
            version:
              type: string
              description: API version used for all requests.
        filter:
          type: string
          widget: Jsonata    
          description: a JSONata function to filter resources based on a given condition.  
        provideVar:
          type: string
          description: when this field is defined, the chosen resource will be provided as a variable of this name.
        toInternal:
          type: string
          widget: Jsonata
          description: a JSONata function to convert from the stored value to the {name, namespace} format. Useful, for example, when the data is stored as a string.
        toExternal:
          type: string
          widget: Jsonata
          description: a JSONata function to convert from the  the {name, namespace} format to the stored value. Useful, for example, when the data is stored as a string.
        defaultExpanded:
          $ref: "#/$defs/defaultExpanded"
  SimpleList:
    if:
      properties:
        widget:
          const: SimpleList
    then:
      properties:
        placeholder:
          $ref: "#/$defs/placeholder"
        defaultExpanded:
          $ref: "#/$defs/defaultExpanded"
  Text:
    if:
      properties:
        widget:
          const: Text
    then:
      properties:
        enum:
          type: [string, array]
          widget: MultiType
          widgets:
            string: Jsonata
            array: SimpleList
          items:
            type: string
        placeholder:
          $ref: "#/$defs/placeholder"
        readOnly:
          type: boolean
          description: a boolean which specifies if field is read only.
          default: false
        decodable:
          type: boolean
          default: false
          description: field is base64-encoded and can be decoded in the UI
        decodedPlaceholder:
          type: string
          description: optional alternative placeholder to use when the field is decoded
        disableOnEdit:
          type: boolean
          description: a boolean which specifies if field is disabled on edit.
          default: false
  Switch:
    if:
      properties:
        widget:
          const: Switch
    then:
      properties:
        description:
          type: string
          description: A string displayed in a tooltip when you hover over a question mark icon, next to the input's label. The default value is taken from the CustomResourceDefintion (CRD).
        disableOnEdit:
          type: boolean
          description: a boolean which specifies if field is disabled on edit.
          default: false
  Number:
    if:
      properties:
        widget:
          const: Number
    then:
      properties:
        description:
          type: string
          description: A string displayed in a tooltip when you hover over a question mark icon, next to the input's label. The default value is taken from the CustomResourceDefintion (CRD).
        disableOnEdit:
          type: boolean
          description: a boolean which specifies if field is disabled on edit.
          default: false

