Skip to content

Commit

Permalink
fix(rulesets): always allow string examples in asyncapi schema (#2625)
Browse files Browse the repository at this point in the history
Co-authored-by: David Müller <d4ve.mone@googlemail.com>
Co-authored-by: Nauman <mnaumanali94@gmail.com>
Co-authored-by: Jonas Lagoni <jonas-lt@live.dk>
  • Loading branch information
4 people authored Oct 4, 2024
1 parent dfe614b commit 4e2f797
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ function runPayloadValidation(targetVal: any, opts: { type: 'examples' | 'defaul
describe('asyncApi2SchemaValidation', () => {
test('validates examples', () => {
const payload = {
type: 'string',
examples: [17, 'one', 13],
type: 'object',
examples: [17, {}, 13, 'string-is-always-accepted'],
};

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

expect(results).toEqual([
{
message: '"0" property type must be string',
message: '"0" property type must be object',
path: ['examples', 0],
},
{
message: '"2" property type must be string',
message: '"2" property type must be object',
path: ['examples', 2],
},
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export default createRulesetFunction<SchemaFragment, Options>(
},
);

if (Array.isArray(result)) {
if (Array.isArray(result) && typeof relevantItem.value !== 'string') {
results.push(...result);
}
}
Expand Down

0 comments on commit 4e2f797

Please sign in to comment.