diff --git a/API.md b/API.md index dae210dc..9b79e4b8 100644 --- a/API.md +++ b/API.md @@ -35,6 +35,8 @@ user will only interact with this class. here we generate different kind of repo
Object
Object
Object
Boolean
| whether to remove un-used components from `components` section or not. Defaults to `true`. |
| [moveAllToComponents] | Boolean
| whether to move all AsyncAPI Specification-valid components to the `components` section or not. Defaults to `true`. |
| [moveDuplicatesToComponents] | Boolean
| whether to move duplicated components to the `components` section or not. Defaults to `false`. |
-| [schemas] | Boolean
| whether to add calculated `schemas` to the optimized AsyncAPI Document or not. Defaults to `true`. |
+
+
+
+## DisableOptimizationFor : Object
+**Kind**: global typedef
+**Properties**
+
+| Name | Type | Description |
+| --- | --- | --- |
+| [schema] | Boolean
| whether object `schema` should be excluded from the process of optimization (`true` instructs **not** to add calculated `schemas` to the optimized AsyncAPI Document.) |
@@ -158,3 +169,5 @@ Converts JSON or YAML string object.
| --- | --- | --- |
| [rules] | [Rules
](#Rules) | the list of rules that specifies which type of optimizations should be applied. |
| [output] | String
| specifies which type of output user wants, `'JSON'` or `'YAML'`. Defaults to `'YAML'`; |
+| [disableOptimizationFor] | [DisableOptimizationFor
](#DisableOptimizationFor) | the list of objects that should be excluded from the process of optimization. |
+
diff --git a/examples/index.js b/examples/index.js
index 2b7db726..5c7d928e 100644
--- a/examples/index.js
+++ b/examples/index.js
@@ -11,15 +11,9 @@ optimizer.getReport().then((report) => {
rules: {
reuseComponents: true,
removeComponents: true,
- moveAllToComponents: true,
- moveDuplicatesToComponents: false,
- },
- disableOptimizationFor: {
- schema: true,
+ moveToComponents: true,
},
})
//store optimizedDocument as to output.yaml
require('fs').writeFileSync('./examples/output.yaml', optimizedDocument)
})
-
-// , { rules: { schemas: false } }
diff --git a/src/Optimizer.ts b/src/Optimizer.ts
index c70e35a2..3d0b2216 100644
--- a/src/Optimizer.ts
+++ b/src/Optimizer.ts
@@ -88,16 +88,20 @@ export class Optimizer {
* @typedef {Object} Rules
* @property {Boolean=} reuseComponents - whether to reuse components from `components` section or not. Defaults to `true`.
* @property {Boolean=} removeComponents - whether to remove un-used components from `components` section or not. Defaults to `true`.
- * @property {Boolean=} moveAllToComponents - whether to move all AsyncAPI Specification-valid components to the `components` section or not.
- * @property {Boolean=} moveDuplicatesToComponents - whether to move duplicated components to the `components` section or not. Defaults to `true`.
+ * @property {Boolean=} moveAllToComponents - whether to move all AsyncAPI Specification-valid components to the `components` section or not. Defaults to `true`.
+ * @property {Boolean=} moveDuplicatesToComponents - whether to move duplicated components to the `components` section or not. Defaults to `false`.
+ */
+ /**
+ * @typedef {Object} DisableOptimizationFor
+ * @property {Boolean=} schema - whether object `schema` should be excluded from the process of optimization (`true` instructs **not** to add calculated `schemas` to the optimized AsyncAPI Document.)
*/
-
/**
* @typedef {Object} Options
* @property {Rules=} rules - the list of rules that specifies which type of optimizations should be applied.
* @property {String=} output - specifies which type of output user wants, `'JSON'` or `'YAML'`. Defaults to `'YAML'`;
+ * @property {DisableOptimizationFor=} disableOptimizationFor - the list of objects that should be excluded from the process of optimization.
*/
- /**
+ /**
* This function is used to get the optimized document after seeing the report.
*
* @param {Options=} Options - the options are a way to customize the final output.
diff --git a/src/Reporters/moveAllToComponents.ts b/src/Reporters/moveAllToComponents.ts
index 952c346f..c3a8144d 100644
--- a/src/Reporters/moveAllToComponents.ts
+++ b/src/Reporters/moveAllToComponents.ts
@@ -26,7 +26,7 @@ const findAllComponents = (
if (component.component['x-origin']) {
componentName = String(component.component['x-origin']).split('/').reverse()[0]
} else {
- componentName = String(component.path).split('.')[1]
+ componentName = String(component.path).split('.').reverse()[0]
}
const target = `components.${optimizableComponentGroup.type}.${componentName}`
resultElements.push({
diff --git a/src/Reporters/moveDuplicatesToComponents.ts b/src/Reporters/moveDuplicatesToComponents.ts
index c57f90c2..cbba17b0 100644
--- a/src/Reporters/moveDuplicatesToComponents.ts
+++ b/src/Reporters/moveDuplicatesToComponents.ts
@@ -5,7 +5,7 @@ import Debug from 'debug'
const debug = Debug('reporter:moveDuplicatesToComponents')
/**
*
- * @param optimizableComponentGroup components that you want to analyze for duplicates.
+ * @param optimizableComponentGroup all AsyncAPI Specification-valid components that you want to analyze for duplicates.
* @returns A list of optimization report elements.
*/
const findDuplicateComponents = (
@@ -28,7 +28,7 @@ const findDuplicateComponents = (
if (component.component['x-origin']) {
componentName = String(component.component['x-origin']).split('/').reverse()[0]
} else {
- componentName = String(component.path).split('.')[1]
+ componentName = String(component.path).split('.').reverse()[0]
}
const target = `components.${optimizableComponentGroup.type}.${componentName}`
resultElements.push({