Skip to content

Commit

Permalink
fix: always allow schema string examples
Browse files Browse the repository at this point in the history
  • Loading branch information
timonback committed May 25, 2024
1 parent 05b782b commit 5cf00d7
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'],

Check failure on line 91 in test/ruleset/rules/v2/asyncapi2-schema-examples.spec.ts

View workflow job for this annotation

GitHub Actions / Test NodeJS PR - ubuntu-latest

Expected indentation of 16 spaces but found 15
},
},
},
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 5cf00d7

Please sign in to comment.