Skip to content

Commit bfc0079

Browse files
louis-preclaude
andcommitted
Throw if documented endpoints reference undocumented resources
Fail at build time when a documented endpoint's response references an undocumented resource type. This prevents generating broken links to pages that don't exist. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent de677e1 commit bfc0079

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

src/lib/blueprint.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,11 @@ export const createBlueprint = async (
510510
actionAttempts,
511511
})
512512

513+
assertDocumentedEndpointsDontReferenceUndocumentedResources({
514+
routes,
515+
resources,
516+
})
517+
513518
return {
514519
title: openapi.info.title,
515520
routes,
@@ -577,6 +582,38 @@ const assertSeamPathsAreUndocumented = ({
577582
}
578583
}
579584

585+
const assertDocumentedEndpointsDontReferenceUndocumentedResources = ({
586+
routes,
587+
resources,
588+
}: Pick<Blueprint, 'routes' | 'resources'>): void => {
589+
const undocumentedResourceTypes = new Set(
590+
resources.filter((r) => r.isUndocumented).map((r) => r.resourceType),
591+
)
592+
593+
const offenders: string[] = []
594+
595+
for (const route of routes) {
596+
for (const endpoint of route.endpoints) {
597+
if (endpoint.isUndocumented) continue
598+
if (endpoint.response.responseType === 'void') continue
599+
if (!('resourceType' in endpoint.response)) continue
600+
601+
const { resourceType } = endpoint.response
602+
if (undocumentedResourceTypes.has(resourceType)) {
603+
offenders.push(
604+
`${endpoint.path} references undocumented resource '${resourceType}'`,
605+
)
606+
}
607+
}
608+
}
609+
610+
if (offenders.length > 0) {
611+
throw new Error(
612+
`Documented endpoints must not reference undocumented resources. Found:\n${offenders.join('\n')}`,
613+
)
614+
}
615+
}
616+
580617
const extractValidActionAttemptTypes = (
581618
schemas: Openapi['components']['schemas'],
582619
): string[] => {

0 commit comments

Comments
 (0)