Skip to content

Commit

Permalink
feat: add flag moveAllToComponents
Browse files Browse the repository at this point in the history
  • Loading branch information
aeworxet committed Mar 14, 2024
1 parent f27491b commit 0cb2bbe
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/ComponentProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 []
Expand Down Expand Up @@ -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({
Expand Down
11 changes: 6 additions & 5 deletions src/Reporters/moveAllToComponents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 0cb2bbe

Please sign in to comment.