feat(docs): enhance Scalar renderer with custom script and font sourc… - #1107
Open
Orfeo42 wants to merge 2 commits into
Open
feat(docs): enhance Scalar renderer with custom script and font sourc…#1107Orfeo42 wants to merge 2 commits into
Orfeo42 wants to merge 2 commits into
Conversation
Collaborator
|
Hi @Orfeo42, thanks for your contribution. We specifically want to avoid registering renderer-specific docs variables (e.g. I've admittedly only skimmed through this code and haven't tested it locally, but could you walk through some of the design decisions please? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes: #1103
Summary
@scalar/api-reference@1.44.20to1.66.1with a fresh SRI hash, and addConfig.DocsScalar(ScalarDocsConfigwithScriptURL,ScriptIntegrity,FontSrc) to override the script location and font source without waiting for a huma release. Override values are validated at registration (rejecting;,,, quotes, whitespace,<,>) to prevent CSP and HTML injection.data-configurationattribute to theScalar.createApiReference('#app', {...})JS API, allowed via a CSPsha256hash of the static inline script. This makes the full Scalar configuration work throughDocsRendererConfig, including multi-documentsources; huma injects the defaulturlonly when the config declares none ofurl,sources, orcontent.'unsafe-eval'fromscript-src(verified unused by 1.66.1 in-browser) and addfont-srcforhttps://fonts.scalar.com(previously blocked by thedefault-src 'none'fallback, breaking font loading).style-src 'unsafe-inline'remains — Scalar applies inlinestyleattributes, which no nonce or hash can allow; tracked by the existing TODO.html.EscapeStringand precompute the CSP header once at registration inregisterDocsRoute(api.go).registerDocsRouteinto focused helpers:scalarScriptFor,scalarFontSrc,scalarConfigJSON,scalarCSP,scalarPage.TestDocsRendererswith coverage for custom script URL/integrity, font-src override, multi-document config, config-shape validation, CSP/comma injection rejection, and title escaping.Breaking Changes
DocsRendererConfigfor the Scalar renderer must now marshal to a JSON object; any other JSON shape panics at API creation (previously any JSON value was serialized intodata-configuration).<script id="api-reference" data-url=... data-configuration=...>element; anything scraping or post-processing that markup must adapt to the new<div id="app">+ inlineScalar.createApiReferencestructure.