Skip to content

Commit 02ad795

Browse files
authored
Merge pull request #1 from OpenAPITools/master
Update
2 parents c96d308 + 0e34d39 commit 02ad795

226 files changed

Lines changed: 8944 additions & 1955 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/samples-dotnet8-client.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ jobs:
1616
matrix:
1717
sample:
1818
- samples/client/petstore/csharp/restsharp/net8/ParameterMappings/
19+
- samples/client/petstore/csharp/restsharp/net8/useVirtualForHooks/
1920
steps:
2021
- uses: actions/checkout@v4
2122
- uses: actions/setup-dotnet@v4.3.0
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Samples OCaml
2+
3+
on:
4+
push:
5+
paths:
6+
- 'samples/client/petstore/ocaml/**'
7+
pull_request:
8+
paths:
9+
- 'samples/client/petstore/ocaml/**'
10+
11+
jobs:
12+
build:
13+
name: Build OCaml
14+
runs-on: ubuntu-latest
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
sample:
19+
- 'samples/client/petstore/ocaml/'
20+
steps:
21+
- uses: actions/checkout@v4
22+
- name: Set-up OCaml
23+
uses: ocaml/setup-ocaml@v3
24+
with:
25+
ocaml-compiler: 5
26+
- name: Install
27+
run: opam install . --deps-only --with-test
28+
working-directory: ${{ matrix.sample }}
29+
- name: Build
30+
run: opam exec -- dune build
31+
working-directory: ${{ matrix.sample }}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# for .net standard
2+
generatorName: csharp
3+
library: restsharp
4+
outputDir: samples/client/petstore/csharp/restsharp/net8/useVirtualForHooks
5+
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore-addpet-only.yaml
6+
templateDir: modules/openapi-generator/src/main/resources/csharp
7+
additionalProperties:
8+
packageGuid: '{D0A67E81-4061-48EB-B4B8-C73BDF8B2D95}'
9+
targetFramework: net8.0
10+
useVirtualForHooks: true

bin/configs/nim.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
generatorName: nim
22
outputDir: samples/client/petstore/nim
3-
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml
3+
inputSpec: modules/openapi-generator/src/test/resources/3_0/nim/petstore.yaml
44
templateDir: modules/openapi-generator/src/main/resources/nim-client
55
additionalProperties:
66
packageName: petstore

