$id: "@ali/low-code-component-protocol-schema"
description: json schema for low code component protocol
allOf:
  - $ref: "#/definitions/BasicSection"
  - $ref: "#/definitions/PropsSection"
  - $ref: "#/definitions/ConfigureSection"
definitions:
  BasicSection:
    type: object
    properties:
      componentName:
        type: string
      title:
        type: string
      description:
        type: string
      docUrl:
        type: string
      screenshot:
        type: string
      icon:
        type: string
      tags:
        type: array
        items:
          type: string
      devMode:
        enum:
          - proCode
          - lowCode
      npm:
        $ref: "#/definitions/Npm"
    required:
      - componentName
      - title
      - npm
  PropsSection:
    type: object
    required:
      - props
    properties:
      props:
        type: array
        items:
          properties:
            name:
              type: string
            propType:
              $ref: "#/definitions/PropType"
            description:
              type: string
            defaultValue: {}
          required:
            - name
            - propType
  ConfigureSection:
    type: object
    properties:
      configure:
        type: object
        properties:
          props:
            type: array
            items:
              $ref: "#/definitions/ConfigureProp"
          styles:
            type: object
            properties: {}
          events:
            type: object
            properties: {}
          component:
            $ref: "#/definitions/ConfigureComponent"
  Npm:
    type: object
    properties:
      package:
        type: string
      exportName:
        type: string
      subName:
        type: string
      main:
        type: string
      destructuring:
        type: boolean
      version:
        type: string
    required:
      - package
      - exportName
      - subName
      - main
      - destructuring
      - version
  PropType:
    oneOf:
      - $ref: "#/definitions/BasicType"
      - $ref: "#/definitions/RequiredType"
      - $ref: "#/definitions/ComplexType"
  BasicType:
    type: string
    enum:
      - array
      - bool
      - func
      - number
      - object
      - string
      - node
      - element
      - any
  RequiredType:
    type: object
    properties:
      type:
        $ref: "#/definitions/BasicType"
      isRequired:
        type: boolean
    additionalProperties: false
    required:
      - type
  ComplexType:
    oneOf:
      - $ref: "#/definitions/OneOf"
      - $ref: "#/definitions/OneOfType"
      - $ref: "#/definitions/ArrayOf"
      - $ref: "#/definitions/ObjectOf"
      - $ref: "#/definitions/Shape"
      - $ref: "#/definitions/Exact"
  OneOf:
    type: object
    required:
      - type
      - value
    properties:
      type:
        type: string
        enum:
          - oneOf
      value:
        type: array
        items:
          oneOf:
            - type: string
            - type: number
            - type: boolean
      isRequired:
        type: boolean
  OneOfType:
    type: object
    required:
      - type
      - value
    properties:
      type:
        type: string
        enum:
          - oneOfType
      value:
        type: array
        items:
          $ref: "#/definitions/PropType"
      isRequired:
        type: boolean
  ArrayOf:
    type: object
    required:
      - type
      - value
    properties:
      type:
        type: string
        enum:
          - arrayOf
      value:
        $ref: "#/definitions/PropType"
      isRequired:
        type: boolean
  ObjectOf:
    type: object
    required:
      - type
      - value
    properties:
      type:
        type: string
        enum:
          - objectOf
      value:
        $ref: "#/definitions/PropType"
      isRequired:
        type: boolean
  Shape:
    type: object
    required:
      - type
      - value
    properties:
      type:
        type: string
        enum:
          - shape
      value:
        type: array
        items:
          type: object
          properties:
            name:
              type: string
            propType:
              $ref: "#/definitions/PropType"
          additionalProperties: false
      isRequired:
        type: boolean
  ShapeItem:
    type: object
    required:
      - name
      - propType
    properties:
      name:
        type: string
      propType:
        $ref: "#/definitions/PropType"
      isRequired:
        type: boolean
    additionalProperties: false
  Exact:
    type: object
    required:
      - type
      - value
    properties:
      type:
        type: string
        enum:
          - exact
      value:
        type: array
        items:
          type: object
          properties:
            name:
              type: string
            propType:
              $ref: "#/definitions/PropType"
          additionalProperties: false
      isRequired:
        type: boolean
  ConfigureProp:
    type: object
    allOf:
      - type: object
        properties:
          title:
            type: string
          extraProps:
            type: object
            properties: {}
      - oneOf:
          - $ref: "#/definitions/ConfigureFieldProp"
          - $ref: "#/definitions/ConfigureGroupProp"
  ConfigureFieldProp:
    type: object
    required:
      - type
    properties:
      type:
        type: string
        enum:
          - field
      name:
        type: string
      setter:
        $ref: "#/definitions/ConfigureFieldSetter"
  ConfigureFieldSetter:
    type: object
    required:
      - componentName
    properties:
      componentName:
        type: string
        enum:
          - List
          - Object
          - Function
          - Node
          - Mixin
          - Expression
          - Switch
          - Number
          - Input
          - TextArea
          - Date
          - DateYear
          - DateMonth
          - DateRange
          - ColorPicker
          - CodeEditor
          - Select
          - RadioGroup
      props:
        type: object
        properties: {} # 暂未校验每个控件的props，待控件入料后获取真实属性
  ConfigureGroupProp:
    type: object
    required:
      - type
      - items
    properties:
      type:
        type: string
        enum:
          - group
      items:
        type: array
        items:
          $ref: "#/definitions/ConfigureProp"
  ConfigureComponent:
    type: object
    properties:
      isContainer:
        type: boolean
      isModal:
        type: boolean
      descriptor:
        type: string
      nestingRule:
        type: object
        properties:
          childWhitelist:
            type: array
            items:
              type: string
          parentWhitelist:
            type: array
            items:
              type: string
          descendantBlacklist:
            type: array
            items:
              type: string
          ancestorWhitelist:
            type: array
            items:
              type: string
      isNullNode:
        type: boolean
      isLayout:
        type: boolean
