Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions lib/swagger-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export class SwaggerModule {
httpAdapter.get(
normalizeRelPath(`${finalPath}/swagger-ui-init.js`),
(req, res) => {
res.type('application/javascript');
httpAdapter.type(res, 'application/javascript');
const document = getBuiltDocument();

if (swaggerOptions.patchDocumentOnRequest) {
Expand All @@ -162,14 +162,14 @@ export class SwaggerModule {
documentToSerialize,
swaggerOptions
);
return res.send(swaggerInitJsPerRequest);
return httpAdapter.send(res, swaggerInitJsPerRequest);
}

if (!swaggerUiInitJS) {
swaggerUiInitJS = buildSwaggerInitJS(document, swaggerOptions);
}

res.send(swaggerUiInitJS);
httpAdapter.send(res, swaggerUiInitJS);
}
);

Expand All @@ -183,7 +183,7 @@ export class SwaggerModule {
`${finalPath}/${urlLastSubdirectory}/swagger-ui-init.js`
),
(req, res) => {
res.type('application/javascript');
httpAdapter.type(res, 'application/javascript');
const document = getBuiltDocument();

if (swaggerOptions.patchDocumentOnRequest) {
Expand All @@ -196,14 +196,14 @@ export class SwaggerModule {
documentToSerialize,
swaggerOptions
);
return res.send(swaggerInitJsPerRequest);
return httpAdapter.send(res, swaggerInitJsPerRequest);
}

if (!swaggerUiInitJS) {
swaggerUiInitJS = buildSwaggerInitJS(document, swaggerOptions);
}

res.send(swaggerUiInitJS);
httpAdapter.send(res, swaggerUiInitJS);
}
);
} catch (err) {
Expand All @@ -214,13 +214,13 @@ export class SwaggerModule {
}

function serveSwaggerHtml(_: any, res: any) {
res.type('text/html');
httpAdapter.type(res, 'text/html');

if (!swaggerUiHtml) {
swaggerUiHtml = buildSwaggerHTML(baseUrlForSwaggerUI, swaggerOptions);
}

res.send(swaggerUiHtml);
httpAdapter.send(res, swaggerUiHtml);
}

httpAdapter.get(finalPath, serveSwaggerHtml);
Expand Down Expand Up @@ -251,21 +251,21 @@ export class SwaggerModule {
) {
if (serveOptions.serveJson) {
httpAdapter.get(normalizeRelPath(options.jsonDocumentUrl), (req, res) => {
res.type('application/json');
httpAdapter.type(res, 'application/json');
const document = getBuiltDocument();

const documentToSerialize = options.swaggerOptions
.patchDocumentOnRequest
? options.swaggerOptions.patchDocumentOnRequest(req, res, document)
: document;

res.send(JSON.stringify(documentToSerialize));
httpAdapter.send(res, JSON.stringify(documentToSerialize));
});
}

if (serveOptions.serveYaml) {
httpAdapter.get(normalizeRelPath(options.yamlDocumentUrl), (req, res) => {
res.type('text/yaml');
httpAdapter.type(res, 'text/yaml');
const document = getBuiltDocument();

const documentToSerialize = options.swaggerOptions
Expand All @@ -277,7 +277,7 @@ export class SwaggerModule {
skipInvalid: true,
noRefs: true
});
res.send(yamlDocument);
httpAdapter.send(res, yamlDocument);
});
}
}
Expand Down