Skip to content

Commit ba281f4

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 6408374 + 74e49ac commit ba281f4

116 files changed

Lines changed: 701 additions & 367 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.
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 }}

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/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/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
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ public JavaClientCodegen() {
238238
cliOptions.add(CliOption.newString(MICROPROFILE_REST_CLIENT_VERSION, "Version of MicroProfile Rest Client API."));
239239
cliOptions.add(CliOption.newString(CodegenConstants.USE_SINGLE_REQUEST_PARAMETER, "Setting this property to \"true\" will generate functions with a single argument containing all API endpoint parameters instead of one argument per parameter. ONLY jersey2, jersey3, okhttp-gson, microprofile, Spring RestClient, Spring WebClient support this option. Setting this property to \"static\" does the same as \"true\", but also makes the generated arguments class static with single parameter instantiation.").defaultValue("false"));
240240
cliOptions.add(CliOption.newBoolean(WEBCLIENT_BLOCKING_OPERATIONS, "Making all WebClient operations blocking(sync). Note that if on operation 'x-webclient-blocking: false' then such operation won't be sync", this.webclientBlockingOperations));
241-
cliOptions.add(CliOption.newBoolean(GENERATE_CLIENT_AS_BEAN, "For resttemplate, configure whether to create `ApiClient.java` and Apis clients as bean (with `@Component` annotation).", this.generateClientAsBean));
241+
cliOptions.add(CliOption.newBoolean(GENERATE_CLIENT_AS_BEAN, "For resttemplate, restclient and webclient, configure whether to create `ApiClient.java` and Apis clients as bean (with `@Component` annotation).", this.generateClientAsBean));
242242
cliOptions.add(CliOption.newBoolean(SUPPORT_URL_QUERY, "Generate toUrlQueryString in POJO (default to true). Available on `native`, `apache-httpclient` libraries."));
243243
cliOptions.add(CliOption.newBoolean(USE_ENUM_CASE_INSENSITIVE, "Use `equalsIgnoreCase` when String for enum comparison", useEnumCaseInsensitive));
244244
cliOptions.add(CliOption.newBoolean(FAIL_ON_UNKNOWN_PROPERTIES, "Fail Jackson de-serialization on unknown properties", this.failOnUnknownProperties));
@@ -1113,7 +1113,7 @@ public ModelsMap postProcessModels(ModelsMap objs) {
11131113
cm.anyOf.remove("ModelNull");
11141114
}
11151115
}
1116-
if (this.parcelableModel) {
1116+
if (this.parcelableModel && !cm.isEnum) {
11171117
((ArrayList<String>) cm.getVendorExtensions().get("x-implements")).add("Parcelable");
11181118
}
11191119
}

modules/openapi-generator/src/main/resources/Java/libraries/microprofile/enumClass.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
@JsonbTypeDeserializer({{datatypeWithEnum}}.Deserializer.class)
99
{{/jsonb}}
1010
{{/withXml}}
11-
{{>additionalEnumTypeAnnotations}}public enum {{datatypeWithEnum}} {
11+
{{>additionalEnumTypeAnnotations}}public enum {{datatypeWithEnum}}{{#vendorExtensions.x-implements}}{{#-first}} implements {{{.}}}{{/-first}}{{^-first}}, {{{.}}}{{/-first}}{{/vendorExtensions.x-implements}} {
1212
1313
{{#allowableValues}}
1414
{{#withXml}}

modules/openapi-generator/src/main/resources/Java/libraries/microprofile/enumOuterClass.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import java.net.URI;
1313
@JsonbTypeSerializer({{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}.Serializer.class)
1414
@JsonbTypeDeserializer({{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}.Deserializer.class)
1515
{{/jsonb}}
16-
{{>additionalEnumTypeAnnotations}}public enum {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} {
16+
{{>additionalEnumTypeAnnotations}}public enum {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}{{#vendorExtensions.x-implements}}{{#-first}} implements {{{.}}}{{/-first}}{{^-first}}, {{{.}}}{{/-first}}{{/vendorExtensions.x-implements}} {
1717
{{#gson}}
1818
{{#allowableValues}}{{#enumVars}}
1919
@SerializedName({{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}}{{{value}}}{{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}})

modules/openapi-generator/src/main/resources/Java/libraries/native/modelEnum.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import java.net.URI;
2323
@JsonbTypeSerializer({{datatypeWithEnum}}.Serializer.class)
2424
@JsonbTypeDeserializer({{datatypeWithEnum}}.Deserializer.class)
2525
{{/jsonb}}
26-
{{>additionalEnumTypeAnnotations}}public enum {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} {
26+
{{>additionalEnumTypeAnnotations}}public enum {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}{{#vendorExtensions.x-implements}}{{#-first}} implements {{{.}}}{{/-first}}{{^-first}}, {{{.}}}{{/-first}}{{/vendorExtensions.x-implements}} {
2727
{{#allowableValues}}{{#enumVars}}
2828
{{#enumDescription}}
2929
/**

modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/modelEnum.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import com.google.gson.stream.JsonWriter;
1212
* {{description}}{{^description}}Gets or Sets {{{name}}}{{/description}}
1313
*/
1414
@JsonAdapter({{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}.Adapter.class)
15-
{{>additionalEnumTypeAnnotations}}public enum {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} {
15+
{{>additionalEnumTypeAnnotations}}public enum {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}{{#vendorExtensions.x-implements}}{{#-first}} implements {{{.}}}{{/-first}}{{^-first}}, {{{.}}}{{/-first}}{{/vendorExtensions.x-implements}} {
1616
{{#allowableValues}}{{#enumVars}}
1717
{{#enumDescription}}
1818
/**

0 commit comments

Comments
 (0)