@@ -32,8 +32,10 @@ import {
3232import {
3333 buildSearchScope ,
3434 capitalize ,
35+ copySymbolIfDefined ,
3536 getKeyValue ,
3637 getSplittedVersionKey ,
38+ getSymbolValueIfDefined ,
3739 isDeprecatedOperationItem ,
3840 isObject ,
3941 isOperationDeprecated ,
@@ -247,12 +249,12 @@ export const calculateSpecRefs = (
247249 } )
248250
249251 if ( operations ?. length ) {
250- resolveComponentsPathItemOperationSpec ( resultSpec , normalizedSpec , operations )
252+ reduceComponentPathItemsToOperations ( resultSpec , normalizedSpec , operations )
251253 }
252254}
253255
254- export function resolveComponentsPathItemOperationSpec (
255- sourceDocument : RestOperationData ,
256+ export function reduceComponentPathItemsToOperations (
257+ resultSpec : RestOperationData ,
256258 normalizedDocument : RestOperationData ,
257259 operations : OperationId [ ] ,
258260) : void {
@@ -263,16 +265,16 @@ export function resolveComponentsPathItemOperationSpec(
263265 if ( ! isNonNullObject ( sourcePathItem ) ) {
264266 continue
265267 }
266- const refs : string [ ] = hasInlineRefsFlag ( sourcePathItem ) ? sourcePathItem [ INLINE_REFS_FLAG ] : [ ]
267- if ( refs . length === 0 ) {
268+ const refs = getSymbolValueIfDefined ( sourcePathItem , INLINE_REFS_FLAG ) as string [ ] | undefined
269+ if ( ! refs || refs ? .length === 0 ) {
268270 continue
269271 }
270272 const { jsonPath } = parseRef ( refs [ 0 ] )
271273 if ( ! jsonPath ) {
272274 continue
273275 }
274276
275- const valueByPath = getValueByPath ( sourceDocument , jsonPath ) as OpenAPIV3 . PathItemObject
277+ const valueByPath = getValueByPath ( resultSpec , jsonPath ) as OpenAPIV3 . PathItemObject
276278
277279 const operationIds : OpenAPIV3 . HttpMethods [ ] = ( Object . keys ( valueByPath ) as OpenAPIV3 . HttpMethods [ ] )
278280 . filter ( ( httpMethod ) => isValidHttpMethod ( httpMethod ) )
@@ -284,7 +286,7 @@ export function resolveComponentsPathItemOperationSpec(
284286 sourcePathItem ?. servers ||
285287 [ ] ,
286288 )
287- const operationId = getOperationId ( basePath , httpMethod , path )
289+ const operationId = calculateOperationId ( basePath , httpMethod , path )
288290 return operations . includes ( operationId )
289291 } )
290292
@@ -299,7 +301,7 @@ export function resolveComponentsPathItemOperationSpec(
299301 return pathItemObject
300302 } , { } ) ,
301303 }
302- setValueByPath ( sourceDocument , jsonPath , pathItemObject )
304+ setValueByPath ( resultSpec , jsonPath , pathItemObject )
303305 }
304306 }
305307}
@@ -322,10 +324,6 @@ const isOperationPaths = (paths: JsonPath[]): boolean => {
322324 )
323325}
324326
325- function hasInlineRefsFlag ( obj : unknown ) : obj is { [ INLINE_REFS_FLAG ] : string [ ] } {
326- return typeof obj === 'object' && obj !== null && INLINE_REFS_FLAG in obj
327- }
328-
329327// todo output of this method disrupts document normalization.
330328// origin symbols are not being transferred to the resulting spec.
331329// DO NOT pass output of this method to apiDiff
@@ -340,19 +338,18 @@ const createSingleOperationSpec = (
340338) : TYPE . RestOperationData => {
341339 const pathData = document . paths [ path ] as OpenAPIV3 . PathItemObject
342340
343- const isContainsRef = ! ! pathData . $ref
344- const refFlag = hasInlineRefsFlag ( pathData ) ? pathData [ INLINE_REFS_FLAG ] : false
341+ const isRefPathData = ! ! pathData . $ref
345342 return {
346343 openapi : openapi ?? '3.0.0' ,
347344 ...takeIfDefined ( { servers } ) ,
348345 ...takeIfDefined ( { security } ) , // TODO: remove duplicates in security
349346 paths : {
350- [ path ] : isContainsRef
347+ [ path ] : isRefPathData
351348 ? pathData
352349 : {
353350 ...extractCommonPathItemProperties ( pathData ) ,
354351 [ method ] : { ...pathData [ method ] } ,
355- ...( refFlag ? { [ INLINE_REFS_FLAG ] : refFlag } : { } ) ,
352+ ...copySymbolIfDefined ( pathData , INLINE_REFS_FLAG ) ,
356353 } ,
357354 } ,
358355 components : {
@@ -374,7 +371,7 @@ function isValidHttpMethod(method: string): method is OpenAPIV3.HttpMethods {
374371 return ( Object . values ( OpenAPIV3 . HttpMethods ) as string [ ] ) . includes ( method )
375372}
376373
377- export function getOperationId (
374+ export function calculateOperationId (
378375 basePath : string ,
379376 key : string ,
380377 path : string ,
0 commit comments