express-openapi-validator
Advanced tools
Comparing version 0.21.2 to 0.30.0
@@ -83,2 +83,3 @@ "use strict"; | ||
const path = u.substring(pathIdx); | ||
// ensure a trailing slash is always present | ||
return path[path.length - 1] === '/' ? path : path + '/'; | ||
@@ -85,0 +86,0 @@ } |
@@ -0,4 +1,10 @@ | ||
import { Application } from 'express'; | ||
export interface OpenApiValidatorOpts { | ||
apiSpecPath: string; | ||
} | ||
export declare function OpenApiValidator(options: OpenApiValidatorOpts): void; | ||
export declare class OpenApiValidator { | ||
private opts; | ||
private context; | ||
constructor(options: OpenApiValidatorOpts); | ||
install(app: Application): void; | ||
} |
@@ -8,37 +8,39 @@ "use strict"; | ||
const loggingKey = 'express-openapi-validator'; | ||
function OpenApiValidator(options) { | ||
if (!options.apiSpecPath) | ||
throw ono_1.default('apiSpecPath required'); | ||
const openApiContext = new openapi_context_1.OpenApiContext({ apiDoc: options.apiSpecPath }); | ||
const opts = { | ||
enableObjectCoercion: true, | ||
apiDoc: openApiContext.apiDoc, | ||
}; | ||
this.opts = opts; | ||
this.context = openApiContext; | ||
} | ||
exports.OpenApiValidator = OpenApiValidator; | ||
OpenApiValidator.prototype.install = function (app) { | ||
const pathParams = []; | ||
for (const route of this.context.routes) { | ||
if (route.pathParams.length > 0) { | ||
pathParams.push(...route.pathParams); | ||
} | ||
class OpenApiValidator { | ||
constructor(options) { | ||
if (!options.apiSpecPath) | ||
throw ono_1.default('apiSpecPath required'); | ||
const openApiContext = new openapi_context_1.OpenApiContext({ apiDoc: options.apiSpecPath }); | ||
const opts = { | ||
enableObjectCoercion: true, | ||
apiDoc: openApiContext.apiDoc, | ||
}; | ||
this.opts = opts; | ||
this.context = openApiContext; | ||
} | ||
// install param on routes with paths | ||
for (const p of _.uniq(pathParams)) { | ||
app.param(p, (req, res, next, value, name) => { | ||
if (req.openapi.pathParams) { | ||
// override path params | ||
req.params[name] = req.openapi.pathParams[name] || req.params[name]; | ||
install(app) { | ||
const pathParams = []; | ||
for (const route of this.context.routes) { | ||
if (route.pathParams.length > 0) { | ||
pathParams.push(...route.pathParams); | ||
} | ||
next(); | ||
}); | ||
} | ||
// install param on routes with paths | ||
for (const p of _.uniq(pathParams)) { | ||
app.param(p, (req, res, next, value, name) => { | ||
if (req.openapi.pathParams) { | ||
// override path params | ||
req.params[name] = req.openapi.pathParams[name] || req.params[name]; | ||
} | ||
next(); | ||
}); | ||
} | ||
app.use(middlewares.applyOpenApiMetadata(this.context), middlewares.validateRequest({ | ||
apiDoc: this.context.apiDoc, | ||
loggingKey, | ||
enableObjectCoercion: this.opts.enableObjectCoercion, | ||
})); | ||
} | ||
app.use(middlewares.applyOpenApiMetadata(this.context), middlewares.validateRequest({ | ||
apiDoc: this.context.apiDoc, | ||
loggingKey, | ||
enableObjectCoercion: this.opts.enableObjectCoercion, | ||
})); | ||
}; | ||
} | ||
exports.OpenApiValidator = OpenApiValidator; | ||
//# sourceMappingURL=index.js.map |
@@ -45,3 +45,2 @@ "use strict"; | ||
const openApiRoute = `${bp}${path}`; | ||
console.log('----', openApiRoute); | ||
const expressRoute = `${openApiRoute}` | ||
@@ -51,3 +50,2 @@ .split('/') | ||
.join('/'); | ||
console.log('----', openApiRoute, expressRoute); | ||
routes.push({ | ||
@@ -54,0 +52,0 @@ expressRoute, |
{ | ||
"name": "express-openapi-validator", | ||
"version": "0.21.2", | ||
"version": "0.30.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
38687
798