@@ -7,6 +7,11 @@ import type {
77 Route ,
88} from '@seamapi/blueprint'
99import { pascalCase } from 'change-case'
10+ import type {
11+ SdkName ,
12+ SyntaxName ,
13+ } from 'node_modules/@seamapi/blueprint/dist/index.cjs'
14+ import type { ResourceSample } from 'node_modules/@seamapi/blueprint/lib/samples/resource-sample.js'
1015
1116import type { PathMetadata } from 'lib/path-metadata.js'
1217
@@ -18,6 +23,7 @@ export interface ApiRouteLayoutContext {
1823 ApiRouteResource & {
1924 warnings : ApiWarning [ ]
2025 errors : ApiError [ ]
26+ resourceSamples : ResourceSampleContext [ ]
2127 }
2228 >
2329 endpoints : ApiRouteEndpoint [ ]
@@ -30,6 +36,12 @@ interface ApiRouteEvent {
3036 properties : ApiRouteProperty [ ]
3137}
3238
39+ interface ResourceSampleContext {
40+ title : string
41+ resourceData : string
42+ resourceDataSyntax : SyntaxName
43+ }
44+
3345type ApiRouteProperty = Pick <
3446 Property ,
3547 'name' | 'description' | 'isDeprecated' | 'deprecationMessage'
@@ -144,6 +156,7 @@ export function setApiRouteLayoutContext(
144156 errors : resourceErrors ,
145157 warnings : resourceWarnings ,
146158 events : resourceEvents ,
159+ resourceSamples : resource . resourceSamples . map ( mapResourceSample ) ,
147160 } )
148161 }
149162}
@@ -337,3 +350,21 @@ function addLinkTargetsToProperties(
337350 }
338351 }
339352}
353+
354+ const mapResourceSample = ( sample : ResourceSample ) : ResourceSampleContext => {
355+ const jsonSample = Object . entries ( sample . resource ) . find (
356+ ( [ k ] ) => ( k as SdkName ) === 'seam_cli' ,
357+ ) ?. [ 1 ]
358+
359+ if ( jsonSample == null ) {
360+ throw new Error (
361+ `Missing seam_cli for ${ sample . resource_type } resource sample: ${ sample . title } ` ,
362+ )
363+ }
364+
365+ return {
366+ title : sample . title ,
367+ resourceData : jsonSample . resource_data ,
368+ resourceDataSyntax : jsonSample . resource_data_syntax ,
369+ }
370+ }
0 commit comments