You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The generated swagger-ui-init.js does not have functions correctly replaced in the swagger options.
For example the previous version generated something like this:
// [...]varoptions={"swaggerDoc": {"openapi": "3.0.0","paths": {// [...]},"info": {// [...]},"tags": [],"servers": [],"components": {"schemas": {}}},"customOptions": {"operationsSorter": (a,b)=>a.get("id").localeCompare(b.get("id"))// Type of function is kept},"swaggerUrl": {}};// [...]
But the new version generates something like this:
// [...]letoptions={"swaggerDoc": {"openapi": "3.0.0","paths": {// [...]},"info": {// [...]},"tags": [],"servers": [],"components": {"schemas": {}}},"customOptions": {"operationsSorter": "(a, b) => a.get("id").localeCompare(b.get("id"))" // Almost the same, but has " before and after the function, which cause an Error}};// [...]
This leads to an empty page when trying to access the generated Swagger API Documention.
Open the Swagger API Documentation in Browser (URL is printed to console)
Inspect the Sources and look at api/swagger-ui-init.js
Expected behavior
Since Version 6 this module provides it's own implementations for the swagger HTML generation etc.
But the newly created lib/swagger-ui/helpers.ts, which basically contains some code from swagger-ui-expressindex.js, fails to correctly replace the function placeholder, because it misses the " before and after the placeholder in the RegExp.
This can be fixed by adding them back and then the built JSInitOptions will have functions as functions and not strings set.
When building JS InitOptions, functions get replaced by a placeholder.
When stringified quotes are added, so we need to replace the placeholder
including the quotes.
Fixes: nestjs#1962
Panzer1119
added a commit
to Panzer1119/nestjs-swagger
that referenced
this issue
Jul 8, 2022
When building JS InitOptions, functions get replaced by a placeholder.
JSON.stringify quotes strings, so we need to replace the placeholder
including the quotes.
Fixes: nestjs#1962
Is there an existing issue for this?
Current behavior
The generated
swagger-ui-init.js
does not have functions correctly replaced in the swagger options.For example the previous version generated something like this:
But the new version generates something like this:
This leads to an empty page when trying to access the generated Swagger API Documention.
Minimum reproduction code
https://github.com/Panzer1119/nestjs-swagger-build-jsinit-options
Steps to reproduce
npm i
npm start
api/swagger-ui-init.js
Expected behavior
Since Version 6 this module provides it's own implementations for the swagger HTML generation etc.
But the newly created
lib/swagger-ui/helpers.ts
, which basically contains some code from swagger-ui-expressindex.js
, fails to correctly replace the function placeholder, because it misses the"
before and after the placeholder in theRegExp
.This can be fixed by adding them back and then the built JSInitOptions will have functions as functions and not strings set.
Original Code (Line 21):
json = json.replace(new RegExp(functionPlaceholder, 'g'), () => fns.shift());
Fixed Code:
json = json.replace(new RegExp('"' + functionPlaceholder + '"', 'g'), () => fns.shift());
Package version
9.0.1
NestJS version
9.0.1
Node.js version
16.13.2
In which operating systems have you tested?
Other
No response
The text was updated successfully, but these errors were encountered: