Skip to main content
Version: Next

internal.TemplateToDocPath

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

Extract path as specified in OpenAPI Doc based on request path

Signature:

export type TemplateToDocPath<Doc extends PathDoc, Path extends DocPathTemplate<Doc>> = ValueOf<{
[Template in DocPath<Doc>]: Path extends PathTemplate<Template> ? Template : never;
}>;

References: PathDoc, DocPathTemplate, ValueOf, DocPath, PathTemplate

Example

const spec = {
paths: {
"/posts/{postId}/comments/{commentId}": {},
"/posts/comments": {},
}
};
const specPathWithParams: DocPath<typeof spec, "/posts/:postId/comments/:commentId"> = "/posts/{postId}/comments/{commentId}";
const specPathWithoutParams: DocPath<typeof spec, "/posts/comments"> = "/posts/comments";