Extract the literal path keys from a document type, or the broad
string fallback when the document is untyped at compile time.
For OpenAPI 3.1 documents the union includes keys from webhooks
alongside paths, because <ApiOperation> / <ApiRequestBody> /
<ApiResponse> resolve webhook names through the same code path as
paths (see lookupPathItem in openapi/resolve.ts). Without the
webhook keys, a typed as const 3.1 document that declares only
webhooks would reject every path prop value at compile time
("Type 'string' is not assignable to type 'never'") despite working
at runtime.
When the document declares neither a paths nor a webhooks map
the union falls back to string so untyped/foreign inputs keep
working — the constraint is informational, not gating.
The string extends keyof P guard distinguishes a typed as const
document (whose paths map has literal keys) from a runtime
Record<string, unknown> document (whose keyof collapses to
string). For the runtime case we surface string so callers pass
arbitrary path values without losing the existing freedom.
Extract the literal path keys from a document type, or the broad
stringfallback when the document is untyped at compile time.For OpenAPI 3.1 documents the union includes keys from
webhooksalongsidepaths, because<ApiOperation>/<ApiRequestBody>/<ApiResponse>resolve webhook names through the same code path as paths (seelookupPathIteminopenapi/resolve.ts). Without the webhook keys, a typedas const3.1 document that declares only webhooks would reject everypathprop value at compile time ("Type 'string' is not assignable to type 'never'") despite working at runtime.When the document declares neither a
pathsnor awebhooksmap the union falls back tostringso untyped/foreign inputs keep working — the constraint is informational, not gating.The
string extends keyof Pguard distinguishes a typedas constdocument (whosepathsmap has literal keys) from a runtimeRecord<string, unknown>document (whosekeyofcollapses tostring). For the runtime case we surfacestringso callers pass arbitrary path values without losing the existing freedom.