Skip to content

Commit

Permalink
fix: always allow schema string examples (#1007)
Browse files Browse the repository at this point in the history
Co-authored-by: Jonas Lagoni <[email protected]>
  • Loading branch information
timonback and jonaslagoni authored Dec 4, 2024
1 parent ebf856e commit 8710f53
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'],
},
},
},
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 8710f53

Please sign in to comment.