Repository navigation
fix(swagger-ui): load the standalone preset when urls is set - #2241
Open
pedrorubinger wants to merge 1 commit into
Open
pedrorubinger wants to merge 1 commit into
pedrorubinger wants to merge 1 commit into
Conversation
Swagger UI only loads a definition from `urls` through the TopBar plugin, which ships in swagger-ui-standalone-preset.js. The middleware never loaded that script, so `urls` rendered "No API definition provided.". When `urls` is given, also load the standalone preset and default to `presets: [SwaggerUIBundle.presets.apis, SwaggerUIStandalonePreset]` and `layout: 'StandaloneLayout'`. User-provided `presets` and `layout` are kept. Also join the rendered asset tags so multiple scripts are not separated by a stray comma in the page. Fixes honojs#1480
🦋 Changeset detectedLatest commit: 52df529 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2241 +/- ##
==========================================
+ Coverage 92.69% 92.70% +0.01%
==========================================
Files 119 119
Lines 4365 4374 +9
Branches 1139 1145 +6
==========================================
+ Hits 4046 4055 +9
Misses 284 284
Partials 35 35
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Fixes #1480
Problem
Passing
urlstoswaggerUI()renders "No API definition provided." and never loads a definition.Swagger UI only loads a definition from
urlsin the TopBar plugin (itscomponentDidMountcallsloadSpec(urls[selectedIndex].url)). TopBar ships inswagger-ui-standalone-preset.js, which the middleware never loads, sourlsis parsed as config but nothing fetches it. Users can't work around it withpresets: ['SwaggerUIStandalonePreset']either, because that global is not on the page.Change
When
urlsis set:swagger-ui-standalone-preset.js(it respectsversionandbaseUrl)presets: [SwaggerUIBundle.presets.apis, SwaggerUIStandalonePreset]andlayout: 'StandaloneLayout'User-provided
presetsandlayoutare kept as is. Pages that only useurlrender exactly as before.This follows the approach @sor4chi described in the issue, except that it turns on automatically with
urlsinstead of behind a newenableStandaloneflag. Sinceurlsdoes not work without the preset, enabling it automatically does not change any working setup, and it avoids a new option. Happy to switch to an explicit flag if you prefer.It also joins the rendered asset tags. With two scripts, the array was stringified with a comma that showed up as text on the page. That removed two now-unused entries from
eslint-suppressions.json.Testing
urlsrendering test and added tests for user-providedpresets/layout, forurlnot loading the preset, and forremoteAssets({ standalonePreset: true }).?urls.primaryName=...deep links open the selected oneversion,baseUrl(unpkg), and specs served by@hono/zod-openapidoc()routesurlonly: unchanged, no extra scriptThe author should do the following, if applicable
pnpm changesetat the top of this repo and push the changeset