@@ -292,8 +292,6 @@ export function createCopyWithEmptyPathItems(template: RestOperationData): RestO
292292export  function  createCopyWithPrefixGroupOperationsOnly ( source : RestOperationData ,  groupPrefix : string ) : RestOperationData  { 
293293  validateGroupPrefix ( groupPrefix ,  'groupPrefix' ) 
294294
295-   // eslint-disable-next-line @typescript-eslint/no-unused-vars 
296-   const  {  paths,  servers : rootServers ,  ...rest  }  =  source 
297295  const  groupWithoutEdgeSlashes  =  trimSlashes ( groupPrefix ) 
298296
299297  // Since we are anyway composing synthetic specs for prefix groups comparison, we can incorporate 
@@ -302,10 +300,11 @@ export function createCopyWithPrefixGroupOperationsOnly(source: RestOperationDat
302300  // Note that servers in operation objects are not taken into account 
303301  // (it is impossible to support them in api-diff mapping 
304302  // and they are considered bad practice on OpenAPI specifications anyway) 
305-   return  { 
303+   const  result : RestOperationData  =  { 
304+     ...source , 
306305    paths : { 
307306      ...Object . fromEntries ( 
308-         Object . entries ( paths ) 
307+         Object . entries ( source . paths ) 
309308          . map ( ( [ pathKey ,  pathItem ] )  =>  { 
310309            // Path item servers take precedence over root servers 
311310            const  pathItemServers  =  ( pathItem  as  OpenAPIV3 . PathItemObject ) ?. servers 
@@ -314,17 +313,21 @@ export function createCopyWithPrefixGroupOperationsOnly(source: RestOperationDat
314313            // Prepend base path to the path 
315314            const  fullPath  =  basePath  ? `/${ trimSlashes ( basePath ) } ${ trimSlashes ( pathKey ) }  . replace ( / \/ + / g,  '/' )  : pathKey 
316315
317-             // Remove servers from path item copy 
318-             // eslint-disable-next-line @typescript-eslint/no-unused-vars 
319-             const   {   servers :  pathServers ,  ... pathItemWithoutServers   }   =   pathItem   as   OpenAPIV3 . PathItemObject 
316+             // Remove servers from path item copy using delete to preserve property order  
317+             const   pathItemCopy   =   {  ... ( pathItem   as   OpenAPIV3 . PathItemObject )   } 
318+             delete   pathItemCopy . servers 
320319
321-             return  [ fullPath ,  pathItemWithoutServers ]  as  const 
320+             return  [ fullPath ,  pathItemCopy ]  as  const 
322321          } ) 
323322          . filter ( ( [ key ] )  =>  removeFirstSlash ( key  as  string ) . startsWith ( `${ groupWithoutEdgeSlashes }  ) )  // note that 'api/v10' is a substring of 'api/v1000' 
324323          // remove group prefix for correct path mapping in apiDiff 
325324          . map ( ( [ key ,  value ] )  =>  [ removeFirstSlash ( key  as  string ) . substring ( groupWithoutEdgeSlashes . length ) ,  value ] ) , 
326325      ) , 
327326    } , 
328-     ...rest , 
329327  } 
328+ 
329+   // Remove servers from root level using delete to preserve property order 
330+   delete  result . servers 
331+ 
332+   return  result 
330333} 
0 commit comments