@@ -31,7 +31,6 @@ interface ResponseExample {
3131}
3232
3333interface MergedExample {
34- key : string
3534 request : {
3635 contentType ?: string
3736 description : string
@@ -66,20 +65,23 @@ export default async function getCodeSamples(operation: Operation): Promise<Merg
6665 count [ item . request . description ] = ( count [ item . request . description ] || 0 ) + 1
6766 }
6867
69- const newMergedExamples = mergedExamples . map ( ( example , i ) => ( {
70- ...example ,
71- request : {
72- ...example . request ,
73- description :
74- count [ example . request . description ] > 1
75- ? `${ example . request . description } ${ i + 1 } : Status Code ${ example . response ! . statusCode } `
76- : example . request . description ,
77- } ,
78- } ) )
79-
80- return newMergedExamples
68+ return mergedExamples . map ( ( example , i ) => {
69+ delete ( example as any ) . key
70+ return {
71+ ...example ,
72+ request : {
73+ ...example . request ,
74+ description :
75+ count [ example . request . description ] > 1
76+ ? `${ example . request . description } ${ i + 1 } : Status Code ${ example . response ! . statusCode } `
77+ : example . request . description ,
78+ } ,
79+ }
80+ } )
8181 }
8282
83+ // Strip the key field — it's only needed during merging, not at runtime
84+ for ( const example of mergedExamples ) delete ( example as any ) . key
8385 return mergedExamples
8486}
8587
@@ -260,6 +262,24 @@ export function getRequestExamples(operation: Operation): RequestExample[] {
260262 return requestExamples
261263}
262264
265+ /*
266+ Recursively removes `example` and `examples` annotation fields from a JSON
267+ Schema object. These fields are OpenAPI annotation-only and are never read
268+ by the runtime rendering code, but they account for ~131 MB of the total
269+ schema.json size across all versions.
270+ */
271+ function stripSchemaExamples ( schema : any ) : any {
272+ if ( ! schema || typeof schema !== 'object' ) return schema
273+ if ( Array . isArray ( schema ) ) return schema . map ( stripSchemaExamples )
274+
275+ const result : any = { }
276+ for ( const [ key , value ] of Object . entries ( schema ) ) {
277+ if ( key === 'example' || key === 'examples' ) continue
278+ result [ key ] = stripSchemaExamples ( value )
279+ }
280+ return result
281+ }
282+
263283/*
264284 Create an example object for each example in the response property
265285 of the schema. Each response can have more than one status code,
@@ -355,7 +375,10 @@ export function getResponseExamples(operation: Operation): ResponseExample[] {
355375 // Note: Including the schema significantly increases JSON file size (~4x),
356376 // but it's necessary to support the schema/example toggle in the UI.
357377 // Users can switch between viewing the example response and the full schema.
358- schema : operation . responses [ statusCode ] . content [ contentType ] . schema ,
378+ // example/examples annotation fields are stripped as they are not rendered.
379+ schema : stripSchemaExamples (
380+ operation . responses [ statusCode ] . content [ contentType ] . schema ,
381+ ) ,
359382 } ,
360383 }
361384 responseExamples . push ( example )
0 commit comments