Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: always allow schema string examples #1007

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading