Skip to main content
Version: Next

internal.PathTemplate

Home > @backstage/backend-openapi-utils > internal > PathTemplate

Validate a string against OpenAPI path template, https://spec.openapis.org/oas/v3.1.0#path-templating-matching.

Signature:

export type PathTemplate<Path extends string> = Path extends `${infer Prefix}{${infer PathName}}${infer Suffix}` ? `${Prefix}:${PathName}${PathTemplate<Suffix>}` : Path;

References: PathTemplate

Example

const path: PathTemplate<"/posts/{postId}/comments/{commentId}"> = "/posts/:postId/comments/:commentId";
const pathWithoutParams: PathTemplate<"/posts/comments"> = "/posts/comments";