Skip to content

Commit da0c6b0

Browse files
committed
Merge branch 'master' into feature/kotlin-spring-useDeductionForOneOfInterfaces
2 parents d9575e4 + 1e60f43 commit da0c6b0

71 files changed

Lines changed: 2974 additions & 77 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.

bin/configs/csharp-restsharp-net4.7-multipleFrameworks.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ additionalProperties:
88
targetFramework: netstandard2.1;net47
99
useCompareNetObjects: "true"
1010
equatable: true
11+
throwOnAnyError: true

bin/utils/test_file_list.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
- filename: "samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/ClientTest.java"
1111
sha256: 325fdd5d7e2c97790c0fb44f712ab7b2ba022d7e1a5b0056f47b07f342682b6d
1212
- filename: "samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/JSONTest.java"
13-
sha256: b1b1d31e0df17f0b68cf2747a4a53879f12acb1bf2860e45385c679c1efe9894
13+
sha256: 074f090e5df50448f3309af83ce30690cd50c83d3675e555de7d359f42d26020
1414
- filename: "samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/api/PetApiTest.java"
1515
sha256: 8b1b8f2a2ad00ccb090873a94a5f73e328b98317d2ec715f53bd7a1accb2a023
1616
- filename: "samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/PetTest.java"

