Add dynamic route matching and validation improvements

Introduces dynamic route parameter support in route path computation and schema matching. Adds a utility for sending validation errors, updates schema definitions to support header validation, and refactors server middleware to handle header, body, and query validation with improved error handling. Also adds a placeholder user route and updates dependencies to include 'path-to-regexp'.
This commit is contained in:
2025-12-20 18:19:03 +01:00
parent 18efd445e5
commit 7e1eaf3f1f
8 changed files with 118 additions and 42 deletions

View File

@@ -28,20 +28,19 @@ function getRecursiveFiles(dir) {
function computeRoutePath(baseDir, filePath) {
const relativePath = path.relative(baseDir, filePath)
const normalizedPath = relativePath.replace(/\\/g, "/")
let route = "/" + relativePath.split(path.sep).join("/")
let route = "/" + normalizedPath
if (route.endsWith("index.js")) {
route = route.replace("index.js", "")
} else {
route = route.replace(".js", "")
if (route.endsWith(".js")) {
route = route.slice(0, -3)
}
if (route.endsWith("/index")) {
route = route.slice(0, -6)
}
route = route.replace(/\/{2,}/g, "/")
route = route.replace(/\[([^\]]+)\]/g, ":$1")
if (route.length > 1 && route.endsWith('/')) {
route = route.slice(0, -1)
if (route === "") {
return "/"
}
return route