diff --git a/.changeset/great-fans-warn.md b/.changeset/great-fans-warn.md new file mode 100644 index 0000000000..79b3bf57ef --- /dev/null +++ b/.changeset/great-fans-warn.md @@ -0,0 +1,5 @@ +--- +"@gitbook/react-openapi": patch +--- + +Match OpenAPI operation paths regardless of trailing slash diff --git a/packages/react-openapi/src/resolveOpenAPIOperation.ts b/packages/react-openapi/src/resolveOpenAPIOperation.ts index 488c8c362f..ebb7ab5f91 100644 --- a/packages/react-openapi/src/resolveOpenAPIOperation.ts +++ b/packages/react-openapi/src/resolveOpenAPIOperation.ts @@ -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; } /**