Skip to content
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
12 changes: 0 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 13 additions & 3 deletions packages/parser/src/ruleset/v2/functions/channelParameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,20 @@ export const channelParameters = createRulesetFunction<{ parameters: Record<stri
options: null,
},
(targetVal, _, ctx) => {
const path = ctx.path[ctx.path.length - 1] as string;
const results: IFunctionResult[] = [];

const parameters = parseUrlVariables(path);
// Channel address is the key under `channels`
const channelAddress = ctx.path[ctx.path.length - 1];

if (typeof channelAddress !== 'string' || channelAddress.trim().length === 0) {
results.push({
message: 'Channel address must be a non-empty string when "parameters" are provided.',
path: [...ctx.path],
});
return results;
}

const parameters = parseUrlVariables(channelAddress);
if (parameters.length === 0) return;

const missingParameters = getMissingProps(parameters, targetVal.parameters);
Expand All @@ -46,4 +56,4 @@ export const channelParameters = createRulesetFunction<{ parameters: Record<stri

return results;
},
);
);
10 changes: 5 additions & 5 deletions packages/parser/test/old-api/tag.spec.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { Tag } from '../../src/old-api/tag';
import * as tag from '../../src/old-api/tag';
import { assertDescriptionMixin, assertExtensionsMixin, assertExternalDocumentationMixin } from './mixins';

describe('Tag', function() {
const json = { name: 'test', description: 'Testing', externalDocs: { url: 'somewhere' }, 'x-test': 'testing' };

describe('name()', function() {
it('should return a string', function() {
const d = new Tag(json);
const d = new tag.Tag(json);
expect(d.name()).toEqual(json.name);
});
});

assertDescriptionMixin(Tag);
assertExtensionsMixin(Tag);
assertExternalDocumentationMixin(Tag);
assertDescriptionMixin(tag.Tag);
assertExtensionsMixin(tag.Tag);
assertExternalDocumentationMixin(tag.Tag);
});
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,26 @@ testRule('asyncapi2-channel-parameters', [
},
],
},

// NEW: address is empty but parameters exist
{
name: 'invalid when channel address is empty but parameters exist',
document: {
asyncapi: '2.0.0',
channels: {
'': {
parameters: {
userId: {},
},
},
},
},
errors: [
{
message: 'Channel address must be a non-empty string when "parameters" are provided.',
path: ['channels', ''],
severity: DiagnosticSeverity.Error,
},
],
},
]);