@@ -91,6 +91,10 @@ public class OpenAPINormalizer {
9191 final String SET_TAGS_TO_OPERATIONID = "SET_TAGS_TO_OPERATIONID" ;
9292 String setTagsToOperationId ;
9393
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+
9498 // when set to true, tags in all operations will be set to operationId or "default" if operationId
9599 // is empty
96100 final String FIX_DUPLICATED_OPERATIONID = "FIX_DUPLICATED_OPERATIONID" ;
@@ -158,6 +162,7 @@ public OpenAPINormalizer(OpenAPI openAPI, Map<String, String> inputRules) {
158162 ruleNames .add (KEEP_ONLY_FIRST_TAG_IN_OPERATION );
159163 ruleNames .add (SET_TAGS_FOR_ALL_OPERATIONS );
160164 ruleNames .add (SET_TAGS_TO_OPERATIONID );
165+ ruleNames .add (SET_TAGS_TO_VENDOR_EXTENSION );
161166 ruleNames .add (FIX_DUPLICATED_OPERATIONID );
162167 ruleNames .add (ADD_UNSIGNED_TO_INTEGER_WITH_INVALID_MAX_VALUE );
163168 ruleNames .add (REFACTOR_ALLOF_WITH_PROPERTIES_ONLY );
@@ -224,6 +229,11 @@ public void processRules(Map<String, String> inputRules) {
224229 rules .put (SET_TAGS_FOR_ALL_OPERATIONS , true );
225230 }
226231
232+ setTagsToVendorExtension = inputRules .get (SET_TAGS_TO_VENDOR_EXTENSION );
233+ if (setTagsToVendorExtension != null ) {
234+ rules .put (SET_TAGS_TO_VENDOR_EXTENSION , true );
235+ }
236+
227237 if (inputRules .get (FILTER ) != null ) {
228238 rules .put (FILTER , true );
229239
@@ -375,6 +385,8 @@ private void normalizeOperation(Operation operation) {
375385
376386 processSetTagsToOperationId (operation );
377387
388+ processSetTagsToVendorExtension (operation );
389+
378390 processFixDuplicatedOperationId (operation );
379391 }
380392
@@ -885,8 +897,7 @@ private void processUseAllOfRefAsParent(Schema schema) {
885897 }
886898
887899 /**
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.
890901 *
891902 * @param operation Operation
892903 */
@@ -955,6 +966,34 @@ private void processSetTagsToOperationId(Operation operation) {
955966 }
956967 }
957968
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+
958997 private void processFixDuplicatedOperationId (Operation operation ) {
959998 if (!getRule (FIX_DUPLICATED_OPERATIONID )) {
960999 return ;
0 commit comments