@@ -91,6 +91,10 @@ public class OpenAPINormalizer {
91
91
final String SET_TAGS_TO_OPERATIONID = "SET_TAGS_TO_OPERATIONID" ;
92
92
String setTagsToOperationId ;
93
93
94
+ // when set to a string value, tags will be set to the value of the provided vendor extension
95
+ final String SET_TAGS_TO_VENDOR_EXTENSION = "SET_TAGS_TO_VENDOR_EXTENSION" ;
96
+ String setTagsToVendorExtension ;
97
+
94
98
// when set to true, tags in all operations will be set to operationId or "default" if operationId
95
99
// is empty
96
100
final String FIX_DUPLICATED_OPERATIONID = "FIX_DUPLICATED_OPERATIONID" ;
@@ -158,6 +162,7 @@ public OpenAPINormalizer(OpenAPI openAPI, Map<String, String> inputRules) {
158
162
ruleNames .add (KEEP_ONLY_FIRST_TAG_IN_OPERATION );
159
163
ruleNames .add (SET_TAGS_FOR_ALL_OPERATIONS );
160
164
ruleNames .add (SET_TAGS_TO_OPERATIONID );
165
+ ruleNames .add (SET_TAGS_TO_VENDOR_EXTENSION );
161
166
ruleNames .add (FIX_DUPLICATED_OPERATIONID );
162
167
ruleNames .add (ADD_UNSIGNED_TO_INTEGER_WITH_INVALID_MAX_VALUE );
163
168
ruleNames .add (REFACTOR_ALLOF_WITH_PROPERTIES_ONLY );
@@ -224,6 +229,11 @@ public void processRules(Map<String, String> inputRules) {
224
229
rules .put (SET_TAGS_FOR_ALL_OPERATIONS , true );
225
230
}
226
231
232
+ setTagsToVendorExtension = inputRules .get (SET_TAGS_TO_VENDOR_EXTENSION );
233
+ if (setTagsToVendorExtension != null ) {
234
+ rules .put (SET_TAGS_TO_VENDOR_EXTENSION , true );
235
+ }
236
+
227
237
if (inputRules .get (FILTER ) != null ) {
228
238
rules .put (FILTER , true );
229
239
@@ -375,6 +385,8 @@ private void normalizeOperation(Operation operation) {
375
385
376
386
processSetTagsToOperationId (operation );
377
387
388
+ processSetTagsToVendorExtension (operation );
389
+
378
390
processFixDuplicatedOperationId (operation );
379
391
}
380
392
@@ -885,8 +897,7 @@ private void processUseAllOfRefAsParent(Schema schema) {
885
897
}
886
898
887
899
/**
888
- * Keep only first tag in the operation if the operation has more than
889
- * one tag.
900
+ * Remove/hide the x-internal in operations and model.
890
901
*
891
902
* @param operation Operation
892
903
*/
@@ -955,6 +966,34 @@ private void processSetTagsToOperationId(Operation operation) {
955
966
}
956
967
}
957
968
969
+ /**
970
+ * Set the tag name to the value of the provided vendor extension
971
+ *
972
+ * @param operation Operation
973
+ */
974
+ private void processSetTagsToVendorExtension (Operation operation ) {
975
+ if (StringUtils .isEmpty (setTagsToVendorExtension )) {
976
+ return ;
977
+ }
978
+
979
+ if (operation .getExtensions () == null ) {
980
+ return ;
981
+ }
982
+
983
+ if (operation .getExtensions ().containsKey (setTagsToVendorExtension )) {
984
+ operation .setTags (null );
985
+ Object argObj = operation .getExtensions ().get (setTagsToVendorExtension );
986
+ if (argObj instanceof List ) {
987
+ List <String > tags = (List <String >) argObj ;
988
+ for (String tag : tags ) {
989
+ operation .addTagsItem (tag );
990
+ }
991
+ } else {
992
+ operation .addTagsItem (String .valueOf (argObj ));
993
+ }
994
+ }
995
+ }
996
+
958
997
private void processFixDuplicatedOperationId (Operation operation ) {
959
998
if (!getRule (FIX_DUPLICATED_OPERATIONID )) {
960
999
return ;
0 commit comments