Skip to content
This repository has been archived by the owner on Dec 15, 2023. It is now read-only.

Move splitted operation references to cli-split-operation-splitted-operations #66

Merged
merged 3 commits into from
Jun 9, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ export class Helper {
(isNullOrUndefined(NodeHelper.getPolyAsResourceParam(vv)) ? '' : `${NEW_LINE}${tab(3)}cli-poly-as-resource-subclass-param: ${NodeHelper.getCliKey(NodeHelper.getPolyAsResourceParam(vv), '<missing-clikey>')}`) +
(isNullOrUndefined(NodeHelper.getPolyAsResourceOriginalOperation(vv)) ? '' : `${NEW_LINE}${tab(3)}cli-poly-as-resource-original-operation: ${NodeHelper.getCliKey(NodeHelper.getPolyAsResourceOriginalOperation(vv), '<missing-clikey>')}`) +
(isNullOrUndefined(NodeHelper.getSplitOperationOriginalOperation(vv)) ? '' : `${NEW_LINE}${tab(3)}cli-split-operation-original-operation: ${NodeHelper.getCliKey(NodeHelper.getSplitOperationOriginalOperation(vv), '<missing-clikey>')}`) +
(NodeHelper.getSplitOperationIntoOperations(vv, () => []).length === 0 ? '' : `${NEW_LINE}${tab(3)}cli-split-operation-into-operations: ${NodeHelper.getSplitOperationIntoOperations(vv, () => []).map((vvv) => NodeHelper.getCliKey(vvv, '<missing-clikey>')).join(',')}`) +
`${NEW_LINE}${tab(3)}parameters:${NEW_LINE}`.concat(
vv.parameters.map(vvv => `${tab(3)}- parameterName: ${generateCliValue(vvv, 4)}${generatePropertyFlattenValue(vvv, 4)}${generatePropertyReadonlyValue(vvv, 4)}${generateDiscriminatorValueForParam(vvv, 4)}${NEW_LINE}` +
(isNullOrUndefined(NodeHelper.getPolyAsResourceBaseSchema(vvv)) ? '' : `${tab(4)}cli-poly-as-resource-base-schema: ${NodeHelper.getCliKey(NodeHelper.getPolyAsResourceBaseSchema(vvv), '<baseSchemaCliKeyMissing>')}${NEW_LINE}`) +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this code is getter more and more complex, feel free to refactor it if you want.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I will do refactor later, thanks

Expand Down
11 changes: 11 additions & 0 deletions src/nodeHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export class NodeHelper {
private static readonly POLY_AS_PARAM_ORIGINIAL_PARAMETER = 'cli-poly-as-param-original-parameter';
private static readonly POLY_AS_PARAM_EXPANDED = 'cli-poly-as-param-expanded';
private static readonly SPLIT_OPERATION_ORIGINAL_OPERATION = 'cli-split-operation-original-operation';
private static readonly SPLIT_OPERATION_INTO_OPERATIONS = 'cli-split-operation-into-operations';
private static readonly SPLIT_OPERATION_NAMES = 'split-operation-names';

private static visitedKeyDict = {};
Expand Down Expand Up @@ -219,6 +220,16 @@ export class NodeHelper {
return NodeHelper.getExtensionsProperty(op, NodeHelper.SPLIT_OPERATION_ORIGINAL_OPERATION, null);
}

public static addSplitOperationIntoOperations(op: Operation, splittedOp: Operation) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about make it more generic to have it in NodeHelper, we dont need split concept here, for example, addExtendedOperation(node: Operation, operation: Operation)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am worried about generic may cause confusing. Because previously we put these operations in cli-operations, which makes az cannot know these operations come from poly or split. That's why I create an independent property for split.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed reference. Thanks

const ops: Operation[] = NodeHelper.getExtensionsProperty(op, NodeHelper.SPLIT_OPERATION_INTO_OPERATIONS, () => []);
ops.push(splittedOp);
NodeHelper.setExtensionsProperty(op, NodeHelper.SPLIT_OPERATION_INTO_OPERATIONS, ops);
}

public static getSplitOperationIntoOperations(originalOperation: Operation, defaultValue: () => any): Operation[] {
return NodeHelper.getExtensionsProperty(originalOperation, NodeHelper.SPLIT_OPERATION_INTO_OPERATIONS, defaultValue);
}

public static setPolyAsParamBaseSchema(param: Parameter, base: Schema) {
NodeHelper.setExtensionsProperty(param, NodeHelper.POLY_AS_PARAM_BASE_SCHEMA, base);
}
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/splitOperation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class SplitOperation{

splittedOperations.forEach((splittedOperation) => {
// Link src operation to splitted operation
NodeHelper.addCliOperation(operation, splittedOperation);
NodeHelper.addSplitOperationIntoOperations(operation, splittedOperation);
// Link splitted operation to src opreation
NodeHelper.setSplitOperationOriginalOperation(splittedOperation, operation);

Expand Down