A wrapper for the Whook HTTP Router to provide SwaggerUI for local dev
npm install @whook/swagger-ui[//]: # ( )
[//]: # (This file is automatically generated by a metapak)
[//]: # (module. Do not change it except between the)
[//]: # (content:start/end flags, your changes would)
[//]: # (be overridden.)
[//]: # ( )

[//]: # (::contents:start)
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:
``sh`
npm i @whook/swagger-ui
To use it, just wrap the HTTP router with this module and override its
registration with the Knifecycle instance inside the runProcess functionsrc/index.ts
(usually in ):
`diff
+ import { initHTTPRouter } from '@whook/whook';
+ import wrapHTTPRouterWithSwaggerUI from '@whook/swagger-ui';
// (...)
// It is important to do this in the runProcess function since it really
// make sense only when actually running the server
export async function runProcess(injectedNames = [], $ = new Knifecycle()) {
// (...)
+ // Add support for Swagger UI by wrapping and
+ // overriding the original HTTP Router
+ $.register(
+ wrapHTTPRouterWithSwaggerUI(initHTTPRouter),
+ );
return await runBaseProcess(injectedNames, $);
}
`
Declare this module types in your src/whook.d.ts type definitions:
`diff
+import {
+ type WhookSwaggerUIEnv,
+ type WhookSwaggerUIRouteConfig,
+ type WhookSwaggerUIConfig,
+} from '@whook/swagger-ui';
// ...
declare module 'application-services' {
export interface AppEnvVars
extends BaseAppEnvVars,
WhookBaseEnv,
// (...)
+ WhookGraphIQLEnv,
WhookSwaggerUIEnv {}
// (...)
export interface AppConfig
- extends WhookBaseConfigs {}
+ extends WhookBaseConfigs, WhookSwaggerUIConfig {}
}
// ...
declare module '@whook/whook' {
export interface WhookRouteConfig
extends WhookBaseRouteConfig,
+ WhookSwaggerUIRouteConfig,
WhookCORSRouteConfig {}
}
`
And add the SwaggerUI config (usually in src/config/common/config.js):
`diff
// ...
import { type AppConfig } from 'application-services';
const CONFIG: AppConfig = {
// ...
BASE_PATH: 'v4',
};
export default CONFIG;
``
[//]: # (::contents:end)