docs/generators/csharp.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
4747
|returnICollection|Return ICollection<T> instead of the concrete type.| |false|
4848
|sourceFolder|source folder for generated code| |src|
4949
|targetFramework|The target .NET framework version. To target multiple frameworks, use `;` as the separator, e.g. `netstandard2.1;netcoreapp3.1`|<dl><dt>**netstandard1.3**</dt><dd>.NET Standard 1.3</dd><dt>**netstandard1.4**</dt><dd>.NET Standard 1.4</dd><dt>**netstandard1.5**</dt><dd>.NET Standard 1.5</dd><dt>**netstandard1.6**</dt><dd>.NET Standard 1.6</dd><dt>**netstandard2.0**</dt><dd>.NET Standard 2.0</dd><dt>**netstandard2.1**</dt><dd>.NET Standard 2.1</dd><dt>**net47**</dt><dd>.NET Framework 4.7</dd><dt>**net48**</dt><dd>.NET Framework 4.8</dd><dt>**net8.0**</dt><dd>.NET 8.0 (End of Support 10 November 2026)</dd><dt>**net9.0**</dt><dd>.NET 9.0 (End of Support 10 November 2026)</dd><dt>**net10.0**</dt><dd>.NET 10.0 (End of Support 14 November 2028)</dd></dl>|net10.0|
50+
|throwOnAnyError|Configure RestSharp to rethrow deserialization and transport errors instead of swallowing them into RestResponse.ErrorException (which the default ToApiResponse&lt;T&gt; discards as null Data). Recommended for production use to surface bugs that would otherwise be invisible. (restsharp only)| |false|
5051
|useCollection|Deserialize array types to Collection&lt;T&gt; instead of List&lt;T&gt;.| |false|
5152
|useDateTimeForDate|Use DateTime to model date properties even if DateOnly supported. (.net 6.0+ only)| |false|
5253
|useDateTimeOffset|Use DateTimeOffset to model date-time properties| |false|

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,7 @@ public void processOpts() {
672672
additionalProperties.put("jsr310", "true");
673673
typeMapping.put("date", "LocalDate");
674674
importMapping.put("LocalDate", "java.time.LocalDate");
675+
typeMapping.put("time-local","LocalTime");
675676
importMapping.put("LocalTime", "java.time.LocalTime");
676677
if ("java8-localdatetime".equals(dateLibrary)) {
677678
typeMapping.put("DateTime", "LocalDateTime");
@@ -1442,6 +1443,13 @@ public String toDefaultValue(CodegenProperty cp, Schema schema) {
14421443
return "URI.create(\"" + escapeText(String.valueOf(schema.getDefault())) + "\")";
14431444
}
14441445
return null;
1446+
} else if (ModelUtils.isTimeLocalSchema(schema)) {
1447+
if (schema.getDefault() != null) {
1448+
if ("java8".equals(getDateLibrary())) {
1449+
return String.format(Locale.ROOT, "LocalTime.parse(\"%s\")", schema.getDefault());
1450+
}
1451+
}
1452+
return null;
14451453
} else if (ModelUtils.isStringSchema(schema)) {
14461454
if (schema.getDefault() != null) {
14471455
String _default;
@@ -1524,6 +1532,10 @@ public String toDefaultValue(CodegenProperty cp, Schema schema) {
15241532
value.asText(),
15251533
"java.time.format.DateTimeFormatter.ISO_ZONED_DATE_TIME.withZone(java.time.ZoneId.systemDefault())");
15261534
}
1535+
} else if(ModelUtils.isTimeLocalSchema(propertySchema)) {
1536+
if("java8".equals(getDateLibrary())) {
1537+
defaultPropertyExpression = String.format(Locale.ROOT, "java.time.LocalTime.parse(\"%s\")", value.asText());
1538+
}
15271539
} else if(ModelUtils.isUUIDSchema(propertySchema)) {
15281540
defaultPropertyExpression = "java.util.UUID.fromString(\"" + value.asText() + "\")";
15291541
} else if(ModelUtils.isStringSchema(propertySchema)) {

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
122122
protected boolean supportsFileParameters = Boolean.TRUE;
123123
protected boolean supportsDateOnly = Boolean.FALSE;
124124
protected boolean useIntForTimeout = Boolean.FALSE;
125+
protected boolean throwOnAnyError = Boolean.FALSE;
125126

126127
@Setter protected boolean validatable = Boolean.TRUE;
127128
@Setter protected boolean equatable = Boolean.FALSE;
@@ -132,6 +133,7 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
132133
private static final String OPERATION_PARAMETER_SORTING_KEY = "operationParameterSorting";
133134
private static final String MODEL_PROPERTY_SORTING_KEY = "modelPropertySorting";
134135
private static final String USE_INT_FOR_TIMEOUT = "useIntForTimeout";
136+
private static final String THROW_ON_ANY_ERROR = "throwOnAnyError";
135137

136138
enum SortingMethod {
137139
DEFAULT,
@@ -249,6 +251,10 @@ public CSharpClientCodegen() {
249251
"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.",
250252
String.valueOf(this.useIntForTimeout));
251253

254+
addSwitch(CSharpClientCodegen.THROW_ON_ANY_ERROR,
255+
"Configure RestSharp to rethrow deserialization and transport errors instead of swallowing them into RestResponse.ErrorException (which the default ToApiResponse<T> discards as null Data). Recommended for production use to surface bugs that would otherwise be invisible. (restsharp only)",
256+
this.throwOnAnyError);
257+
252258
CliOption framework = new CliOption(
253259
CodegenConstants.DOTNET_FRAMEWORK,
254260
CodegenConstants.DOTNET_FRAMEWORK_DESC
@@ -871,6 +877,7 @@ public void processOpts() {
871877
syncBooleanProperty(additionalProperties, "useSourceGeneration", this::setUseSourceGeneration, this.useSourceGeneration);
872878
syncBooleanProperty(additionalProperties, "supportsDateOnly", this::setSupportsDateOnly, this.supportsDateOnly);
873879
syncBooleanProperty(additionalProperties, "useIntForTimeout", this::setUseIntForTimeout, this.useIntForTimeout);
880+
syncBooleanProperty(additionalProperties, "throwOnAnyError", this::setThrowOnAnyError, this.throwOnAnyError);
874881

875882
final String testPackageName = testPackageName();
876883
String packageFolder = sourceFolder + File.separator + packageName;
@@ -1244,6 +1251,10 @@ public void setUseIntForTimeout(Boolean useIntForTimeout) {
12441251
this.useIntForTimeout = useIntForTimeout;
12451252
}
12461253

1254+
public void setThrowOnAnyError(Boolean throwOnAnyError) {
1255+
this.throwOnAnyError = throwOnAnyError;
1256+
}
1257+
12471258
public void setSupportsRetry(Boolean supportsRetry) {
12481259
this.supportsRetry = supportsRetry;
12491260
}

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,23 @@ public ModelsMap postProcessModels(ModelsMap objs) {
343343
public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<ModelMap> allModels) {
344344
objs = super.postProcessOperationsWithModels(objs, allModels);
345345
removeImport(objs, "java.util.List");
346+
if (QUARKUS_LIBRARY.equals(library) && !returnResponse && !returnJbossResponse && useJakartaEe) {
347+
for (CodegenOperation op : objs.getOperations().getOperation()) {
348+
op.responses.stream()
349+
.filter(r -> r.is2xx && r.code.matches("\\d+"))
350+
.findFirst()
351+
.ifPresent(r -> op.vendorExtensions.put("x-java-success-response-code", r.code));
352+
}
353+
boolean hasAnnotations = objs.getOperations().getOperation().stream()
354+
.anyMatch(op -> op.vendorExtensions.containsKey("x-java-success-response-code"));
355+
// Always set explicitly so Mustache does not fall through to the global additionalProperties
356+
// value when this file has no annotated operations.
357+
objs.put("hasResponseStatusAnnotations", hasAnnotations);
358+
if (hasAnnotations) {
359+
// Global flag used by pom.mustache, which is rendered once per project.
360+
additionalProperties.put("hasResponseStatusAnnotations", true);
361+
}
362+
}
346363
return objs;
347364
}
348365

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,12 @@ public static boolean isDateTimeSchema(Schema schema) {
715715
&& SchemaTypeUtil.DATE_TIME_FORMAT.equals(schema.getFormat()));
716716
}
717717

718+
public static boolean isTimeLocalSchema(Schema schema) {
719+
// format: time-local, see https://spec.openapis.org/registry/format/time-local.html
720+
return (SchemaTypeUtil.STRING_TYPE.equals(getType(schema))
721+
&& "time-local".equals(schema.getFormat()));
722+
}
723+
718724
public static boolean isPasswordSchema(Schema schema) {
719725
return (schema instanceof PasswordSchema) ||
720726
// double

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
434434
}
435435
{{/isString}}
436436
{{#isModel}}
437+
{{^isEnum}}
437438
{{#required}}
438439
{{#isNullable}}
439440
if (jsonObj.get("{{{baseName}}}") != null && !jsonObj.get("{{{baseName}}}").isJsonNull()) {
@@ -450,6 +451,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
450451
{{{dataType}}}.validateJsonElement(jsonObj.get("{{{baseName}}}"));
451452
}
452453
{{/required}}
454+
{{/isEnum}}
453455
{{/isModel}}
454456
{{#isEnum}}
455457
{{#required}}

modules/openapi-generator/src/main/resources/JavaJaxRS/spec/libraries/quarkus/api.mustache

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,14 @@ package {{package}};
55

66
import {{javaxPackage}}.ws.rs.*;
77
import {{javaxPackage}}.ws.rs.core.Response;
8-
{{#returnJBossResponse}}import org.jboss.resteasy.reactive.RestResponse;{{/returnJBossResponse}}
9-
8+
{{#returnJBossResponse}}
9+
import org.jboss.resteasy.reactive.RestResponse;
10+
{{/returnJBossResponse}}
11+
{{#interfaceOnly}}
12+
{{#hasResponseStatusAnnotations}}
13+
import org.jboss.resteasy.reactive.ResponseStatus;
14+
{{/hasResponseStatusAnnotations}}
15+
{{/interfaceOnly}}
1016
{{#useGzipFeature}}
1117
import org.jboss.resteasy.annotations.GZIP;
1218
{{/useGzipFeature}}
@@ -34,8 +40,10 @@ import java.util.concurrent.CompletableFuture;
3440
import java.io.InputStream;
3541
import java.util.Map;
3642
import java.util.List;
37-
{{#useBeanValidation}}import {{javaxPackage}}.validation.constraints.*;
38-
import {{javaxPackage}}.validation.Valid;{{/useBeanValidation}}
43+
{{#useBeanValidation}}
44+
import {{javaxPackage}}.validation.constraints.*;
45+
import {{javaxPackage}}.validation.Valid;
46+
{{/useBeanValidation}}
3947

4048
{{#useMicroProfileOpenAPIAnnotations}}@org.eclipse.microprofile.openapi.annotations.OpenAPIDefinition(
4149
info = @org.eclipse.microprofile.openapi.annotations.info.Info(
@@ -116,4 +124,4 @@ public {{#interfaceOnly}}interface{{/interfaceOnly}}{{^interfaceOnly}}class{{/in
116124
{{#interfaceOnly}}{{>apiInterface}}{{/interfaceOnly}}{{^interfaceOnly}}{{>apiMethod}}{{/interfaceOnly}}
117125
{{/operation}}
118126
}
119-
{{/operations}}
127+
{{/operations}}

modules/openapi-generator/src/main/resources/JavaJaxRS/spec/libraries/quarkus/apiInterface.mustache

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,7 @@
5050
{{^vendorExtensions.x-java-is-response-void}}@org.eclipse.microprofile.openapi.annotations.media.Content(schema = @org.eclipse.microprofile.openapi.annotations.media.Schema(implementation = {{{baseType}}}.class{{#vendorExtensions.x-microprofile-open-api-return-schema-container}}, type = {{{.}}} {{/vendorExtensions.x-microprofile-open-api-return-schema-container}}{{#vendorExtensions.x-microprofile-open-api-return-unique-items}}, uniqueItems = true {{/vendorExtensions.x-microprofile-open-api-return-unique-items}})){{/vendorExtensions.x-java-is-response-void}}
5151
}){{^-last}},{{/-last}}{{/responses}}
5252
}){{/hasProduces}}{{/useMicroProfileOpenAPIAnnotations}}
53-
{{#supportAsync}}{{>returnAsyncTypeInterface}}{{/supportAsync}}{{^supportAsync}}{{#returnJBossResponse}}{{>returnResponseTypeInterface}}{{/returnJBossResponse}}{{^returnJBossResponse}}{{#returnResponse}}Response{{/returnResponse}}{{^returnResponse}}{{>returnTypeInterface}}{{/returnResponse}}{{/returnJBossResponse}}{{/supportAsync}} {{nickname}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>cookieParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{^-last}},{{/-last}}{{/allParams}});
53+
{{#vendorExtensions.x-java-success-response-code}}
54+
@ResponseStatus({{{vendorExtensions.x-java-success-response-code}}})
55+
{{/vendorExtensions.x-java-success-response-code}}
56+
{{#supportAsync}}{{>returnAsyncTypeInterface}}{{/supportAsync}}{{^supportAsync}}{{#returnJBossResponse}}{{>returnResponseTypeInterface}}{{/returnJBossResponse}}{{^returnJBossResponse}}{{#returnResponse}}Response{{/returnResponse}}{{^returnResponse}}{{>returnTypeInterface}}{{/returnResponse}}{{/returnJBossResponse}}{{/supportAsync}} {{nickname}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>cookieParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{^-last}},{{/-last}}{{/allParams}});

0 commit comments

Comments
 (0)