Skip to content

Commit

Permalink
feat(cloud): do not allow optional for notEmpty=true
Browse files Browse the repository at this point in the history
  • Loading branch information
Niklas Kiefer authored and merge-me[bot] committed Feb 14, 2022
1 parent 78e9a3f commit 085d043
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 0 deletions.
27 changes: 27 additions & 0 deletions resources/cloud.json
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,33 @@
}
}
}
},
{
"if": {
"properties": {
"optional": {
"const": true
}
},
"required": [
"optional"
]
},
"then": {
"properties": {
"constraints": {
"properties": {
"notEmpty": {
"const": false,
"errorMessage": "optional is not allowed for truthy \"notEmpty\" constraint"
}
},
"required": [
"notEmpty"
]
}
}
}
}
],
"properties": {
Expand Down
27 changes: 27 additions & 0 deletions src/defs/cloud-properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,33 @@
}
}
}
},
{
"if": {
"properties": {
"optional": {
"const": true
}
},
"required": [
"optional"
]
},
"then": {
"properties": {
"constraints": {
"properties": {
"notEmpty": {
"const": false,
"errorMessage": "optional is not allowed for truthy \"notEmpty\" constraint"
}
},
"required": [
"notEmpty"
]
}
}
}
}
],
"properties": {
Expand Down
97 changes: 97 additions & 0 deletions test/fixtures/cloud-optional-invalid-not-empty.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
export const template = {
'name': 'REST Connector',
'id': 'io.camunda.connectors.RestConnector-s1',
'description': 'A generic REST service.',
'appliesTo': [
'bpmn:ServiceTask'
],
'properties': [
{
'label': 'Request Body',
'type': 'String',
'optional': true,
'binding': {
'type': 'zeebe:input',
'name': 'body'
},
'constraints': {
'notEmpty': false
}
},
{
'label': 'Result Variable',
'type': 'String',
'optional': true,
'binding': {
'type': 'zeebe:input',
'name': 'key'
},
'constraints': {
'notEmpty': true
}
},
{
'label': 'foo',
'type': 'String',
'optional': true,
'binding': {
'type': 'zeebe:input',
'name': 'body'
}
},
{
'label': 'bar',
'type': 'String',
'optional': false,
'binding': {
'type': 'zeebe:input',
'name': 'body'
},
'constraints': {
'notEmpty': true
}
}
]
};

export const errors = [
{
keyword: 'errorMessage',
dataPath: '/properties/1/constraints/notEmpty',
schemaPath: '#/definitions/properties/allOf/1/items/allOf/3/then/properties/constraints/properties/notEmpty/errorMessage',
params: {
errors: [
{
keyword: 'const',
dataPath: '/properties/1/constraints/notEmpty',
schemaPath: '#/definitions/properties/allOf/1/items/allOf/3/then/properties/constraints/properties/notEmpty/const',
params: { allowedValue: false },
message: 'should be equal to constant',
emUsed: true
}
]
},
message: 'optional is not allowed for truthy "notEmpty" constraint'
},
{
keyword: 'if',
dataPath: '/properties/1',
schemaPath: '#/definitions/properties/allOf/1/items/allOf/3/if',
params: { failingKeyword: 'then' },
message: 'should match "then" schema'
},
{
keyword: 'type',
dataPath: '',
schemaPath: '#/oneOf/1/type',
params: { type: 'array' },
message: 'should be array'
},
{
keyword: 'oneOf',
dataPath: '',
schemaPath: '#/oneOf',
params: { passingSchemas: null },
message: 'should match exactly one schema in oneOf'
}
];
3 changes: 3 additions & 0 deletions test/spec/cloud.validationSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ describe('validation - cloud', function() {
testTemplate('cloud-optional-invalid-type');


testTemplate('cloud-optional-invalid-not-empty');


describe('property type - binding type', function() {

testTemplate('invalid-property-type');
Expand Down

0 comments on commit 085d043

Please sign in to comment.