Skip to content

Commit 4e2f797

Browse files
timonbacksam0r040mnaumanali94jonaslagoni
authored
fix(rulesets): always allow string examples in asyncapi schema (#2625)
Co-authored-by: David Müller <[email protected]> Co-authored-by: Nauman <[email protected]> Co-authored-by: Jonas Lagoni <[email protected]>
1 parent dfe614b commit 4e2f797

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

packages/rulesets/src/asyncapi/functions/__tests__/asyncApi2SchemaValidation.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@ function runPayloadValidation(targetVal: any, opts: { type: 'examples' | 'defaul
77
describe('asyncApi2SchemaValidation', () => {
88
test('validates examples', () => {
99
const payload = {
10-
type: 'string',
11-
examples: [17, 'one', 13],
10+
type: 'object',
11+
examples: [17, {}, 13, 'string-is-always-accepted'],
1212
};
1313

1414
const results = runPayloadValidation(payload, { type: 'examples' });
1515

1616
expect(results).toEqual([
1717
{
18-
message: '"0" property type must be string',
18+
message: '"0" property type must be object',
1919
path: ['examples', 0],
2020
},
2121
{
22-
message: '"2" property type must be string',
22+
message: '"2" property type must be object',
2323
path: ['examples', 2],
2424
},
2525
]);

packages/rulesets/src/asyncapi/functions/asyncApi2SchemaValidation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export default createRulesetFunction<SchemaFragment, Options>(
6767
},
6868
);
6969

70-
if (Array.isArray(result)) {
70+
if (Array.isArray(result) && typeof relevantItem.value !== 'string') {
7171
results.push(...result);
7272
}
7373
}

0 commit comments

Comments
 (0)