Skip to content

Commit

Permalink
fix(validator): validation error on empty postman groups (#65)
Browse files Browse the repository at this point in the history
fixes #64
  • Loading branch information
derevnjuk authored Dec 6, 2021
1 parent 51bb83f commit 146d303
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 21 deletions.
23 changes: 13 additions & 10 deletions packages/validator/src/schemas/postman/v2.0.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"else": {
"$ref": "#/definitions/item-group"
}
}
},
"minItems": 1
},
"event": {
"$ref": "#/definitions/event-list"
Expand Down Expand Up @@ -360,15 +361,17 @@
"type": "array",
"items": {
"title": "Items",
"anyOf": [
{
"$ref": "#/definitions/item"
},
{
"$ref": "#/definitions/item-group"
}
]
}
"if": {
"required": ["request"]
},
"then": {
"$ref": "#/definitions/item"
},
"else": {
"$ref": "#/definitions/item-group"
}
},
"minItems": 1
},
"event": {
"$ref": "#/definitions/event-list"
Expand Down
23 changes: 13 additions & 10 deletions packages/validator/src/schemas/postman/v2.1.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"else": {
"$ref": "#/definitions/item-group"
}
}
},
"minItems": 1
},
"event": {
"$ref": "#/definitions/event-list"
Expand Down Expand Up @@ -405,15 +406,17 @@
"type": "array",
"items": {
"title": "Items",
"anyOf": [
{
"$ref": "#/definitions/item"
},
{
"$ref": "#/definitions/item-group"
}
]
}
"if": {
"required": ["request"]
},
"then": {
"$ref": "#/definitions/item"
},
"else": {
"$ref": "#/definitions/item-group"
}
},
"minItems": 1
},
"event": {
"$ref": "#/definitions/event-list"
Expand Down
8 changes: 7 additions & 1 deletion packages/validator/tests/error-humanizer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ describe('ErrorHumanizer', () => {
patch: 0
}
},
item: [] as any,
item: [
{
request: {
url: 'https://example.com'
}
}
],
variable: []
});

Expand Down
59 changes: 59 additions & 0 deletions packages/validator/tests/postman.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,64 @@ describe('PostmanValidator', () => {

result.should.deep.eq(expected);
});

it('should return list of errors if no items', async () => {
const input: Postman.Document = {
info: {
name: 'Postman document',
schema:
'https://schema.getpostman.com/json/collection/v2.1.0/collection.json'
},
item: []
} as unknown as Postman.Document;

const expected: ErrorObject[] = [
{
instancePath: '/item',
schemaPath: '#/properties/item/minItems',
keyword: 'minItems',
params: {
limit: 1
},
message: 'must NOT have fewer than 1 items'
}
];

const result = await validator.verify(input);

result.should.deep.eq(expected);
});

it('should return a list of errors if no items in item-group', async () => {
const input: Postman.Document = {
info: {
name: 'Postman document',
schema:
'https://schema.getpostman.com/json/collection/v2.1.0/collection.json'
},
item: [
{
name: 'Folder',
item: []
}
]
} as unknown as Postman.Document;

const expected: ErrorObject[] = [
{
instancePath: '/item/0/item',
schemaPath: '#/properties/item/minItems',
keyword: 'minItems',
params: {
limit: 1
},
message: 'must NOT have fewer than 1 items'
}
];

const result = await validator.verify(input);

result.should.deep.eq(expected);
});
});
});

0 comments on commit 146d303

Please sign in to comment.