Skip to content

Commit

Permalink
feat(): routing platform independence (PR comments resolution)
Browse files Browse the repository at this point in the history
  • Loading branch information
flamewow committed Apr 15, 2022
1 parent 92e85c9 commit a893977
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 19 deletions.
7 changes: 6 additions & 1 deletion e2e/manual-e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ async function bootstrap() {
customSiteTitle: 'Demo API - Swagger UI 1',
swaggerOptions: {
persistAuthorization: true,
defaultModelsExpandDepth: -1
defaultModelsExpandDepth: -1,
syntaxHighlight: {
activate: true,
theme: 'tomorrow-night'
},
tryItOutEnabled: true
},
customfavIcon: '/public/favicon.ico',
customCssUrl: '/public/theme.css', // to showcase that in new implementation u can use custom css with fastify
Expand Down
4 changes: 2 additions & 2 deletions lib/backward-compatilibity-layer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
FastifySwaggerCustomOptions,
SwaggerCustomOptions,
SwaggerCustomOptionsLegacy
LegacySwaggerCustomOptions
} from './interfaces';
import { HttpServer } from '@nestjs/common/interfaces/http/http-server.interface';

Expand All @@ -21,7 +21,7 @@ export interface ProcessSwaggerOptionsOutput {
}

export function processSwaggerOptions(
options: SwaggerCustomOptionsLegacy = {}
options: LegacySwaggerCustomOptions = {}
): ProcessSwaggerOptionsOutput {
const unifiedOptions: SwaggerCustomOptions = options;
const fastifyOptions: FastifySwaggerCustomOptions = options;
Expand Down
2 changes: 1 addition & 1 deletion lib/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { OpenAPIObject } from './open-api-spec.interface';
export * from './swagger-custom-options.interface';
export * from './swagger-document-options.interface';
export * from './swagger-custom-options-legacy.instace';
export * from './legacy-swagger-custom-options.interfaces';
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
interface _CommonSwaggerCustomOptions {
interface LegacyCommonSwaggerCustomOptions {
useGlobalPrefix?: boolean;
}

/**
* @deprecated use SwaggerCustomOptions interface
*/
export interface ExpressSwaggerCustomOptions
extends _CommonSwaggerCustomOptions {
extends LegacyCommonSwaggerCustomOptions {
explorer?: boolean;
swaggerOptions?: Record<string, any>;
customCss?: string;
Expand All @@ -17,11 +20,11 @@ export interface ExpressSwaggerCustomOptions
urls?: Record<'url' | 'name', string>[];
}

/*
* @deprecated
/**
* @deprecated use SwaggerCustomOptions interface
*/
export interface FastifySwaggerCustomOptions
extends _CommonSwaggerCustomOptions {
extends LegacyCommonSwaggerCustomOptions {
uiConfig?: Partial<{
deepLinking: boolean;
displayOperationId: boolean;
Expand Down Expand Up @@ -58,10 +61,12 @@ export interface FastifySwaggerCustomOptions
};
}

/*
* TODO: remove entire file when FastifySwaggerCustomOptions backward compatibility layer is no longer needed
* and use SwaggerCustomOptions in SwaggerModule.setup
// TODO: remove entire file when FastifySwaggerCustomOptions backward compatibility layer is no longer needed
// and use SwaggerCustomOptions in SwaggerModule.setup

/**
* @deprecated use SwaggerCustomOptions interface
*/
export type SwaggerCustomOptionsLegacy =
export type LegacySwaggerCustomOptions =
| FastifySwaggerCustomOptions
| ExpressSwaggerCustomOptions;
8 changes: 4 additions & 4 deletions lib/swagger-module.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { INestApplication } from '@nestjs/common';
import {
OpenAPIObject,
SwaggerCustomOptionsLegacy,
LegacySwaggerCustomOptions,
SwaggerDocumentOptions
} from './interfaces';
import { SwaggerScanner } from './swagger-scanner';
Expand Down Expand Up @@ -101,7 +101,7 @@ export class SwaggerModule {
path: string,
app: INestApplication,
document: OpenAPIObject,
options?: SwaggerCustomOptionsLegacy
options?: LegacySwaggerCustomOptions
) {
const globalPrefix = getGlobalPrefix(app);
const finalPath = validatePath(
Expand All @@ -122,9 +122,9 @@ export class SwaggerModule {
const httpAdapter = app.getHttpAdapter();

// START: fastify backward compatibility layer
const IS_FASTIFY = httpAdapter && httpAdapter.getType() === 'fastify';
const isFastify = httpAdapter && httpAdapter.getType() === 'fastify';

if (IS_FASTIFY) {
if (isFastify) {
serveDocumentsFastify(
finalPath,
httpAdapter,
Expand Down
1 change: 0 additions & 1 deletion lib/swagger-ui/swagger-ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export function buildSwaggerInitJS(
* Stores absolute path to swagger-ui assets
*/
export const swaggerAssetsAbsoluteFSPath = swaggerUi.getAbsoluteFSPath();
console.log(swaggerAssetsAbsoluteFSPath);
/**
* Used to build swagger-ui custom html
*/
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"test:e2e": "jest --config e2e/jest-e2e.json",
"prerelease": "npm run build",
"release": "release-it",
"---execution---": "",
"---manual-tests---": "",
"start": "nest start",
"start:dev": "nest start --watch",
"start:debug": "nest start --watch --debug"
Expand Down

0 comments on commit a893977

Please sign in to comment.