Skip to content

Fix/upstream bugs - #1158

Closed
sroucheray wants to merge 16 commits into
rapi-doc:masterfrom
PerfectMemory:fix/upstream-bugs
Closed

sroucheray wants to merge 16 commits into
rapi-doc:masterfrom
PerfectMemory:fix/upstream-bugs

Conversation

@sroucheray

@sroucheray sroucheray commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A batch of small, independent bug fixes found while embedding RapiDoc in a host application (Angular wrapper, OAuth flows, themed UI). Each fix is its own commit, so they can be reviewed or cherry-picked one by one.

Fixes

Crashes

  • Search filter: clicking the ↩ icon next to "Filter" passed the icon <div> as the event target, so searchVal became undefined and the component search threw Cannot read properties of undefined (reading 'toLowerCase'). onSearchChange now reads the input (also in json-schema-viewer).
  • API key attributes during loading: setting api-key-name, api-key-location or api-key-value while the spec is loading threw Cannot read properties of undefined (reading 'find'), because resolvedSpec is only a placeholder without securitySchemes at that point. The update is now skipped until the spec is resolved.
  • Examples: standardizeExample no longer throws on a null example.

OAuth

  • oauth-receiver relays storage events with relayAuthParams.
  • A relative refreshUrl is resolved against the server URL.
  • The fake postMessage gets a valid target origin.

Markdown

  • Use the marked 18 heading renderer signature.
  • In-page #anchor links stay on the current page (a <base> tag is added), instead of navigating away.

Other

  • nav-accent-text-color is honored by the theme (the token was misspelled in json-schema-viewer).
  • rapidoc-mini registers the api-key scheme under securitySchemeId.
  • json-schema-viewer passes ProcessSpec arguments in the right positions.
  • The tab-content part is exported from api-request and api-response.

Cleanups (no behavior change)

  • Stop passing arguments that the callee ignores (generateExample, json-schema-viewer template).

Tests

Unit tests were added or extended for the markdown and schema utilities (tests/unit/markdown-utils.test.js, tests/unit/schema-utils.test.js).

npm run test:unit

The search and api-key fixes were checked by hand against an embedding host app; they have no automated test.

sroucheray and others added 16 commits October 9, 2026 17:54
setTheme read the misspelled `theme.navAccenttextColor` whenever
`navAccentTextColor` was set, so a custom value always resolved to undefined
(for both the dark and the light theme).
The storage listener called `this.receiveStorage`, which does not exist, so it
threw a TypeError on every storage event instead of relaying the OAuth data
to the parent window.
The api-key security scheme was pushed with an `apiKeyId` field while the
lookup just above matches on `securitySchemeId`. The entry was therefore never
found again and every api-key attribute change pushed a duplicate scheme.
The relative refreshUrl branch concatenated the server URL with the tokenUrl
(copy/paste of the tokenUrl branch), so when the server URL ends with a slash
the refresh URL silently became the token endpoint.
The element itself was passed as `targetOrigin`, which browsers reject with a
SyntaxError. Starting a new OAuth flow while a previous single-use message
listener was still active therefore threw before the authorization window was
opened. The fake message is sent to the current window and carries no data, so
'*' is safe.
…tions

ProcessSpec takes (attrApiKey, attrApiKeyLocation, attrApiKeyValue, serverUrl)
before (matchPaths, matchType, removeEndpointsWithBadgeLabelAs), but the viewer
passed the match-* attributes directly after sortEndpointsBy, so they landed in
the api-key parameters and the match parameters kept their defaults.
generateExample takes 8 parameters but the call passed 9: the extra `true`
shifted 'text' into includeGeneratedExample and put `true` in outputType. The
generated sample of an object-typed parameter was thus returned as an object
instead of JSON text, and `data-example="${example.exampleVal}"` rendered
"[object Object]" which the "Fill Example" button then wrote into the input.
Two heading renderers (read-mode endpoint descriptions and the info
description headings in the nav bar) still used the pre-v5
`heading(text, level, raw)` signature. marked 18 passes a single token
object, so `level` and `raw` were undefined and headings rendered as
`<hundefined ... id="...--undefined">`. Align them with the renderers already
updated in focused-endpoint-template and overview-template.
`typeof null === 'object'`, so a valid `example: null` (or a null entry in an
examples map) reached `ex.value` / `obj.value` and threw a TypeError, breaking
the rendering of the whole endpoint.
…onse

`exportparts` takes `inner:outer`; the entries read `tab-coontent:tab-content`
(typo), so no inner part matched and the documented `tab-content` part was
never re-exported to the rapi-doc host.
- downloadResource/viewResource/onApiKeyChange are called with an event
  argument they do not accept
- unsafeHTML() takes a single argument; the `{ USE_PROFILES }` options (a
  DOMPurify leftover) were silently ignored since sanitizeHTML already runs
- endpoint ordering by method compared indices as strings (via toString +
  localeCompare); compare them numerically

No behavior change.
…eme tokens

The viewer built its theme object with the misspelled key `navAccenttextColor`,
so setTheme never saw the configured nav-accent-text-color.
jsonSchemaViewerTemplate only takes `isMini`; the three extra arguments were
leftovers of the former endpoint template signature.
…<base> tag

When the host page has an HTML <base> tag, a bare `#section` link in a markdown
description resolves against the base URL, so clicking it navigates away from
the page instead of jumping to the section.

Markdown in-page anchors are now rendered as absolute URLs of the current page
(with an `anchor-link` class). The fix is applied to the global marked instance
and to the custom renderers (headings in the nav bar, read mode, focused mode),
which replace the global renderer when passed per call.

Covered by unit tests and by a browser test on a page with a <base> tag.
The icon click passed a div as event target, so searchVal became undefined and
the component search crashed on undefined.toLowerCase().

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…pec is loading

resolvedSpec is a placeholder without securitySchemes during loadSpec, so
attributeChangedCallback threw on securitySchemes.find.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@mrin9

mrin9 commented Oct 10, 2026 •

Copy link
Copy Markdown
Collaborator

Thanks for the contribution
We are moving away from attribute based styling (which is now considered anti-pattern) to pure css based styling. The next release will be in couple of days once we are completely remove the issues found in tests.
It will be a breaking change as RapiDoc's API will change.

I will hold onto this PR once v11 is released. Once thats done i will see what can be cherry picked. In case you spot any conflicts in your PR after v11 please feel free to resolve them as it will help me merge the changes faster

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mrin9

mrin9 commented Oct 12, 2026

Copy link
Copy Markdown
Collaborator

Thank you for the detailed fixes and test cases, Stéphane!

We have cherry-picked and integrated the 12 relevant bug fixes into our upcoming feature/theme (v11) branch:

OAuth fixes (storage listener, refreshUrl resolution, and postMessage targetOrigin)
Marked 18 heading renderer signatures
OpenAPI null example crash fix (standardizeExample) and test cases
In-page markdown anchor links with tags and test suite
Navbar search icon click fix and spec loading API-key race condition
The remaining 4 commits touching theme.js and json-schema-viewer were omitted as those legacy components have been superseded/removed in v11.

Closing this PR as these fixes are now incorporated in feature/theme."

@mrin9 mrin9 closed this Oct 12, 2026
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.

2 participants