Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: validate type of value #139

Merged
merged 2 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,38 @@
},
{
"$ref": "condition.json"
},
{
"if": {
"properties": {
"type": {
"not": {
"const": "Number"
}
}
},
"required": [
"type"
]
},
"then": {
"properties": {
"value": {
"type": [
"string",
"boolean"
]
}
}
}
}
],
"properties": {
"value": {
"$id": "#/properties/property/value",
"type": [
"string",
"number",
"boolean"
],
"description": "The value of a control field."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const errors = [
{
keyword: 'type',
dataPath: '/properties/0/value',
schemaPath: '#/allOf/0/items/properties/value/type',
schemaPath: '#/allOf/0/items/allOf/2/then/properties/value/type',
params: {
type: [
'string',
Expand All @@ -30,6 +30,15 @@ export const errors = [
},
message: 'should be string,boolean'
},
{
dataPath: '/properties/0',
keyword: 'if',
message: 'should match "then" schema',
params: {
failingKeyword: 'then'
},
schemaPath: '#/allOf/0/items/allOf/2/if'
},
{
dataPath: '',
keyword: 'type',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,25 @@
}
}
}
},
{
"if": {
"properties": {
"feel": {
"const": "required"
}
},
"required": [
"feel"
]
},
"then": {
"properties": {
"value": {
"type": "string"
}
}
}
}
],
"properties": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
export const template = {
name: 'Pattern Template',
id: 'com.example.PatternTemplate',
appliesTo: [
'bpmn:Task'
],
properties: [
{
type: 'Text',
binding: {
type: 'zeebe:property',
name: 'prop'
},
feel: 'required',
value: 'valid'
},
{
type: 'Boolean',
binding: {
type: 'zeebe:property',
name: 'prop'
},
feel: 'required',
value: true
},
{
type: 'Number',
binding: {
type: 'zeebe:property',
name: 'prop'
},
feel: 'required',
value: 123
},
]
};

export const errors = [
{
keyword: 'type',
dataPath: '/properties/1/value',
schemaPath: '#/allOf/1/items/allOf/9/then/properties/value/type',
params: { type: 'string' },
message: 'should be string'
},
{
keyword: 'if',
dataPath: '/properties/1',
schemaPath: '#/allOf/1/items/allOf/9/if',
params: { failingKeyword: 'then' },
message: 'should match "then" schema'
},
{
keyword: 'type',
dataPath: '/properties/2/value',
schemaPath: '#/allOf/1/items/allOf/9/then/properties/value/type',
params: { type: 'string' },
message: 'should be string'
},
{
keyword: 'if',
dataPath: '/properties/2',
schemaPath: '#/allOf/1/items/allOf/9/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'
}
];
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ export const template = {
'type': 'property',
'name': 'name'
}
},
{
'label': 'Am I awesome?',
'type': 'Number',
'value': 50,
'binding': {
'type': 'zeebe:property',
'name': 'customProp'
}
}
]
};
Expand All @@ -21,7 +30,7 @@ export const errors = [
{
keyword: 'type',
dataPath: '/properties/0/value',
schemaPath: '#/allOf/0/items/properties/value/type',
schemaPath: '#/allOf/0/items/allOf/2/then/properties/value/type',
params: {
type: [
'string',
Expand All @@ -30,6 +39,15 @@ export const errors = [
},
message: 'should be string,boolean'
},
{
dataPath: '/properties/0',
keyword: 'if',
message: 'should match "then" schema',
params: {
failingKeyword: 'then'
},
schemaPath: '#/allOf/0/items/allOf/2/if'
},
{
dataPath: '',
keyword: 'type',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ describe('validation', function() {
testTemplate('feel-type-mismatch');


testTemplate('feel-value-mismatch');


testTemplate('language');


Expand Down