docs/customization.md

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ Another useful option is `inlineSchemaOptions`, which allows you to customize ho
504504
- `MAP_ITEM_SUFFIX` set the map item suffix
505505
- `SKIP_SCHEMA_REUSE=true` is a special value to skip reusing inline schemas during refactoring
506506
- `REFACTOR_ALLOF_INLINE_SCHEMAS=true` will restore the 6.x (or below) behaviour to refactor allOf inline schemas into $ref. (v7.0.0 will skip the refactoring of these allOf inline schemas by default)
507-
- `RESOLVE_INLINE_ENUMS=true` will refactor inline enum definitions into $ref
507+
- `RESOLVE_INLINE_ENUMS=true` will refactor inline enum definitions into $ref. This must be activated to allow the renaming of inline enum definitions using `inlineSchemaMappings`.
508508
509509
## OpenAPI Normalizer
510510
@@ -601,11 +601,29 @@ Example:
601601
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -g java -i modules/openapi-generator/src/test/resources/3_0/enableKeepOnlyFirstTagInOperation_test.yaml -o /tmp/java-okhttp/ --openapi-normalizer REMOVE_X_INTERNAL=true
602602
```
603603
604-
- `FILTER`: When set to `operationId:addPet|getPetById` for example, it will add `x-internal:true` to operations with operationId not equal to addPet/getPetById (which will have x-internal set to false) so that these operations marked as internal won't be generated.
604+
- `FILTER`
605605
606-
Example:
607-
```
608-
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -g java -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -o /tmp/java-okhttp/ --openapi-normalizer FILTER="operationId:addPet|getPetById"
606+
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.
607+
608+
### Available Filters
609+
610+
- **`operationId`**
611+
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`.
612+
613+
- **`method`**
614+
When set to `method:get|post`, operations **not** using `GET` or `POST` methods will be marked as internal (`x-internal: true`), preventing their generation.
615+
616+
- **`tag`**
617+
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.
618+
619+
### Example Usage
620+
621+
```sh
622+
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
623+
-g java \
624+
-i modules/openapi-generator/src/test/resources/3_0/petstore.yaml \
625+
-o /tmp/java-okhttp/ \
626+
--openapi-normalizer FILTER="operationId:addPet|getPetById"
609627
```
610628

611629
- `SET_CONTAINER_TO_NULLABLE`: When set to `array|set|map` (or just `array`) for example, it will set `nullable` in array, set and map to true.

docs/generators/csharp.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
5454
|useIntForTimeout|Use int for Timeout (fall back to v7.9.0 templates). This option (for restsharp only) will be deprecated so please migrated to TimeSpan instead.| |false|
5555
|useOneOfDiscriminatorLookup|Use the discriminator's mapping in oneOf to speed up the model lookup. IMPORTANT: Validation (e.g. one and only one match in oneOf's schemas) will be skipped.| |false|
5656
|useSourceGeneration|Use source generation where available (only `generichost` library supports this option).| |false|
57+
|useVirtualForHooks|Generate code that exposes public virtual hooks on ApiClient to customize low-level HTTP requests (only `restsharp`. `httpclient` libraries support this option).| |false|
5758
|validatable|Generates self-validatable models.| |true|
5859
|zeroBasedEnums|Enumerations with string values will start from 0 when true, 1 when false. If not set, enumerations with string values will start from 0 if the first value is 'unknown', case insensitive.| |null|
5960

docs/generators/java-microprofile.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
5252
|errorObjectType|Error Object type. (This option is for okhttp-gson only)| |null|
5353
|failOnUnknownProperties|Fail Jackson de-serialization on unknown properties| |false|
5454
|generateBuilders|Whether to generate builders for models| |false|
55-
|generateClientAsBean|For resttemplate, configure whether to create `ApiClient.java` and Apis clients as bean (with `@Component` annotation).| |false|
55+
|generateClientAsBean|For resttemplate, restclient and webclient, configure whether to create `ApiClient.java` and Apis clients as bean (with `@Component` annotation).| |false|
5656
|generateConstructorWithAllArgs|whether to generate a constructor for all arguments| |false|
5757
|gradleProperties|Append additional Gradle properties to the gradle.properties file| |null|
5858
|groupId|groupId in generated pom.xml| |org.openapitools|

docs/generators/java.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
5252
|errorObjectType|Error Object type. (This option is for okhttp-gson only)| |null|
5353
|failOnUnknownProperties|Fail Jackson de-serialization on unknown properties| |false|
5454
|generateBuilders|Whether to generate builders for models| |false|
55-
|generateClientAsBean|For resttemplate, configure whether to create `ApiClient.java` and Apis clients as bean (with `@Component` annotation).| |false|
55+
|generateClientAsBean|For resttemplate, restclient and webclient, configure whether to create `ApiClient.java` and Apis clients as bean (with `@Component` annotation).| |false|
5656
|generateConstructorWithAllArgs|whether to generate a constructor for all arguments| |false|
5757
|gradleProperties|Append additional Gradle properties to the gradle.properties file| |null|
5858
|groupId|groupId in generated pom.xml| |org.openapitools|

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,9 @@ public static enum ENUM_PROPERTY_NAMING_TYPE {camelCase, PascalCase, snake_case,
286286
public static final String SUPPORTS_ASYNC = "supportsAsync";
287287
public static final String SUPPORTS_ASYNC_DESC = "Generate code that supports async operations.";
288288

289+
public static final String USE_VIRTUAL_FOR_HOOKS = "useVirtualForHooks";
290+
public static final String USE_VIRTUAL_FOR_HOOKS_DESC = "Generate code that exposes public virtual hooks on ApiClient to customize low-level HTTP requests (only `restsharp`. `httpclient` libraries support this option).";
291+
289292
public static final String EXCLUDE_TESTS = "excludeTests";
290293
public static final String EXCLUDE_TESTS_DESC = "Specifies that no tests are to be generated.";
291294

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

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.slf4j.LoggerFactory;
3333

3434
import java.util.*;
35+
import java.util.function.Function;
3536
import java.util.stream.Collectors;
3637

3738
import static org.openapitools.codegen.utils.StringUtils.getUniqueString;
@@ -119,6 +120,9 @@ public class OpenAPINormalizer {
119120
// when set (e.g. operationId:getPetById|addPet), filter out (or remove) everything else
120121
final String FILTER = "FILTER";
121122
HashSet<String> operationIdFilters = new HashSet<>();
123+
HashSet<String> methodFilters = new HashSet<>();
124+
125+
HashSet<String> tagFilters = new HashSet<>();
122126

123127
// when set (e.g. operationId:getPetById|addPet), filter out (or remove) everything else
124128
final String SET_CONTAINER_TO_NULLABLE = "SET_CONTAINER_TO_NULLABLE";
@@ -238,15 +242,25 @@ public void processRules(Map<String, String> inputRules) {
238242

239243
String[] filterStrs = inputRules.get(FILTER).split(":");
240244
if (filterStrs.length != 2) { // only support operationId with : at the moment
241-
LOGGER.error("FILTER rule must be in the form of `operationId:name1|name2|name3`: {}", inputRules.get(FILTER));
245+
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));
242246
} else {
243247
if ("operationId".equals(filterStrs[0])) {
244248
operationIdFilters = Arrays.stream(filterStrs[1].split("[|]"))
245249
.filter(Objects::nonNull)
246250
.map(String::trim)
247251
.collect(Collectors.toCollection(HashSet::new));
252+
} else if ("method".equals(filterStrs[0])) {
253+
methodFilters = Arrays.stream(filterStrs[1].split("[|]"))
254+
.filter(Objects::nonNull)
255+
.map(String::trim)
256+
.collect(Collectors.toCollection(HashSet::new));
257+
} else if ("tag".equals(filterStrs[0])) {
258+
tagFilters = Arrays.stream(filterStrs[1].split("[|]"))
259+
.filter(Objects::nonNull)
260+
.map(String::trim)
261+
.collect(Collectors.toCollection(HashSet::new));
248262
} else {
249-
LOGGER.error("FILTER rule must be in the form of `operationId:name1|name2|name3`: {}", inputRules.get(FILTER));
263+
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));
250264
}
251265
}
252266
}
@@ -338,6 +352,27 @@ private void normalizePaths() {
338352
PathItem path = pathsEntry.getValue();
339353
List<Operation> operations = new ArrayList<>(path.readOperations());
340354

355+
Map<String, Function<PathItem, Operation>> methodMap = Map.of(
356+
"get", PathItem::getGet,
357+
"put", PathItem::getPut,
358+
"head", PathItem::getHead,
359+
"post", PathItem::getPost,
360+
"delete", PathItem::getDelete,
361+
"patch", PathItem::getPatch,
362+
"options", PathItem::getOptions,
363+
"trace", PathItem::getTrace
364+
);
365+
366+
// Iterates over each HTTP method in methodMap, retrieves the corresponding Operation from the PathItem,
367+
// and marks it as internal (`x-internal`) if the method is not in methodFilters.
368+
methodMap.forEach((method, getter) -> {
369+
Operation operation = getter.apply(path);
370+
if (operation != null && !methodFilters.isEmpty()) {
371+
LOGGER.info("operation `{}` marked internal only (x-internal: `{}`) by the method FILTER", operation.getOperationId(), !methodFilters.contains(method));
372+
operation.addExtension("x-internal", !methodFilters.contains(method));
373+
}
374+
});
375+
341376
// Include callback operation as well
342377
for (Operation operation : path.readOperations()) {
343378
Map<String, Callback> callbacks = operation.getCallbacks();
@@ -357,7 +392,14 @@ private void normalizePaths() {
357392
if (operationIdFilters.contains(operation.getOperationId())) {
358393
operation.addExtension("x-internal", false);
359394
} else {
360-
LOGGER.info("operation `{}` marked as internal only (x-internal: true) by the FILTER", operation.getOperationId());
395+
LOGGER.info("operation `{}` marked as internal only (x-internal: true) by the operationId FILTER", operation.getOperationId());
396+
operation.addExtension("x-internal", true);
397+
}
398+
} else if (!tagFilters.isEmpty()) {
399+
if (operation.getTags().stream().anyMatch(tagFilters::contains)) {
400+
operation.addExtension("x-internal", false);
401+
} else {
402+
LOGGER.info("operation `{}` marked as internal only (x-internal: true) by the tag FILTER", operation.getOperationId());
361403
operation.addExtension("x-internal", true);
362404
}
363405
}

0 commit comments

Comments
 (0)