@@ -14,11 +14,43 @@ import GithubSlugger from 'github-slugger'
1414// These are only used by REST templates and kept here (not in engine.ts)
1515// to avoid a circular dependency: rest-tags → renderContent → engine.
1616for ( const [ tagName , tagClass ] of Object . entries ( apiTransformerTags ) ) {
17- engine . registerTag ( tagName , tagClass as any )
17+ engine . registerTag ( tagName , tagClass as unknown as Parameters < typeof engine . registerTag > [ 1 ] )
1818}
1919
2020const DEBUG = process . env . RUNNER_DEBUG === '1' || process . env . DEBUG === '1'
2121
22+ type PreparedCodeExample = {
23+ request : {
24+ description : string
25+ url : string
26+ acceptHeader ?: string
27+ bodyParameters : string | null
28+ }
29+ response : {
30+ statusCode ?: string
31+ schema : string | null
32+ }
33+ }
34+
35+ type PreparedOperation = Omit < Operation , 'statusCodes' | 'codeExamples' > & {
36+ description : string
37+ hasParameters : boolean
38+ showHeaders : boolean
39+ needsContentTypeHeader : boolean
40+ statusCodes ?: Array < { httpStatusCode : string ; description ?: string } >
41+ codeExamples : PreparedCodeExample [ ]
42+ }
43+
44+ type PreparedTemplateData = {
45+ page : {
46+ title : Page [ 'title' ]
47+ intro : string
48+ }
49+ manualContent : string
50+ restOperations : PreparedOperation [ ]
51+ apiVersion ?: string
52+ }
53+
2254/**
2355 * Transformer for REST API pages
2456 * Converts REST operations and their data into markdown format using a Liquid template
@@ -114,12 +146,14 @@ export class RestTransformer implements PageTransformer {
114146 // Load and render template
115147 const templateContent = loadTemplate ( this . templateName )
116148
117- // Render the template with Liquid
149+ // Render the template with Liquid. templateData intentionally replaces
150+ // context.page with a simplified, text-rendered {title, intro} for the
151+ // template, so the merged object is not a strict Context.
118152 const rendered = await renderContent ( templateContent , {
119153 ...context ,
120154 ...templateData ,
121155 markdownRequested : true ,
122- } )
156+ } as unknown as Context )
123157
124158 if ( DEBUG ) console . log ( `[DEBUG] RestTransformer completed in ${ Date . now ( ) - startTime } ms` )
125159 return rendered
@@ -134,7 +168,7 @@ export class RestTransformer implements PageTransformer {
134168 context : Context ,
135169 manualContent : string ,
136170 apiVersion ?: string ,
137- ) : Promise < Record < string , any > > {
171+ ) : Promise < PreparedTemplateData > {
138172 // Prepare page intro
139173 const intro = page . intro ? await page . renderProp ( 'intro' , context , { textOnly : true } ) : ''
140174
@@ -152,8 +186,7 @@ export class RestTransformer implements PageTransformer {
152186 }
153187 const schemaMap = new Map < string , string > ( )
154188 for ( const op of preparedOperations ) {
155- if ( ! op . codeExamples ) continue
156- for ( const example of op . codeExamples as any [ ] ) {
189+ for ( const example of op . codeExamples ) {
157190 const schema = example . response ?. schema
158191 if ( ! schema || typeof schema !== 'string' ) continue
159192
@@ -181,7 +214,7 @@ export class RestTransformer implements PageTransformer {
181214 /**
182215 * Prepare a single operation for template rendering
183216 */
184- private async prepareOperation ( operation : Operation ) : Promise < Record < string , any > > {
217+ private async prepareOperation ( operation : Operation ) : Promise < PreparedOperation > {
185218 // Convert HTML description to text
186219 const description = operation . descriptionHTML ? fastTextOnly ( operation . descriptionHTML ) : ''
187220
@@ -213,6 +246,9 @@ export class RestTransformer implements PageTransformer {
213246 }
214247 }
215248
249+ const responseSchema = (
250+ example . response as { schema ?: Parameters < typeof summarizeSchema > [ 0 ] } | undefined
251+ ) ?. schema
216252 return {
217253 request : {
218254 description : example . request ?. description
@@ -226,9 +262,7 @@ export class RestTransformer implements PageTransformer {
226262 } ,
227263 response : {
228264 statusCode : example . response ?. statusCode ,
229- schema : ( example . response as any ) ?. schema
230- ? summarizeSchema ( ( example . response as any ) . schema )
231- : null ,
265+ schema : responseSchema ? summarizeSchema ( responseSchema ) : null ,
232266 } ,
233267 }
234268 } ) || [ ]
0 commit comments