Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolved dependency path-to-regexp with latest version #975

Closed
wants to merge 10 commits into from
2 changes: 1 addition & 1 deletion examples/3-eov-operations/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const app = express();
const apiSpec = path.join(__dirname, 'api.yaml');

// 1. Install bodyParsers for the request types your API will support
app.use(bodyParsers.urlencoded({ extended: false }));
app.use(express.urlencoded({ extended: false }));
app.use(express.text());
app.use(express.json());

Expand Down
11 changes: 7 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"media-typer": "^1.1.0",
"multer": "^1.4.5-lts.1",
"ono": "^7.1.3",
"path-to-regexp": "^6.3.0"
"path-to-regexp": "^8.1.0"
},
"devDependencies": {
"@types/cookie-parser": "^1.4.2",
Expand Down
5 changes: 3 additions & 2 deletions src/framework/base.path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class BasePath {
}
if (/{\w+}/.test(urlPath)) {
// has variable that we need to check out
urlPath = urlPath.replace(/{(\w+)}/g, (substring, p1) => `:${p1}(.*)`);
urlPath = urlPath.replace(/{(\w+)}/g, (substring, p1) => `:"${p1}"`);
}
this.expressPath = urlPath;
for (const variable in server.variables) {
Expand Down Expand Up @@ -69,7 +69,8 @@ export class BasePath {
}, []);

const allParamCombos = cartesian(...allParams);
const toPath = compile(this.expressPath);
const filteredExpressPath = this.expressPath.replace(/[(]/g, '\\\\(').replace(/[)]/g, '\\\\)');
const toPath = compile(filteredExpressPath);
const paths = new Set<string>();
for (const combo of allParamCombos) {
paths.add(toPath(combo));
Expand Down
4 changes: 3 additions & 1 deletion src/framework/openapi.spec.loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ export class OpenApiSpecLoader {
// substitute wildcard path with express equivalent
// {/path} => /path(*) <--- RFC 6570 format (not supported by openapi)
// const pass1 = part.replace(/\{(\/)([^\*]+)(\*)}/g, '$1:$2$3');

if(/[*]/g.test(part)){
return part.replace(/\/{([^}]+)}\({0,1}(\*)\){0,1}/g, '/$2$1').replace(/\{([^\/}]+)}/g, ':$1');
}
// instead create our own syntax that is compatible with express' pathToRegex
// /{path}* => /:path*)
// /{path}(*) => /:path*)
Expand Down
5 changes: 2 additions & 3 deletions src/middlewares/openapi.metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,14 @@ export function applyOpenApiMetadata(
const pathKey = openApiRoute.substring((<any>methods).basePath.length);
const schema = openApiContext.apiDoc.paths[pathKey][method.toLowerCase()];
const _schema = responseApiDoc?.paths[pathKey][method.toLowerCase()];

const keys = [];

const strict = !!req.app.enabled('strict routing');
const sensitive = !!req.app.enabled('case sensitive routing');
const pathOpts = {
sensitive,
strict,
};
const regexp = pathToRegexp(expressRoute, keys, pathOpts);
const {regexp, keys} = pathToRegexp(expressRoute, pathOpts);
const matchedRoute = regexp.exec(path);

if (matchedRoute) {
Expand Down
Loading