A wrapper for the Whook HTTP Router to provide SwaggerUI for local dev

Usage no npm install needed!

<script type="module">
  import whookSwaggerUi from 'https://cdn.skypack.dev/@whook/swagger-ui';



A wrapper for the Whook HTTP Router to provide SwaggerUI for local dev

GitHub license NPM version

This module provides the GraphIQL UI to your local Whook server !


The DEV_MODE=1 environment variable must be used when starting your server (npm run dev does it by default).


Install the module:

npm i @whook/swagger-ui

To use it, just wrap the HTTP router with this module and register it again with the Knifecycle instance inside the runServer function (usually in src/index.ts):

+ import initHTTPRouter from '@whook/http-router';
+ import wrapHTTPRouterWithSwaggerUI from '@whook/swagger-ui';

// (...)

// It is important to do this in the runServer function since it really
//  make sense only when actually running the server
export async function runServer(injectedNames = [], $ = new Knifecycle()) {

  // (...)

+   // Add support for Swagger UI by wrapping and
+  //  overriding the original HTTP Router
+   $.register(
+     wrapHTTPRouterWithSwaggerUI(initHTTPRouter),
+   );

  return await runBaseServer(injectedNames, $);

And add the SwaggerUI config (usually in src/config/common/config.js):

+ import type {
+   WhookAPIOperationSwaggerConfig,
+   WhookSwaggerUIConfig,
+ } from '@whook/swagger-ui';

// ...

export type AppConfigs = WhookConfigs &
  CORSConfig &
+  WhookSwaggerUIConfig &

const CONFIG: AppConfigs = {
  // ...

// Export custom handlers definitions
export type APIHandlerDefinition = WhookAPIHandlerDefinition<
  WhookAPIOperationCORSConfig &
+  WhookAPIOperationSwaggerConfig

export default CONFIG;


wrapHTTPRouterWithSwaggerUI(initHTTPRouter) ⇒ function

Wraps the httpRouter initializer to also serve the Swagger/OpenAPI UI for development purpose.

Kind: global function
Returns: function - The httpRouter initializer wrapped

Param Type Description
initHTTPRouter function The httpRouter initializer