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
1 change: 1 addition & 0 deletions packages/parser/src/custom-operations/parse-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const customSchemasPathsV3 = [
// operations
'$.operations.*.messages.*.payload',
'$.operations.*.messages.*.headers',
'$.operations.*.channel.messages.*.payload',
'$.components.operations.*.messages.*.payload',
'$.components.operations.*.messages.*.headers',
// messages
Expand Down
52 changes: 52 additions & 0 deletions packages/parser/test/custom-operations/parse-schema-v3.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { AsyncAPIDocumentV3 } from '../../src/models';
import { Parser } from '../../src/parser';
import { ValidateSchemaInput, ParseSchemaInput } from '../../src/schema-parser';

import type { v3 } from '../../src/spec-types';
import { SchemaValidateResult, AsyncAPISchema } from '../../src/types';

describe('custom operations for v3 - parse schemas', function() {
const parser = new Parser();
Expand Down Expand Up @@ -133,3 +135,53 @@ describe('custom operations for v3 - parse schemas', function() {
expect(diagnostics.length > 0).toEqual(true);
});
});

describe('custom parsers are executed for v3 - parse schemas', function() {
const parser = new Parser();
parser.registerSchemaParser({
getMimeTypes (): string[] {
return ['testFormat'];
},
validate (input: ValidateSchemaInput<unknown, unknown>): void | SchemaValidateResult[] | Promise<void | SchemaValidateResult[]> {
return [];
},
parse (input: ParseSchemaInput<unknown, unknown>): AsyncAPISchema | Promise<AsyncAPISchema> {
return {title: 'parsedFormat'};
}
});

it('should parse schemas only defined through an operations channel', async function () {
const documentRaw = {
asyncapi: '3.0.0',
info: {
title: 'Valid AsyncApi document',
version: '1.0'
},
operations: {
operation: {
action: 'receive',
channel: {
address: 'channel',
messages: {
message: {
payload: {
schemaFormat: 'testFormat',
schema: {
type: 'object'
}
}
}
}
},
}
},
};

const { document, diagnostics } = await parser.parse(documentRaw);

expect(document).toBeInstanceOf(AsyncAPIDocumentV3);
expect(diagnostics.length === 0).toEqual(true);

expect(((((document?.json() as any).operations?.operation as v3.OperationObject).channel as v3.ChannelObject)?.messages?.message as v3.MessageObject)?.payload?.schema).toEqual({ title: 'parsedFormat'});
});
});