From 72f486b578eb56fe3f8eeae24e365e6d705693cc Mon Sep 17 00:00:00 2001 From: Niklas Kiefer Date: Thu, 17 Feb 2022 11:30:00 +0100 Subject: [PATCH] feat(cloud-element-templates): validate against JSON Schema Closes #561 --- src/index.js | 3 + .../cloud-element-templates/Validator.js | 69 ++- src/provider/element-templates/Validator.js | 4 +- .../cloud-element-templates/Validator.spec.js | 417 ++++++++++++++++++ .../fixtures/connectors.json | 189 ++++++++ .../fixtures/error-binding-missing.json | 16 + .../fixtures/error-groups-missing-id.json | 24 + .../fixtures/error-id-duplicate.json | 20 + .../fixtures/error-id-missing.json | 10 + .../fixtures/error-id-version-duplicate.json | 22 + .../fixtures/error-invalid-optional.json | 20 + .../fixtures/error-name-missing.json | 10 + .../fixtures/error-optional-not-empty.json | 23 + .../fixtures/groups.json | 70 +++ .../fixtures/simple-defined-schema.json | 9 + .../fixtures/simple-high-schema-version.json | 49 ++ .../simple-latest-schema-version.json | 49 ++ .../fixtures/simple-low-schema-version.json | 49 ++ .../fixtures/simple-missing-schema.json | 8 + .../fixtures/simple-mixed-schema-version.json | 49 ++ .../fixtures/simple-same-schema-version.json | 49 ++ .../fixtures/simple-wrong-schema.json | 9 + 22 files changed, 1160 insertions(+), 8 deletions(-) create mode 100644 test/spec/provider/cloud-element-templates/Validator.spec.js create mode 100644 test/spec/provider/cloud-element-templates/fixtures/connectors.json create mode 100644 test/spec/provider/cloud-element-templates/fixtures/error-binding-missing.json create mode 100644 test/spec/provider/cloud-element-templates/fixtures/error-groups-missing-id.json create mode 100644 test/spec/provider/cloud-element-templates/fixtures/error-id-duplicate.json create mode 100644 test/spec/provider/cloud-element-templates/fixtures/error-id-missing.json create mode 100644 test/spec/provider/cloud-element-templates/fixtures/error-id-version-duplicate.json create mode 100644 test/spec/provider/cloud-element-templates/fixtures/error-invalid-optional.json create mode 100644 test/spec/provider/cloud-element-templates/fixtures/error-name-missing.json create mode 100644 test/spec/provider/cloud-element-templates/fixtures/error-optional-not-empty.json create mode 100644 test/spec/provider/cloud-element-templates/fixtures/groups.json create mode 100644 test/spec/provider/cloud-element-templates/fixtures/simple-defined-schema.json create mode 100644 test/spec/provider/cloud-element-templates/fixtures/simple-high-schema-version.json create mode 100644 test/spec/provider/cloud-element-templates/fixtures/simple-latest-schema-version.json create mode 100644 test/spec/provider/cloud-element-templates/fixtures/simple-low-schema-version.json create mode 100644 test/spec/provider/cloud-element-templates/fixtures/simple-missing-schema.json create mode 100644 test/spec/provider/cloud-element-templates/fixtures/simple-mixed-schema-version.json create mode 100644 test/spec/provider/cloud-element-templates/fixtures/simple-same-schema-version.json create mode 100644 test/spec/provider/cloud-element-templates/fixtures/simple-wrong-schema.json diff --git a/src/index.js b/src/index.js index 857ad8d3c..0b3851caf 100644 --- a/src/index.js +++ b/src/index.js @@ -8,3 +8,6 @@ export { DescriptionProvider as ZeebeDescriptionProvider } from './contextProvid // hooks export { useService } from './hooks'; + +// utils +export { Validator as CloudElementTemplatesValidator } from './provider/cloud-element-templates/Validator'; diff --git a/src/provider/cloud-element-templates/Validator.js b/src/provider/cloud-element-templates/Validator.js index 01ed909f1..447737d11 100644 --- a/src/provider/cloud-element-templates/Validator.js +++ b/src/provider/cloud-element-templates/Validator.js @@ -1,5 +1,19 @@ -import { Validator as BaseValidator } from '../element-templates/Validator'; +import { + Validator as BaseValidator, + filteredSchemaErrors, + getSchemaVersion +} from '../element-templates/Validator'; +import semver from 'semver'; + +import { + validateZeebe as validateAgainstSchema, + getZeebeSchemaPackage as getTemplateSchemaPackage, + getZeebeSchemaVersion as getTemplateSchemaVersion +} from '@bpmn-io/element-templates-validator'; + +const SUPPORTED_SCHEMA_VERSION = getTemplateSchemaVersion(); +const SUPPORTED_SCHEMA_PACKAGE = getTemplateSchemaPackage(); /** * A Camunda Cloud element template validator. @@ -10,8 +24,6 @@ export class Validator extends BaseValidator { } /** - * TODO(pinussilvestrus): we disable JSON schema validation for now. - * * Validate given template and return error (if any). * * @param {TemplateDescriptor} template @@ -22,9 +34,34 @@ export class Validator extends BaseValidator { let err; const id = template.id, - version = template.version || '_'; + version = template.version || '_', + schema = template.$schema, + schemaVersion = schema && getSchemaVersion(schema); + + // (1) compatibility + if (schemaVersion && (semver.compare(SUPPORTED_SCHEMA_VERSION, schemaVersion) < 0)) { + return this._logError( + `unsupported element template schema version <${ schemaVersion }>. Your installation only supports up to version <${ SUPPORTED_SCHEMA_VERSION }>. Please update your installation`, + template + ); + } + + // (2) $schema attribute defined + if (!schema) { + return this._logError( + 'missing $schema attribute.', + template + ); + } + + if (!this.isSchemaValid(schema)) { + return this._logError( + `unsupported $schema attribute <${ schema }>.`, + template + ); + } - // (1) versioning + // (3) versioning if (this._templatesById[ id ] && this._templatesById[ id ][ version ]) { if (version === '_') { return this._logError(`template id <${ id }> already used`, template); @@ -33,6 +70,26 @@ export class Validator extends BaseValidator { } } + // (4) JSON schema compliance + const validationResult = validateAgainstSchema(template); + + const { + errors, + valid + } = validationResult; + + if (!valid) { + err = new Error('invalid template'); + + filteredSchemaErrors(errors).forEach((error) => { + this._logError(error.message, template); + }); + } + return err; } -} + + isSchemaValid(schema) { + return schema && schema.includes(SUPPORTED_SCHEMA_PACKAGE); + } +} \ No newline at end of file diff --git a/src/provider/element-templates/Validator.js b/src/provider/element-templates/Validator.js index b0d9d19a5..5403e514c 100644 --- a/src/provider/element-templates/Validator.js +++ b/src/provider/element-templates/Validator.js @@ -167,7 +167,7 @@ export class Validator { * * @return {String} for example '99.99.99' */ -function getSchemaVersion(schemaUri) { +export function getSchemaVersion(schemaUri) { const re = /\d+\.\d+\.\d+/g; const match = schemaUri.match(re); @@ -189,7 +189,7 @@ function getSchemaVersion(schemaUri) { * * @return {Array} */ -function filteredSchemaErrors(schemaErrors) { +export function filteredSchemaErrors(schemaErrors) { return filter(schemaErrors, (err) => { const { dataPath, diff --git a/test/spec/provider/cloud-element-templates/Validator.spec.js b/test/spec/provider/cloud-element-templates/Validator.spec.js new file mode 100644 index 000000000..33df78c98 --- /dev/null +++ b/test/spec/provider/cloud-element-templates/Validator.spec.js @@ -0,0 +1,417 @@ +import { Validator } from 'src/provider/cloud-element-templates/Validator'; + +import { getZeebeSchemaVersion as getTemplateSchemaVersion } from '@bpmn-io/element-templates-validator'; + +const ElementTemplateSchemaVersion = getTemplateSchemaVersion(); + + +describe('provider/cloud-element-templates - Validator', function() { + + function errors(validator) { + return validator.getErrors().map(function(e) { + return e.message; + }); + } + + function valid(validator) { + return validator.getValidTemplates(); + } + + describe('schema version', function() { + + it('should accept when template and library have the same version', function() { + + // given + const templates = new Validator(); + + const templateDescriptor = require('./fixtures/simple-same-schema-version.json'); + + templateDescriptor.map(function(template) { + template.$schema = 'https://unpkg.com/@camunda/zeebe-element-templates-json-schema@' + + ElementTemplateSchemaVersion + '/resources/schema.json'; + }); + + // when + templates.addAll(templateDescriptor); + + // then + expect(errors(templates)).to.be.empty; + + expect(valid(templates)).to.have.length(templateDescriptor.length); + }); + + + it('should accept when template has lower version than library', function() { + + // given + const templates = new Validator(); + + const templateDescriptor = require('./fixtures/simple-low-schema-version.json'); + + // when + templates.addAll(templateDescriptor); + + // then + expect(errors(templates)).to.be.empty; + + expect(valid(templates)).to.have.length(templateDescriptor.length); + }); + + + it('should reject when template has higher version than library', function() { + + // given + const templates = new Validator(); + + const templateDescriptor = require('./fixtures/simple-high-schema-version.json'); + + // when + templates.addAll(templateDescriptor); + + // then + expect(valid(templates)).to.be.empty; + + expect(errors(templates)).to.have.length(templateDescriptor.length); + }); + + + it('should accept when template has no version', function() { + + // given + const templates = new Validator(); + + const templateDescriptor = require('./fixtures/simple.json'); + + // when + templates.addAll(templateDescriptor); + + // then + expect(errors(templates)).to.be.empty; + + expect(valid(templates)).to.have.length(templateDescriptor.length); + }); + + + it('should accept when template has latest version', function() { + + // given + const templates = new Validator(); + + const templateDescriptor = require('./fixtures/simple-latest-schema-version.json'); + + // when + templates.addAll(templateDescriptor); + + // then + expect(errors(templates)).to.be.empty; + + expect(valid(templates)).to.have.length(templateDescriptor.length); + }); + + + it('should accept and reject when some templates have unsupported version', function() { + + // given + const templates = new Validator(); + + const templateDescriptor = require('./fixtures/simple-mixed-schema-version.json'); + + // when + templates.addAll(templateDescriptor); + + // then + expect(errors(templates)).to.have.length(3); + + expect(valid(templates)).to.have.length(3); + }); + + + it('should provide correct error details when rejecting', function() { + + // given + const templates = new Validator(); + + const templateDescriptor = require('./fixtures/simple-high-schema-version.json'); + + // when + templates.addAll(templateDescriptor); + + // then + expect(errors(templates)).to.have.length(6); + + expect(errors(templates)[0]).to.eql('template(id: , name: ): unsupported element template schema version <99.99.99>. Your installation only supports up to version <' + ElementTemplateSchemaVersion + '>. Please update your installation'); + }); + + }); + + + describe('schema attribute', function() { + + it('should accept', function() { + + // given + const templates = new Validator(); + + const templateDescriptor = require('./fixtures/simple-defined-schema.json'); + + // when + templates.addAll(templateDescriptor); + + // then + expect(errors(templates)).to.be.empty; + + expect(valid(templates)).to.have.length(templateDescriptor.length); + }); + + + it('should reject - missing $schema', function() { + + // given + const templates = new Validator(); + + const templateDescriptor = require('./fixtures/simple-missing-schema.json'); + + // when + templates.addAll(templateDescriptor); + + // then + expect(valid(templates)).to.be.empty; + + expect(errors(templates)).to.jsonEqual([ + 'template(id: , name: ): missing $schema attribute.' + ]); + }); + + + it('should reject - wrong $schema', function() { + + // given + const templates = new Validator(); + + const templateDescriptor = require('./fixtures/simple-wrong-schema.json'); + + // when + templates.addAll(templateDescriptor); + + // then + expect(valid(templates)).to.be.empty; + + expect(errors(templates)).to.jsonEqual([ + 'template(id: , name: ): unsupported $schema attribute .' + ]); + }); + + }); + + + describe('content validation', function() { + + it('should accept simple example templates', function() { + + // given + const templates = new Validator(); + + const templateDescriptor = require('./fixtures/simple'); + + // when + templates.addAll(templateDescriptor); + + // then + expect(errors(templates)).to.be.empty; + + expect(valid(templates)).to.have.length(templateDescriptor.length); + }); + + + it('should accept complex example templates', function() { + + // given + const templates = new Validator(); + + const templateDescriptor = require('./fixtures/complex'); + + // when + templates.addAll(templateDescriptor); + + // then + expect(errors(templates)).to.be.empty; + + expect(valid(templates)).to.have.length(templateDescriptor.length); + }); + + it('should accept connectors templates', function() { + + // given + const templates = new Validator(); + + const templateDescriptor = require('./fixtures/connectors'); + + // when + templates.addAll(templateDescriptor); + + // then + expect(errors(templates)).to.be.empty; + + expect(valid(templates)).to.have.length(templateDescriptor.length); + }); + + + it('should reject missing name', function() { + + // given + const templates = new Validator(); + + const templateDescriptor = require('./fixtures/error-name-missing'); + + // when + templates.addAll(templateDescriptor); + + // then + expect(errors(templates)).to.contain('template(id: , name: ): missing template name'); + + expect(valid(templates)).to.be.empty; + }); + + + it('should reject missing id', function() { + + // given + const templates = new Validator(); + + const templateDescriptor = require('./fixtures/error-id-missing'); + + // when + templates.addAll(templateDescriptor); + + // then + expect(errors(templates)).to.contain('template(id: , name: ): missing template id'); + + expect(valid(templates)).to.be.empty; + }); + + + it('should reject missing binding', function() { + + // given + const templates = new Validator(); + + const templateDescriptor = require('./fixtures/error-binding-missing'); + + // when + templates.addAll(templateDescriptor); + + // then + expect(errors(templates)).to.contain('template(id: , name: ): missing binding for property "0"'); + + expect(valid(templates)).to.be.empty; + }); + + + it('should reject duplicate id', function() { + + // given + const templates = new Validator(); + + const templateDescriptor = require('./fixtures/error-id-duplicate'); + + // when + templates.addAll(templateDescriptor); + + // then + expect(errors(templates)).to.contain('template(id: , name: ): template id already used'); + + expect(valid(templates)).to.have.length(1); + }); + + + it('should reject duplicate id and version', function() { + + // given + const templates = new Validator(); + + const templateDescriptor = require('./fixtures/error-id-version-duplicate'); + + // when + templates.addAll(templateDescriptor); + + // then + expect(errors(templates)).to.contain('template(id: , name: ): template id and version <1> already used'); + + expect(valid(templates)).to.have.length(1); + }); + + + it('should reject invalid optional binding type', function() { + + // given + const templates = new Validator(); + + const templateDescriptor = require('./fixtures/error-invalid-optional'); + + // when + templates.addAll(templateDescriptor); + + // then + expect(errors(templates)).to.contain('template(id: , name: ): optional is not supported for binding type "zeebe:taskHeader"; must be any of { zeebe:input, zeebe:output }'); + + expect(valid(templates)).to.be.empty; + }); + + + it('should reject optional=true <-> constraints.notEmpty=true', function() { + + // given + const templates = new Validator(); + + const templateDescriptor = require('./fixtures/error-optional-not-empty'); + + // when + templates.addAll(templateDescriptor); + + // then + expect(errors(templates)).to.contain('template(id: , name: ): optional is not allowed for truthy "notEmpty" constraint'); + + expect(valid(templates)).to.be.empty; + }); + + + describe('grouping', function() { + + it('should accept groups', function() { + + // given + const templates = new Validator(); + + const templateDescriptor = require('./fixtures/groups'); + + // when + templates.addAll(templateDescriptor); + + // then + expect(errors(templates)).to.be.empty; + + expect(valid(templates)).to.have.length(templateDescriptor.length); + }); + + + it('should not accept missing group id', function() { + + // given + const templates = new Validator(); + + const templateDescriptor = require('./fixtures/error-groups-missing-id'); + + // when + templates.addAll(templateDescriptor); + + // then + expect(errors(templates)).to.contain('template(id: , name: ): missing id for group "0"'); + + expect(valid(templates)).to.be.empty; + }); + + }); + + }); + +}); diff --git a/test/spec/provider/cloud-element-templates/fixtures/connectors.json b/test/spec/provider/cloud-element-templates/fixtures/connectors.json new file mode 100644 index 000000000..5587ea430 --- /dev/null +++ b/test/spec/provider/cloud-element-templates/fixtures/connectors.json @@ -0,0 +1,189 @@ +[ + { + "$schema": "https://unpkg.com/@camunda/zeebe-element-templates-json-schema/resources/schema.json", + "name": "Email Connector", + "id": "io.camunda.connectors.EmailConnector-s2", + "description": "A Email sending task.", + "appliesTo": [ + "bpmn:ServiceTask" + ], + "properties": [ + { + "type": "Hidden", + "value": "send-email", + "binding": { + "type": "zeebe:taskDefinition:type" + } + }, + { + "label": "Hostname", + "description": "Specify the email server (SMTP) host name", + "type": "String", + "binding": { + "type": "zeebe:input", + "name": "HOST_NAME" + }, + "constraints": { + "notEmpty": true + } + }, + { + "label": "Port", + "description": "Specify the email server (SMTP) port (default=25)", + "type": "String", + "value": "= 25", + "binding": { + "type": "zeebe:input", + "name": "PORT" + }, + "constraints": { + "optional": true + } + }, + { + "label": "Username", + "description": "Specify the user name to authenticate with", + "type": "String", + "binding": { + "type": "zeebe:input", + "name": "USER_NAME" + }, + "constraints": { + "optional": true + } + }, + { + "label": "Password", + "description": "Specify the password to authenticate with", + "type": "String", + "binding": { + "type": "zeebe:input", + "name": "PASSWORD" + }, + "constraints": { + "optional": true + } + }, + { + "label": "Sender", + "description": "Enter the FROM field", + "type": "String", + "binding": { + "type": "zeebe:input", + "name": "sender" + }, + "constraints": { + "notEmpty": true + } + }, + { + "label": "Recipient", + "description": "Enter the TO field", + "type": "String", + "binding": { + "type": "zeebe:input", + "name": "recipient" + }, + "constraints": { + "notEmpty": true + } + }, + { + "label": "Subject", + "description": "Enter the mail subject", + "type": "String", + "binding": { + "type": "zeebe:input", + "name": "subject" + }, + "constraints": { + "notEmpty": true + } + }, + { + "label": "Body", + "description": "Enter the email message body", + "type": "Text", + "binding": { + "type": "zeebe:input", + "name": "message" + }, + "constraints": { + "notEmpty": true + } + } + ] + }, + { + "$schema": "https://unpkg.com/@camunda/zeebe-element-templates-json-schema/resources/schema.json", + "name": "REST Connector", + "id": "io.camunda.connectors.RestConnector-s1", + "description": "A REST API invocation task.", + "appliesTo": [ + "bpmn:ServiceTask" + ], + "properties": [ + { + "type": "Hidden", + "value": "http", + "binding": { + "type": "zeebe:taskDefinition:type" + } + }, + { + "label": "REST Endpoint URL", + "description": "Specify the url of the REST API to talk to.", + "type": "String", + "binding": { + "type": "zeebe:taskHeader", + "key": "url" + }, + "constraints": { + "notEmpty": true, + "pattern": { + "value": "^https?://.*", + "message": "Must be http(s) URL." + } + } + }, + { + "label": "REST Method", + "description": "Specify the HTTP method to use.", + "type": "Dropdown", + "value": "get", + "choices": [ + { "name": "GET", "value": "get" }, + { "name": "POST", "value": "post" }, + { "name": "PATCH", "value": "patch" }, + { "name": "DELETE", "value": "delete" } + ], + "binding": { + "type": "zeebe:taskHeader", + "key": "method" + } + }, + { + "label": "Request Body", + "description": "Data to send to the endpoint.", + "value": "", + "type": "String", + "optional": true, + "binding": { + "type": "zeebe:input", + "name": "body" + } + }, + { + "label": "Result Variable", + "description": "Name of variable to store the response data in.", + "value": "response", + "type": "String", + "optional": true, + "binding": { + "type": "zeebe:output", + "source": "= body" + } + } + ] + } +] \ No newline at end of file diff --git a/test/spec/provider/cloud-element-templates/fixtures/error-binding-missing.json b/test/spec/provider/cloud-element-templates/fixtures/error-binding-missing.json new file mode 100644 index 000000000..1cdce502e --- /dev/null +++ b/test/spec/provider/cloud-element-templates/fixtures/error-binding-missing.json @@ -0,0 +1,16 @@ +[ + { + "$schema": "https://unpkg.com/@camunda/zeebe-element-templates-json-schema/resources/schema.json", + "id": "invalid", + "name": "Invalid", + "appliesTo": [ + "bpmn:UserTask" + ], + "properties": [ + { + "type": "Hidden", + "value": "http" + } + ] + } +] \ No newline at end of file diff --git a/test/spec/provider/cloud-element-templates/fixtures/error-groups-missing-id.json b/test/spec/provider/cloud-element-templates/fixtures/error-groups-missing-id.json new file mode 100644 index 000000000..028d4b2c9 --- /dev/null +++ b/test/spec/provider/cloud-element-templates/fixtures/error-groups-missing-id.json @@ -0,0 +1,24 @@ +[ + { + "$schema": "https://unpkg.com/@camunda/zeebe-element-templates-json-schema/resources/schema.json", + "name": "Missing group id", + "id": "example.com.missingGroupId", + "appliesTo": [ + "bpmn:ServiceTask" + ], + "properties": [], + "groups": [ + { + "label": "Group one" + }, + { + "id": "two", + "label": "Group two" + }, + { + "id": "three", + "label": "Group three" + } + ] + } +] \ No newline at end of file diff --git a/test/spec/provider/cloud-element-templates/fixtures/error-id-duplicate.json b/test/spec/provider/cloud-element-templates/fixtures/error-id-duplicate.json new file mode 100644 index 000000000..42491d64c --- /dev/null +++ b/test/spec/provider/cloud-element-templates/fixtures/error-id-duplicate.json @@ -0,0 +1,20 @@ +[ + { + "$schema": "https://unpkg.com/@camunda/zeebe-element-templates-json-schema/resources/schema.json", + "name": "FOO 1", + "id": "foo", + "appliesTo": [ + "bpmn:UserTask" + ], + "properties": [] + }, + { + "$schema": "https://unpkg.com/@camunda/zeebe-element-templates-json-schema/resources/schema.json", + "name": "Foo 2", + "id": "foo", + "appliesTo": [ + "bpmn:UserTask" + ], + "properties": [] + } +] \ No newline at end of file diff --git a/test/spec/provider/cloud-element-templates/fixtures/error-id-missing.json b/test/spec/provider/cloud-element-templates/fixtures/error-id-missing.json new file mode 100644 index 000000000..7ea722383 --- /dev/null +++ b/test/spec/provider/cloud-element-templates/fixtures/error-id-missing.json @@ -0,0 +1,10 @@ +[ + { + "$schema": "https://unpkg.com/@camunda/zeebe-element-templates-json-schema/resources/schema.json", + "name": "Invalid", + "appliesTo": [ + "bpmn:UserTask" + ], + "properties": [] + } +] \ No newline at end of file diff --git a/test/spec/provider/cloud-element-templates/fixtures/error-id-version-duplicate.json b/test/spec/provider/cloud-element-templates/fixtures/error-id-version-duplicate.json new file mode 100644 index 000000000..fe28f317f --- /dev/null +++ b/test/spec/provider/cloud-element-templates/fixtures/error-id-version-duplicate.json @@ -0,0 +1,22 @@ +[ + { + "$schema": "https://unpkg.com/@camunda/zeebe-element-templates-json-schema/resources/schema.json", + "name": "FOO 1", + "id": "foo", + "version": 1, + "appliesTo": [ + "bpmn:UserTask" + ], + "properties": [] + }, + { + "$schema": "https://unpkg.com/@camunda/zeebe-element-templates-json-schema/resources/schema.json", + "name": "Foo 2", + "id": "foo", + "version": 1, + "appliesTo": [ + "bpmn:UserTask" + ], + "properties": [] + } +] \ No newline at end of file diff --git a/test/spec/provider/cloud-element-templates/fixtures/error-invalid-optional.json b/test/spec/provider/cloud-element-templates/fixtures/error-invalid-optional.json new file mode 100644 index 000000000..6e400f427 --- /dev/null +++ b/test/spec/provider/cloud-element-templates/fixtures/error-invalid-optional.json @@ -0,0 +1,20 @@ +[ + { + "$schema": "https://unpkg.com/@camunda/zeebe-element-templates-json-schema/resources/schema.json", + "name": "Invalid", + "id": "invalid", + "appliesTo": [ + "bpmn:ServiceTask" + ], + "properties": [ + { + "type": "String", + "optional": true, + "binding": { + "type": "zeebe:taskHeader", + "key": "header" + } + } + ] + } +] \ No newline at end of file diff --git a/test/spec/provider/cloud-element-templates/fixtures/error-name-missing.json b/test/spec/provider/cloud-element-templates/fixtures/error-name-missing.json new file mode 100644 index 000000000..f091e14eb --- /dev/null +++ b/test/spec/provider/cloud-element-templates/fixtures/error-name-missing.json @@ -0,0 +1,10 @@ +[ + { + "$schema": "https://unpkg.com/@camunda/zeebe-element-templates-json-schema/resources/schema.json", + "id": "invalid", + "appliesTo": [ + "bpmn:UserTask" + ], + "properties": [] + } +] \ No newline at end of file diff --git a/test/spec/provider/cloud-element-templates/fixtures/error-optional-not-empty.json b/test/spec/provider/cloud-element-templates/fixtures/error-optional-not-empty.json new file mode 100644 index 000000000..a969fb14a --- /dev/null +++ b/test/spec/provider/cloud-element-templates/fixtures/error-optional-not-empty.json @@ -0,0 +1,23 @@ +[ + { + "$schema": "https://unpkg.com/@camunda/zeebe-element-templates-json-schema/resources/schema.json", + "name": "Invalid", + "id": "invalid", + "appliesTo": [ + "bpmn:ServiceTask" + ], + "properties": [ + { + "type": "String", + "optional": true, + "binding": { + "type": "zeebe:input", + "name": "header" + }, + "constraints": { + "notEmpty": true + } + } + ] + } +] \ No newline at end of file diff --git a/test/spec/provider/cloud-element-templates/fixtures/groups.json b/test/spec/provider/cloud-element-templates/fixtures/groups.json new file mode 100644 index 000000000..0c09c1ce5 --- /dev/null +++ b/test/spec/provider/cloud-element-templates/fixtures/groups.json @@ -0,0 +1,70 @@ +[ + { + "$schema": "https://unpkg.com/@camunda/zeebe-element-templates-json-schema/resources/schema.json", + "name": "Grouping", + "id": "example.com.grouping", + "appliesTo": [ + "bpmn:ServiceTask" + ], + "properties": [ + { + "label": "input 1", + "type": "String", + "binding": { + "type": "zeebe:input", + "name": "input1" + } + }, + { + "label": "input 2", + "group": "one", + "type": "String", + "binding": { + "type": "zeebe:input", + "name": "input2" + } + }, + { + "label": "input 3", + "group": "one", + "type": "String", + "binding": { + "type": "zeebe:input", + "name": "input3" + } + }, + { + "label": "input 4", + "group": "two", + "type": "String", + "binding": { + "type": "zeebe:input", + "name": "input4" + } + }, + { + "label": "input 5", + "group": "three", + "type": "String", + "binding": { + "type": "zeebe:input", + "name": "input5" + } + } + ], + "groups": [ + { + "id": "one", + "label": "Group one" + }, + { + "id": "two", + "label": "Group two" + }, + { + "id": "three", + "label": "Group three" + } + ] + } +] \ No newline at end of file diff --git a/test/spec/provider/cloud-element-templates/fixtures/simple-defined-schema.json b/test/spec/provider/cloud-element-templates/fixtures/simple-defined-schema.json new file mode 100644 index 000000000..85042cb0f --- /dev/null +++ b/test/spec/provider/cloud-element-templates/fixtures/simple-defined-schema.json @@ -0,0 +1,9 @@ +[ + { + "$schema": "https://unpkg.com/@camunda/zeebe-element-templates-json-schema/resources/schema.json", + "id": "foo", + "name":"Foo", + "appliesTo": [ "bpmn:Task" ], + "properties": [] + } +] \ No newline at end of file diff --git a/test/spec/provider/cloud-element-templates/fixtures/simple-high-schema-version.json b/test/spec/provider/cloud-element-templates/fixtures/simple-high-schema-version.json new file mode 100644 index 000000000..0b07c362c --- /dev/null +++ b/test/spec/provider/cloud-element-templates/fixtures/simple-high-schema-version.json @@ -0,0 +1,49 @@ +[ + { + "$schema": "https://unpkg.com/@camunda/zeebe-element-templates-json-schema@99.99.99/resources/schema.json", + "id": "foo", + "name":"Foo", + "appliesTo": [ "bpmn:Task" ], + "properties": [] + }, + { + "$schema": "https://unpkg.com/@camunda/zeebe-element-templates-json-schema@99.99.99/resources/schema.json", + "id": "foo", + "name":"Foo 1", + "version": 1, + "isDefault": true, + "appliesTo": [ "bpmn:Task" ], + "properties": [] + }, + { + "$schema": "https://unpkg.com/@camunda/zeebe-element-templates-json-schema@99.99.99/resources/schema.json", + "id": "foo", + "name":"Foo 2", + "version": 2, + "appliesTo": [ "bpmn:Task" ], + "properties": [] + }, + { + "$schema": "https://unpkg.com/@camunda/zeebe-element-templates-json-schema@99.99.99/resources/schema.json", + "id": "bar", + "name":"Bar 1", + "version": 1, + "appliesTo": [ "bpmn:Task" ], + "properties": [] + }, + { + "$schema": "https://unpkg.com/@camunda/zeebe-element-templates-json-schema@99.99.99/resources/schema.json", + "id": "bar", + "name":"Bar 2", + "version": 2, + "appliesTo": [ "bpmn:Task" ], + "properties": [] + }, + { + "$schema": "https://unpkg.com/@camunda/zeebe-element-templates-json-schema@99.99.99/resources/schema.json", + "id": "baz", + "name":"Baz", + "appliesTo": [ "bpmn:Task" ], + "properties": [] + } +] diff --git a/test/spec/provider/cloud-element-templates/fixtures/simple-latest-schema-version.json b/test/spec/provider/cloud-element-templates/fixtures/simple-latest-schema-version.json new file mode 100644 index 000000000..aa9651060 --- /dev/null +++ b/test/spec/provider/cloud-element-templates/fixtures/simple-latest-schema-version.json @@ -0,0 +1,49 @@ +[ + { + "$schema": "https://unpkg.com/@camunda/zeebe-element-templates-json-schema/resources/schema.json", + "id": "foo", + "name":"Foo", + "appliesTo": [ "bpmn:Task" ], + "properties": [] + }, + { + "$schema": "https://unpkg.com/@camunda/zeebe-element-templates-json-schema/resources/schema.json", + "id": "foo", + "name":"Foo 1", + "version": 1, + "isDefault": true, + "appliesTo": [ "bpmn:Task" ], + "properties": [] + }, + { + "$schema": "https://unpkg.com/@camunda/zeebe-element-templates-json-schema/resources/schema.json", + "id": "foo", + "name":"Foo 2", + "version": 2, + "appliesTo": [ "bpmn:Task" ], + "properties": [] + }, + { + "$schema": "https://unpkg.com/@camunda/zeebe-element-templates-json-schema/resources/schema.json", + "id": "bar", + "name":"Bar 1", + "version": 1, + "appliesTo": [ "bpmn:Task" ], + "properties": [] + }, + { + "$schema": "https://unpkg.com/@camunda/zeebe-element-templates-json-schema/resources/schema.json", + "id": "bar", + "name":"Bar 2", + "version": 2, + "appliesTo": [ "bpmn:Task" ], + "properties": [] + }, + { + "$schema": "https://unpkg.com/@camunda/zeebe-element-templates-json-schema/resources/schema.json", + "id": "baz", + "name":"Baz", + "appliesTo": [ "bpmn:Task" ], + "properties": [] + } +] diff --git a/test/spec/provider/cloud-element-templates/fixtures/simple-low-schema-version.json b/test/spec/provider/cloud-element-templates/fixtures/simple-low-schema-version.json new file mode 100644 index 000000000..4967df219 --- /dev/null +++ b/test/spec/provider/cloud-element-templates/fixtures/simple-low-schema-version.json @@ -0,0 +1,49 @@ +[ + { + "$schema": "https://unpkg.com/@camunda/zeebe-element-templates-json-schema@0.0.1/resources/schema.json", + "id": "foo", + "name":"Foo", + "appliesTo": [ "bpmn:Task" ], + "properties": [] + }, + { + "$schema": "https://unpkg.com/@camunda/zeebe-element-templates-json-schema@0.0.1/resources/schema.json", + "id": "foo", + "name":"Foo 1", + "version": 1, + "isDefault": true, + "appliesTo": [ "bpmn:Task" ], + "properties": [] + }, + { + "$schema": "https://unpkg.com/@camunda/zeebe-element-templates-json-schema@0.0.1/resources/schema.json", + "id": "foo", + "name":"Foo 2", + "version": 2, + "appliesTo": [ "bpmn:Task" ], + "properties": [] + }, + { + "$schema": "https://unpkg.com/@camunda/zeebe-element-templates-json-schema@0.0.1/resources/schema.json", + "id": "bar", + "name":"Bar 1", + "version": 1, + "appliesTo": [ "bpmn:Task" ], + "properties": [] + }, + { + "$schema": "https://unpkg.com/@camunda/zeebe-element-templates-json-schema@0.0.1/resources/schema.json", + "id": "bar", + "name":"Bar 2", + "version": 2, + "appliesTo": [ "bpmn:Task" ], + "properties": [] + }, + { + "$schema": "https://unpkg.com/@camunda/zeebe-element-templates-json-schema@0.0.1/resources/schema.json", + "id": "baz", + "name":"Baz", + "appliesTo": [ "bpmn:Task" ], + "properties": [] + } +] diff --git a/test/spec/provider/cloud-element-templates/fixtures/simple-missing-schema.json b/test/spec/provider/cloud-element-templates/fixtures/simple-missing-schema.json new file mode 100644 index 000000000..2d68468c6 --- /dev/null +++ b/test/spec/provider/cloud-element-templates/fixtures/simple-missing-schema.json @@ -0,0 +1,8 @@ +[ + { + "id": "foo", + "name":"Foo", + "appliesTo": [ "bpmn:Task" ], + "properties": [] + } +] \ No newline at end of file diff --git a/test/spec/provider/cloud-element-templates/fixtures/simple-mixed-schema-version.json b/test/spec/provider/cloud-element-templates/fixtures/simple-mixed-schema-version.json new file mode 100644 index 000000000..21924aa99 --- /dev/null +++ b/test/spec/provider/cloud-element-templates/fixtures/simple-mixed-schema-version.json @@ -0,0 +1,49 @@ +[ + { + "$schema": "https://unpkg.com/@camunda/zeebe-element-templates-json-schema@0.0.1/resources/schema.json", + "id": "foo", + "name":"Foo", + "appliesTo": [ "bpmn:Task" ], + "properties": [] + }, + { + "$schema": "https://unpkg.com/@camunda/zeebe-element-templates-json-schema@0.0.1/resources/schema.json", + "id": "foo", + "name":"Foo 1", + "version": 1, + "isDefault": true, + "appliesTo": [ "bpmn:Task" ], + "properties": [] + }, + { + "$schema": "https://unpkg.com/@camunda/zeebe-element-templates-json-schema@0.0.1/resources/schema.json", + "id": "foo", + "name":"Foo 2", + "version": 2, + "appliesTo": [ "bpmn:Task" ], + "properties": [] + }, + { + "$schema": "https://unpkg.com/@camunda/zeebe-element-templates-json-schema@99.99.99/resources/schema.json", + "id": "bar", + "name":"Bar 1", + "version": 1, + "appliesTo": [ "bpmn:Task" ], + "properties": [] + }, + { + "$schema": "https://unpkg.com/@camunda/zeebe-element-templates-json-schema@99.99.99/resources/schema.json", + "id": "bar", + "name":"Bar 2", + "version": 2, + "appliesTo": [ "bpmn:Task" ], + "properties": [] + }, + { + "$schema": "https://unpkg.com/@camunda/zeebe-element-templates-json-schema@99.99.99/resources/schema.json", + "id": "baz", + "name":"Baz", + "appliesTo": [ "bpmn:Task" ], + "properties": [] + } +] diff --git a/test/spec/provider/cloud-element-templates/fixtures/simple-same-schema-version.json b/test/spec/provider/cloud-element-templates/fixtures/simple-same-schema-version.json new file mode 100644 index 000000000..fff403398 --- /dev/null +++ b/test/spec/provider/cloud-element-templates/fixtures/simple-same-schema-version.json @@ -0,0 +1,49 @@ +[ + { + "$schema": "", + "id": "foo", + "name":"Foo", + "appliesTo": [ "bpmn:Task" ], + "properties": [] + }, + { + "$schema": "", + "id": "foo", + "name":"Foo 1", + "version": 1, + "isDefault": true, + "appliesTo": [ "bpmn:Task" ], + "properties": [] + }, + { + "$schema": "", + "id": "foo", + "name":"Foo 2", + "version": 2, + "appliesTo": [ "bpmn:Task" ], + "properties": [] + }, + { + "$schema": "", + "id": "bar", + "name":"Bar 1", + "version": 1, + "appliesTo": [ "bpmn:Task" ], + "properties": [] + }, + { + "$schema": "", + "id": "bar", + "name":"Bar 2", + "version": 2, + "appliesTo": [ "bpmn:Task" ], + "properties": [] + }, + { + "$schema": "", + "id": "baz", + "name":"Baz", + "appliesTo": [ "bpmn:Task" ], + "properties": [] + } +] diff --git a/test/spec/provider/cloud-element-templates/fixtures/simple-wrong-schema.json b/test/spec/provider/cloud-element-templates/fixtures/simple-wrong-schema.json new file mode 100644 index 000000000..1acde3b11 --- /dev/null +++ b/test/spec/provider/cloud-element-templates/fixtures/simple-wrong-schema.json @@ -0,0 +1,9 @@ +[ + { + "$schema": "https://unpkg.com/@camunda/element-templates-json-schema/resources/schema.json", + "id": "foo", + "name":"Foo", + "appliesTo": [ "bpmn:Task" ], + "properties": [] + } +] \ No newline at end of file