From 95e77ad8fbb06d458ea4c249fbafbb11ecb4410c Mon Sep 17 00:00:00 2001 From: necusjz Date: Thu, 25 Sep 2025 23:46:15 +1000 Subject: [PATCH 1/4] fix: duplicate option name --- .../command/model/configuration/_command.py | 42 +++++++++++-------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/src/aaz_dev/command/model/configuration/_command.py b/src/aaz_dev/command/model/configuration/_command.py index 7785bf80..9bfbb328 100644 --- a/src/aaz_dev/command/model/configuration/_command.py +++ b/src/aaz_dev/command/model/configuration/_command.py @@ -324,6 +324,28 @@ def _build_output_type_by_subresource_selector(subresource_selector): def handle_duplicated_options(arguments, has_subresource, operation_id): + def has_duplicate(arg1, arg2): + # check whether you need to replace argument + ret = False + if _can_replace_argument(arg1, arg2, has_subresource): + arg2.ref_schema.arg = arg1.var + dropped_args.add(arg2.var) + ret = False + + elif _can_replace_argument(arg2, arg1, has_subresource): + arg1.ref_schema.arg = arg2.var + dropped_args.add(arg1.var) + ret = True + + else: + # warning developer handle duplicated options + logger.warning( + f"Duplicated Option Value: {set(arg1.options).intersection(arg2.options)} : " + f"{arg1.var} with {arg2.var} : {operation_id}" + ) + + return ret + # check argument with duplicated option names dropped_args = set() used_args = set() @@ -331,27 +353,13 @@ def handle_duplicated_options(arguments, has_subresource, operation_id): used_args.add(arg.var) if arg.var in dropped_args or not arg.options: continue - r_arg = None + for v in arguments.values(): if v.var in used_args or v.var in dropped_args or arg.var == v.var or not v.options: continue if not set(arg.options).isdisjoint(v.options): - r_arg = v - break - if r_arg: - # check whether you need to replace argument - if _can_replace_argument(r_arg, arg, has_subresource): - arg.ref_schema.arg = r_arg.var - dropped_args.add(arg.var) - elif _can_replace_argument(arg, r_arg, has_subresource): - r_arg.ref_schema.arg = arg.var - dropped_args.add(r_arg.var) - else: - # warning developer handle duplicated options - logger.warning( - f"Duplicated Option Value: {set(arg.options).intersection(r_arg.options)} : " - f"{arg.var} with {r_arg.var} : {operation_id}" - ) + if has_duplicate(arg, v): + break return [arg for var, arg in arguments.items() if var not in dropped_args] From 6b15c757c58de22fe5f6c00128405bf80a38f8dc Mon Sep 17 00:00:00 2001 From: necusjz Date: Thu, 25 Sep 2025 23:55:56 +1000 Subject: [PATCH 2/4] refactor: more meaningful func name --- src/aaz_dev/command/model/configuration/_command.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/aaz_dev/command/model/configuration/_command.py b/src/aaz_dev/command/model/configuration/_command.py index 9bfbb328..713f1595 100644 --- a/src/aaz_dev/command/model/configuration/_command.py +++ b/src/aaz_dev/command/model/configuration/_command.py @@ -324,7 +324,7 @@ def _build_output_type_by_subresource_selector(subresource_selector): def handle_duplicated_options(arguments, has_subresource, operation_id): - def has_duplicate(arg1, arg2): + def can_be_replaced(arg1, arg2): # check whether you need to replace argument ret = False if _can_replace_argument(arg1, arg2, has_subresource): @@ -357,8 +357,9 @@ def has_duplicate(arg1, arg2): for v in arguments.values(): if v.var in used_args or v.var in dropped_args or arg.var == v.var or not v.options: continue + if not set(arg.options).isdisjoint(v.options): - if has_duplicate(arg, v): + if can_be_replaced(arg, v): break return [arg for var, arg in arguments.items() if var not in dropped_args] From a38a96f6cc20336bcf254d2774212987f04c17cb Mon Sep 17 00:00:00 2001 From: necusjz Date: Mon, 29 Sep 2025 10:54:01 +1000 Subject: [PATCH 3/4] fix: handle duplicates in query --- src/aaz_dev/command/model/configuration/_command.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/aaz_dev/command/model/configuration/_command.py b/src/aaz_dev/command/model/configuration/_command.py index 713f1595..f2999832 100644 --- a/src/aaz_dev/command/model/configuration/_command.py +++ b/src/aaz_dev/command/model/configuration/_command.py @@ -327,12 +327,12 @@ def handle_duplicated_options(arguments, has_subresource, operation_id): def can_be_replaced(arg1, arg2): # check whether you need to replace argument ret = False - if _can_replace_argument(arg1, arg2, has_subresource): + if _compare_argument(arg1, arg2, has_subresource): arg2.ref_schema.arg = arg1.var dropped_args.add(arg2.var) ret = False - elif _can_replace_argument(arg2, arg1, has_subresource): + elif _compare_argument(arg2, arg1, has_subresource): arg1.ref_schema.arg = arg2.var dropped_args.add(arg1.var) ret = True @@ -365,12 +365,14 @@ def can_be_replaced(arg1, arg2): return [arg for var, arg in arguments.items() if var not in dropped_args] -def _can_replace_argument(arg, old_arg, has_subresource): +def _compare_argument(arg, old_arg, has_subresource): arg_prefix = arg.var.split('.')[0] old_prefix = old_arg.var.split('.')[0] - if old_prefix in (CMDArgBuildPrefix.Query, CMDArgBuildPrefix.Header, CMDArgBuildPrefix.Path): - # replace argument should only be in body + if old_prefix == CMDArgBuildPrefix.Query: + return True + + if old_prefix in (CMDArgBuildPrefix.Header, CMDArgBuildPrefix.Path): return False if arg_prefix in (CMDArgBuildPrefix.Query, CMDArgBuildPrefix.Header): From ee24dc4e743498977f6c01749310de20efdaac73 Mon Sep 17 00:00:00 2001 From: necusjz Date: Mon, 29 Sep 2025 11:16:19 +1000 Subject: [PATCH 4/4] Update src/aaz_dev/command/model/configuration/_command.py --- src/aaz_dev/command/model/configuration/_command.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/aaz_dev/command/model/configuration/_command.py b/src/aaz_dev/command/model/configuration/_command.py index f2999832..eff6dbe6 100644 --- a/src/aaz_dev/command/model/configuration/_command.py +++ b/src/aaz_dev/command/model/configuration/_command.py @@ -369,10 +369,10 @@ def _compare_argument(arg, old_arg, has_subresource): arg_prefix = arg.var.split('.')[0] old_prefix = old_arg.var.split('.')[0] - if old_prefix == CMDArgBuildPrefix.Query: + if old_prefix in (CMDArgBuildPrefix.Query, CMDArgBuildPrefix.Header): return True - if old_prefix in (CMDArgBuildPrefix.Header, CMDArgBuildPrefix.Path): + if old_prefix == CMDArgBuildPrefix.Path: return False if arg_prefix in (CMDArgBuildPrefix.Query, CMDArgBuildPrefix.Header):