You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
OpenApiNormalizer FILTER improvements. Multi filters + filter on path (#22128)
* Use Filter Parser and allow multiple filters
* OpenAPINormalizer fails for invalid FILTER syntax
* Fix typo
* Use constants for filter keys.
Improve exception handling and tests.
* Fix format missing Locale.ROOT
* Make Filter extensible
* Additional unit test for invalid filter
The `FILTER` parameter allows selective inclusion of API operations based on specific criteria. It applies the `x-internal: true` property to operations that do **not** match the specified values, preventing them from being generated.
648
+
The `FILTER` parameter allows selective inclusion of API operations based on specific criteria. It applies the `x-internal: true` property to operations that do **not** match the specified values, preventing them from being generated. Multiple filters can be separated by a semicolon.
649
649
650
650
### Available Filters
651
651
@@ -658,14 +658,17 @@ The `FILTER` parameter allows selective inclusion of API operations based on spe
658
658
- **`tag`**
659
659
When set to `tag:person|basic`, operations **not** tagged with `person` or `basic` will be marked as internal (`x-internal: true`), and will not be generated.
660
660
661
+
- **`path`**
662
+
When set to `path:/v1|/v2`, operations on paths **not** starting with `/v1` or with `/v2` will be marked as internal (`x-internal: true`), and will not be generated.
if (filterStrs.length != 2) { // only support operationId with : at the moment
281
-
LOGGER.error("FILTER rule must be in the form of `operationId:name1|name2|name3` or `method:get|post|put` or `tag:tag1|tag2|tag3`: {}", inputRules.get(FILTER));
LOGGER.error("FILTER rule must be in the form of `operationId:name1|name2|name3` or `method:get|post|put` or `tag:tag1|tag2|tag3`: {}", inputRules.get(FILTER));
300
-
}
301
-
}
274
+
// actual parsing is delayed to allow customization of the Filter processing
302
275
}
303
276
304
277
if (inputRules.get(SET_CONTAINER_TO_NULLABLE) != null) {
@@ -344,6 +317,19 @@ public void processRules(Map<String, String> inputRules) {
344
317
}
345
318
}
346
319
320
+
/**
321
+
* Create the filter to process the FILTER normalizer.
322
+
* Override this to create a custom filter normalizer.
323
+
*
324
+
* @param openApi Contract used in the filtering (could be used for customization).
// Iterates over each HTTP method in methodMap, retrieves the corresponding Operation from the PathItem,
409
-
// and marks it as internal (`x-internal`) if the method is not in methodFilters.
410
-
methodMap.forEach((method, getter) -> {
411
-
Operationoperation = getter.apply(path);
412
-
if (operation != null && !methodFilters.isEmpty()) {
413
-
LOGGER.info("operation `{}` marked internal only (x-internal: `{}`) by the method FILTER", operation.getOperationId(), !methodFilters.contains(method));
Stringmessage = String.format(Locale.ROOT, "FILTER rule [%s] must be in the form of `%s:name1|name2|name3` or `%s:get|post|put` or `%s:tag1|tag2|tag3` or `%s:/v1|/v2`. Error: %s",
0 commit comments