From cfb55fbba9baecc028bc80980f7934a02289c12d Mon Sep 17 00:00:00 2001 From: Shwetas Dhake Date: Sat, 8 Feb 2025 23:26:20 +0530 Subject: [PATCH] fix: allow custom schema formats without validation error The parser now accepts any string schema format as valid, aligning with the AsyncAPI spec which states custom formats are allowed with optional implementation. Unknown formats are passed through without modification instead of throwing an error. --- packages/parser/src/schema-parser/index.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/parser/src/schema-parser/index.ts b/packages/parser/src/schema-parser/index.ts index a40f944c0..4d5acf32c 100644 --- a/packages/parser/src/schema-parser/index.ts +++ b/packages/parser/src/schema-parser/index.ts @@ -46,10 +46,21 @@ export async function validateSchema(parser: Parser, input: ValidateSchemaInput) } export async function parseSchema(parser: Parser, input: ParseSchemaInput) { + // First validate that format is a string + if (typeof input.schemaFormat !== 'string') { + throw new Error('Schema format must be a string'); + } + const schemaParser = parser.parserRegistry.get(input.schemaFormat); + if (schemaParser === undefined) { - throw new Error('Unknown schema format'); + // Simply return the schema as-is for unknown formats + return { + parsed: input.data, // Assuming you meant to return input.data instead of input.schema + format: input.schemaFormat + }; } + return schemaParser.parse(input); }