Skip to content

Commit b0ed007

Browse files
committed
Improve documentation
1 parent b82a63a commit b0ed007

3 files changed

Lines changed: 36 additions & 22 deletions

File tree

docs/customization.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generat
647647
648648
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.
649649
650-
### Available Filters
650+
### Available FILTER filters
651651
652652
- **`operationId`**
653653
When set to `operationId:addPet|getPetById`, operations **not** matching `addPet` or `getPetById` will be marked as internal (`x-internal: true`), and excluded from generation. Matching operations will have `x-internal: false`.
@@ -715,3 +715,34 @@ Into this securityScheme:
715715
scheme: bearer
716716
type: http
717717
```
718+
719+
- `REMOVE_FILTER`
720+
721+
The `REMOVE_FILTER` parameter allows the removal of elements in an openAPI document. A semicolon can separate multiple filters.
722+
723+
### Available REMOVE_FILTER filters
724+
725+
- **`internal`**
726+
When specified as `internal` or set to `internal:true`, all operations, schemas, properties and parameters marked with x-internal: true are removed from the document. Optionally set individual options like in `internal:operations|schemas|properties|parameters`
727+
728+
- **`deprecated`**
729+
When specified as `deprecated` or set to `deprecated:true`, all operations, schemas, properties and parameters marked with deprecated: true are removed.
730+
731+
- **`tags`**
732+
When specified as `tags` or set to `tags:true`, all tags are removed.
733+
When set to `tags:store|user` all tags whose name is store or user are removed.
734+
When set to `tags:keepOnlyFirstTag` perform the KEEP_ONLY_FIRST_TAG_IN_OPERATION normalization
735+
736+
- **`vendorExtensions`**
737+
When specified as `vendorExtensions` or set to `vendorExtensions:true`, remove all vendorExtensions (including x-internal).
738+
When set to `vendorExtensions:x-role|x-groups`, remove all `x-role` and `x-groups` vendorExtensions. When set to `vendorExtensions:x-internal`, perform the equivalent of REMOVE_X_INTERNAL normalization.
739+
740+
- **`unused`**
741+
When specified as `unused` or set to `unused:true`, remove all unused schemas, tags, requestBodies, responses and parameters.
742+
Optionally set individual options like in `unused:schemas|tags|requestBodies|responses|parameters`
743+
744+
Example:
745+
```
746+
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -g openapi -i modules/openapi-generator/src/test/resources/3_1/java/petstore.yaml -o /tmp/openapi/ --openapi-normalizer FILTER=tag:pet --openapi-normalizer REMOVE_FILTER=internal;unused
747+
```
748+
generates an openapi.json without the store and user operations.

modules/openapi-generator/src/main/java/org/openapitools/codegen/OpenAPINormalizer.java

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2255,8 +2255,6 @@ public boolean parse() {
22552255
} catch (RuntimeException e) {
22562256
String message = String.format(Locale.ROOT, "FILTER rule [%s] `. Error: %s",
22572257
filters, e.getMessage());
2258-
// throw an exception. This is a breaking change compared to pre 7.16.0
2259-
// Workaround: fix the syntax!
22602258
throw new IllegalArgumentException(message);
22612259
}
22622260
}
@@ -2266,11 +2264,6 @@ public boolean hasFilter() {
22662264
}
22672265

22682266
private void doParse() {
2269-
if ("true".equals(filters)) {
2270-
allTrue();
2271-
return;
2272-
}
2273-
22742267
for (String filter : filters.split(";")) {
22752268
filter = filter.trim();
22762269
String[] filterStrs = filter.split(":");
@@ -2346,20 +2339,6 @@ protected void parseFails(String filterName, String filterValue) {
23462339
throw new IllegalArgumentException("filter not supported :[" + filterName + ":" + filterValue + "]");
23472340
}
23482341

2349-
private void allTrue() {
2350-
hasFilter = true;
2351-
2352-
internalOperations = true;
2353-
internalSchemas = true;
2354-
internalProperties = true;
2355-
internalParameters = true;
2356-
2357-
unusedSchemas = true;
2358-
unusedParameters = true;
2359-
unusedTags = true;
2360-
unusedRequestBodies = true;
2361-
}
2362-
23632342
protected boolean matchTag(Operation operation, int index, String tag) {
23642343
if (removeAllTags) {
23652344
return true;

modules/openapi-generator/src/test/java/org/openapitools/codegen/OpenAPINormalizerTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,6 +1283,10 @@ public Object[][] getTestConfigs() {
12831283
URL path = getClass().getClassLoader().getResource("openapi_normalizer");
12841284
File[] files = new File(path.getFile())
12851285
.listFiles(file -> file.getName().endsWith("_config.yaml"));
1286+
1287+
if (files == null || files.length == 0) {
1288+
throw new AssertionError("No test configs found in openapi_normalizer directory.");
1289+
}
12861290
return Arrays.stream(files)
12871291
.map(file -> new Object[]{"src/test/resources/openapi_normalizer/" +file.getName()})
12881292
.toArray(Object[][]::new);

0 commit comments

Comments
 (0)