sdk icon indicating copy to clipboard operation
sdk copied to clipboard

Change "integrationConfigFields.json" to be JSON schema compatible

Open austinkelleher opened this issue 5 years ago • 1 comments

Currently, integrations perform a lot of basic validation on IntegrationInstance config that could be shifted to automatic validation in the SDK. We could do this by changing our existing integrationConfigFields.json to be JSON schema compatible.

For example, many integrations have validation like this:

const apiKey = instance.config?.apiKey;
if (!apiKey) {
  throw new Error(
    'Configuration option "apiKey" is missing on the integration instance config',
  );
}

// More simple validation...

Proposed:

integrationConfigFields.json:

{
  // We assume that every `integrationConfigFields.json` is type "object". If it is specified, we
  // will just ignore it.
  // type: "object",
  "properties": {
    "apiKey": {
      "type": "string",
      "format": "masked"
    },
    "myNumberField": {
      "type": "number",
      "minimum": 1,
      "maximum": 5
    }
  },
  "required": ["apiKey"]
}

The apiKey property above has a "format" property. We will write a custom ajv formatter for masked properties.

austinkelleher avatar Apr 23 '20 12:04 austinkelleher

I think it still a good idea to have a JSON Schema for the config, but now that we have moved projects to integrationConfigFields.ts, we'd likely want to generate the schema.

aiwilliams avatar May 14 '20 18:05 aiwilliams