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: allow custom schema formats without validation error (#1066) #1085

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

shwetd19
Copy link

@shwetd19 shwetd19 commented Feb 8, 2025

Overview

This PR fixes a bug where the parser incorrectly throws an "Unknown schema format" error when encountering custom schema formats. According to the AsyncAPI specification, custom schema formats are allowed and their implementation is OPTIONAL.

Changes

  • Modified parseSchema function to accept any valid string as schema format
  • Changed validation to only check if format is a string type
  • Added passthrough handling for unknown formats instead of throwing error
  • Maintained existing parser behavior for supported formats

Implementation Details

export async function parseSchema(parser: Parser, input: ParseSchemaInput) {
  if (typeof input.schemaFormat !== 'string') {
    throw new Error('Schema format must be a string');
  }

  const schemaParser = parser.parserRegistry.get(input.schemaFormat);
  
  if (schemaParser === undefined) {
    return {
      parsed: input.schema,
      format: input.schemaFormat
    };
  }
  
  return schemaParser.parse(input);
}

Fixes #1066

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.
Copy link

changeset-bot bot commented Feb 8, 2025

⚠️ No Changeset found

Latest commit: cfb55fb

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

sonarqubecloud bot commented Feb 8, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Any non supported schema format should not make the doc invalid
1 participant