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 Nov 1, 2024
1 parent 7c7c556 commit f7f6b49
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
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
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 packages/parser/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 f7f6b49

Please sign in to comment.