Match OpenAPI operation paths regardless of trailing slash (#4282)

This commit is contained in:
Nolann B.
2026-05-29 12:16:24 +02:00
committed by GitHub
parent 2885a137f8
commit f158064817
2 changed files with 12 additions and 1 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@gitbook/react-openapi": patch
---
Match OpenAPI operation paths regardless of trailing slash
@@ -101,7 +101,13 @@ function getPathObject(
schema: OpenAPIV3.Document | OpenAPIV3_1.Document,
path: string
): OpenAPIV3.PathItemObject | OpenAPIV3_1.PathItemObject | null {
return schema.paths?.[path] || null;
const paths = schema.paths;
if (!paths) {
return null;
}
// Match regardless of a trailing slash, which specs may or may not include
const alternatePath = path.endsWith('/') ? path.slice(0, -1) : `${path}/`;
return paths[path] ?? paths[alternatePath] ?? null;
}
/**