Skip to content

Conversation

@KrishCodesw
Copy link

Description

This PR fixes a TypeError: Unknown encoding: base64url that occurs when the UI tries to generate a sample for a schema with contentEncoding: base64url.

The encodeBase64Url helper function was incorrectly passing the string "base64url" directly to Buffer.toString(), which is not a valid encoding and causes a crash.

This fix changes the function to:

Call the working encodeBase64 function first.

Manually replace the +, /, and = characters to correctly conform to the base64url specification.

Motivation and Context

This change is required to fix a bug that crashes the UI when trying to render a valid OpenAPI 3.1 schema.

Fixes #10613

How Has This Been Tested?

I manually tested this fix using the following steps:

Created a new spec file (dev-helpers/bug-spec.yml) with the schema provided in issue #10613.

Ran the development server using npm run dev.

Loaded the spec file in the browser at http://localhost:3200.

Opened the developer console and expanded the /authorize endpoint.

Confirmed the TypeError: Unknown encoding: base64url was thrown.

Applied the code fix to encodeBase64Url.js.

Hard-refreshed the browser.

Expanded the /authorize endpoint again and confirmed the error was gone and the UI rendered the parameters correctly.

Ran the unit test suite (npm test) and confirmed all existing tests pass.

Screenshots (if appropriate):

image

Checklist

My PR contains...

  • No code changes (src/ is unmodified: changes to documentation, CI, metadata, etc.)
  • Dependency changes (any modification to dependencies in package.json)
  • [x ] Bug fixes (non-breaking change which fixes an issue)
  • Improvements (misc. changes to existing features)
  • Features (non-breaking change which adds functionality)

My changes...

  • are breaking changes to a public API (config options, System API, major UI change, etc).
  • are breaking changes to a private API (Redux, component props, utility functions, etc.).
  • are breaking changes to a developer API (npm script behavior changes, new dev system dependencies, etc).
  • [x ] are not breaking changes.

Documentation

  • [x ] My changes do not require a change to the project documentation.
  • My changes require a change to the project documentation.
  • If yes to above: I have updated the documentation accordingly.

Automated tests

  • My changes can not or do not need to be tested.
  • [x ] My changes can and should be tested by unit and/or integration tests.
  • If yes to above: I have added tests to cover my changes.
  • If yes to above: I have taken care to cover edge cases in my tests.
  • [x ] All new and existing tests passed.

@KrishCodesw
Copy link
Author

Hey,any update on the PR ?

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.

OpenApi 3.1 contentEncoding: base64url not working

1 participant