Skip to content
Closed
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
27 changes: 27 additions & 0 deletions packages/parser/src/ruleset/functions/documentStructure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,25 @@ function getCopyOfSchema(version: AsyncAPIVersions): RawSchema {
return JSON.parse(JSON.stringify(specs.schemas[version])) as RawSchema;
}

/**
* Removes the `format` constraint from ReferenceObject schema definitions.
*
* The ajv-formats `uri-reference` format validator rejects valid URI references
* containing square brackets (`[`, `]`), which are legal per RFC 3986 and RFC 6901.
* This causes false validation failures for $refs pointing to components whose keys
* contain special characters (e.g. message names from messaging systems like JMS).
*/
function relaxRefFormat(schema: { definitions?: RawSchema }): void {
for (const key of Object.keys(schema.definitions || {})) {
if (key.endsWith('/ReferenceObject.json')) {
const refObjDef = (schema.definitions as Record<string, any>)[key];
if (refObjDef?.format) {
delete refObjDef.format;
}
}
}
}

const serializedSchemas = new Map<AsyncAPIVersions, RawSchema>();
function getSerializedSchema(version: AsyncAPIVersions, resolved: boolean): RawSchema {
const serializedSchemaKey = resolved ? `${version}-resolved` : `${version}-unresolved`;
Expand All @@ -105,6 +124,14 @@ function getSerializedSchema(version: AsyncAPIVersions, resolved: boolean): RawS
copied = prepareV3ResolvedSchema(copied, version);
}

// For unresolved schemas, relax the uri-reference format on $ref fields.
// The ajv-formats uri-reference validator incorrectly rejects valid URI
// references containing square brackets (e.g. message names with [, ]).
// See https://github.com/asyncapi/parser-js/issues/1132
if (!resolved) {
relaxRefFormat(copied);
}

serializedSchemas.set(serializedSchemaKey as AsyncAPIVersions, copied);
return copied;
}
Expand Down
Loading