Skip to content

Commit

Permalink
fix: always allow schema string examples
Browse files Browse the repository at this point in the history
Co-authored-by: David Müller <[email protected]>
  • Loading branch information
timonback and sam0r040 committed Jun 7, 2024
1 parent f7feb39 commit 52400c3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/ruleset/v2/functions/schemaValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const schemaValidation = createRulesetFunction<SchemaFragment, { type: 'd
},
);

if (Array.isArray(result)) {
if (Array.isArray(result) && typeof relevantItem.value !== 'string') {
results.push(...result);
}
}
Expand Down
36 changes: 18 additions & 18 deletions test/ruleset/rules/v2/asyncapi2-schema-examples.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ testRule('asyncapi2-schema-examples', [
parameters: {
userId: {
schema: {
examples: [17, 'one', 13],
examples: [17, {}, 13, 'string-is-always-accepted'],
},
},
},
Expand All @@ -53,26 +53,26 @@ testRule('asyncapi2-schema-examples', [
parameters: {
orphanParameter: {
schema: {
examples: [17, 'one', 13],
examples: [17, {}, 13, 'string-is-always-accepted'],
},
},
},
schemas: {
aSchema: {
type: 'string',
examples: [17, 'one', 13],
type: 'object',
examples: [17, {}, 13, 'string-is-always-accepted'],
},
},
},
},
errors: [
{
message: '"0" property type must be string',
message: '"0" property type must be object',
path: ['components', 'schemas', 'aSchema', 'examples', '0'],
severity: DiagnosticSeverity.Error,
},
{
message: '"2" property type must be string',
message: '"2" property type must be object',
path: ['components', 'schemas', 'aSchema', 'examples', '2'],
severity: DiagnosticSeverity.Error,
},
Expand All @@ -88,7 +88,7 @@ testRule('asyncapi2-schema-examples', [
parameters: {
userId: {
schema: {
examples: [17, 'one', 13],
examples: [17, {}, 13, 'string-is-always-accepted'],
},
},
},
Expand All @@ -98,26 +98,26 @@ testRule('asyncapi2-schema-examples', [
parameters: {
orphanParameter: {
schema: {
type: 'string',
examples: [17, 'one', 13],
type: 'object',
examples: [17, {}, 13, 'string-is-always-accepted'],
},
},
},
schemas: {
aSchema: {
examples: [17, 'one', 13],
examples: [17, {}, 13, 'string-is-always-accepted'],
},
},
},
},
errors: [
{
message: '"0" property type must be string',
message: '"0" property type must be object',
path: ['components', 'parameters', 'orphanParameter', 'schema', 'examples', '0'],
severity: DiagnosticSeverity.Error,
},
{
message: '"2" property type must be string',
message: '"2" property type must be object',
path: ['components', 'parameters', 'orphanParameter', 'schema', 'examples', '2'],
severity: DiagnosticSeverity.Error,
},
Expand All @@ -133,8 +133,8 @@ testRule('asyncapi2-schema-examples', [
parameters: {
userId: {
schema: {
type: 'string',
examples: [17, 'one', 13],
type: 'object',
examples: [17, {}, 13, 'string-is-always-accepted'],
},
},
},
Expand All @@ -144,25 +144,25 @@ testRule('asyncapi2-schema-examples', [
parameters: {
orphanParameter: {
schema: {
examples: [17, 'one', 13],
examples: [17, {}, 13, 'string-is-always-accepted'],
},
},
},
schemas: {
aSchema: {
examples: [17, 'one', 13],
examples: [17, {}, 13, 'string-is-always-accepted'],
},
},
},
},
errors: [
{
message: '"0" property type must be string',
message: '"0" property type must be object',
path: ['channels', 'users/{userId}/signedUp', 'parameters', 'userId', 'schema', 'examples', '0'],
severity: DiagnosticSeverity.Error,
},
{
message: '"2" property type must be string',
message: '"2" property type must be object',
path: ['channels', 'users/{userId}/signedUp', 'parameters', 'userId', 'schema', 'examples', '2'],
severity: DiagnosticSeverity.Error,
},
Expand Down

0 comments on commit 52400c3

Please sign in to comment.