@@ -80,6 +80,11 @@ public class OpenAPINormalizer {
80
80
final String SET_TAGS_FOR_ALL_OPERATIONS = "SET_TAGS_FOR_ALL_OPERATIONS" ;
81
81
String setTagsForAllOperations ;
82
82
83
+ // when set to true, tags in all operations will be set to operationId or "default" if operationId
84
+ // is empty
85
+ final String SET_TAGS_TO_OPERATIONID = "SET_TAGS_TO_OPERATIONID" ;
86
+ String setTagsToOperationId ;
87
+
83
88
// when set to true, auto fix integer with maximum value 4294967295 (2^32-1) or long with 18446744073709551615 (2^64-1)
84
89
// by adding x-unsigned to the schema
85
90
final String ADD_UNSIGNED_TO_INTEGER_WITH_INVALID_MAX_VALUE = "ADD_UNSIGNED_TO_INTEGER_WITH_INVALID_MAX_VALUE" ;
@@ -117,6 +122,7 @@ public OpenAPINormalizer(OpenAPI openAPI, Map<String, String> inputRules) {
117
122
ruleNames .add (SIMPLIFY_BOOLEAN_ENUM );
118
123
ruleNames .add (KEEP_ONLY_FIRST_TAG_IN_OPERATION );
119
124
ruleNames .add (SET_TAGS_FOR_ALL_OPERATIONS );
125
+ ruleNames .add (SET_TAGS_TO_OPERATIONID );
120
126
ruleNames .add (ADD_UNSIGNED_TO_INTEGER_WITH_INVALID_MAX_VALUE );
121
127
ruleNames .add (REFACTOR_ALLOF_WITH_PROPERTIES_ONLY );
122
128
ruleNames .add (NORMALIZE_31SPEC );
@@ -233,6 +239,8 @@ private void normalizeOperation(Operation operation) {
233
239
processKeepOnlyFirstTagInOperation (operation );
234
240
235
241
processSetTagsForAllOperations (operation );
242
+
243
+ processSetTagsToOperationId (operation );
236
244
}
237
245
238
246
/**
@@ -619,6 +627,24 @@ private void processSetTagsForAllOperations(Operation operation) {
619
627
operation .addTagsItem (setTagsForAllOperations );
620
628
}
621
629
630
+ /**
631
+ * Set the tag name to operationId (or "default" if operationId is empty)
632
+ *
633
+ * @param operation Operation
634
+ */
635
+ private void processSetTagsToOperationId (Operation operation ) {
636
+ if (!getRule (SET_TAGS_TO_OPERATIONID )) {
637
+ return ;
638
+ }
639
+
640
+ operation .setTags (null );
641
+ if (StringUtils .isNotEmpty (operation .getOperationId ())) {
642
+ operation .addTagsItem (operation .getOperationId ());
643
+ } else { // default to "default" if operationId is empty
644
+ operation .addTagsItem ("default" );
645
+ }
646
+ }
647
+
622
648
/**
623
649
* If the schema contains anyOf/oneOf and properties, remove oneOf/anyOf as these serve as rules to
624
650
* ensure inter-dependency between properties. It's a workaround as such validation is not supported at the moment.
0 commit comments