diff --git a/src/ComponentProvider.ts b/src/ComponentProvider.ts index 96aa33d7..0516d6ae 100644 --- a/src/ComponentProvider.ts +++ b/src/ComponentProvider.ts @@ -56,7 +56,6 @@ export const getOptimizableComponents = ( asyncAPIDocument: AsyncAPIDocumentInterface ): OptimizableComponentGroup[] => { const optimizeableComponents: OptimizableComponentGroup[] = [] - const getAllComponents = (type: string) => { // @ts-ignore if (typeof asyncAPIDocument[type] !== 'function') return [] @@ -84,6 +83,8 @@ export const getOptimizableComponents = ( operationBindings: getAllComponents('operationBindings'), messageBindings: getAllComponents('messageBindings'), } + const options = { includeSchemas: false } + !options.includeSchemas && delete optimizableComponents.schemas for (const [type, components] of Object.entries(optimizableComponents)) { if (components.length === 0) continue optimizeableComponents.push({ diff --git a/src/Reporters/moveAllToComponents.ts b/src/Reporters/moveAllToComponents.ts index 40537772..cada90a9 100644 --- a/src/Reporters/moveAllToComponents.ts +++ b/src/Reporters/moveAllToComponents.ts @@ -17,16 +17,17 @@ const findAllComponents = ( const resultElements: ReportElement[] = [] - let counter = 1 - for (const [index, component] of outsideComponentsSection.entries()) { const existingResult = resultElements.filter( (reportElement) => component.path === reportElement.path )[0] if (!existingResult) { - const componentName = - component.component.name || - `${optimizableComponentGroup.type.slice(0, -1)}-${counter++}` + let componentName: string + if (component.component['x-origin']) { + componentName = String(component.component['x-origin']).split('/').reverse()[0] + } else { + componentName = String(component.path).split('.')[1] + } const target = `components.${optimizableComponentGroup.type}.${componentName}` resultElements.push({ path: component.path,