Skip to main content

Function: addSchemaToCommand()

addSchemaToCommand(directory): (id, schema, version?, options?) => Promise<void>

Defined in: commands.ts:292

Add a schema to a command by it's id.

Optionally specify a version to add a schema to a specific version of the command.

Parameters​

ParameterType
directorystring

Returns​

Function

Parameters​

ParameterType
idstring
schema{ fileName: string; schema: string; }
schema.fileNamestring
schema.schema?string
version?string
options?{ path: string; }
options.path?string

Returns​

Promise<void>

Example​

import utils from '@eventcatalog/utils';

const { addSchemaToCommand } = utils('/path/to/eventcatalog');

// JSON schema example
const schema = {
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"name": {
"type": "string"
},
"age": {
"type": "number"
}
},
"required": ["name", "age"]
};

// adds a schema to the latest UpdateInventory command
await addSchemaToCommand('UpdateInventory', { schema, fileName: 'schema.json' });

// adds a file to a specific version of the UpdateInventory command
await addSchemaToCommand('UpdateInventory', { schema, fileName: 'schema.json' }, '0.0.1');