Skip to content

Commit 15ab408

Browse files
authored
Merge branch 'OpenAPITools:master' into master
2 parents 605250f + 21bf477 commit 15ab408

File tree

128 files changed

+316
-276
lines changed

Some content is hidden

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

128 files changed

+316
-276
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation
427427
for (CodegenParameter param : op.pathParams) {
428428
// Replace {baseName} with {paramName} for format string
429429
String paramSearch = "{" + param.baseName + "}";
430-
String paramReplace = ":" + param.paramName;
430+
String paramReplace = "{" + param.paramName + "}";
431431

432432
axumPath = axumPath.replace(paramSearch, paramReplace);
433433
}

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

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,10 @@
3838
import org.openapitools.codegen.CodegenConstants;
3939
import org.openapitools.codegen.CodegenModel;
4040
import org.openapitools.codegen.CodegenOperation;
41-
import org.openapitools.codegen.CodegenProperty;
4241
import org.openapitools.codegen.CodegenParameter;
42+
import org.openapitools.codegen.CodegenProperty;
4343
import org.openapitools.codegen.CodegenType;
4444
import org.openapitools.codegen.SupportingFile;
45-
import org.openapitools.codegen.VendorExtension;
4645
import org.openapitools.codegen.meta.features.ClientModificationFeature;
4746
import org.openapitools.codegen.meta.features.DocumentationFeature;
4847
import org.openapitools.codegen.meta.features.GlobalFeature;
@@ -109,6 +108,10 @@ public class RustClientCodegen extends AbstractRustCodegen implements CodegenCon
109108
protected String modelDocPath = "docs/";
110109
protected String apiFolder = "src/apis";
111110
protected String modelFolder = "src/models";
111+
// The API has at least one UUID type.
112+
// If the API does not contain any UUIDs we do not need depend on the `uuid` crate
113+
private boolean hasUUIDs = false;
114+
112115

113116
@Override
114117
public CodegenType getTag() {
@@ -253,6 +256,7 @@ public RustClientCodegen() {
253256
supportedLibraries.put(REQWEST_LIBRARY, "HTTP client: Reqwest.");
254257
supportedLibraries.put(REQWEST_TRAIT_LIBRARY, "HTTP client: Reqwest (trait based).");
255258

259+
256260
CliOption libraryOption = new CliOption(CodegenConstants.LIBRARY, "library template (sub-template) to use.");
257261
libraryOption.setEnum(supportedLibraries);
258262
// set reqwest as the default
@@ -642,6 +646,13 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
642646
}
643647
}
644648

649+
for (var param : operation.allParams) {
650+
if (!hasUUIDs && param.isUuid) {
651+
hasUUIDs = true;
652+
break;
653+
}
654+
}
655+
645656
// http method verb conversion, depending on client library (e.g. Hyper: PUT => Put, Reqwest: PUT => put)
646657
if (HYPER_LIBRARY.equals(getLibrary())) {
647658
operation.httpMethod = StringUtils.camelize(operation.httpMethod.toLowerCase(Locale.ROOT));
@@ -705,9 +716,43 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
705716
}*/
706717
}
707718

719+
if (!hasUUIDs) {
720+
for (var map : allModels) {
721+
CodegenModel m = map.getModel();
722+
if (m.getIsUuid() || hasUuidInProperties(m.vars)) {
723+
hasUUIDs = true;
724+
LOGGER.debug("found UUID in model: " + m.name);
725+
break;
726+
}
727+
}
728+
}
729+
730+
this.additionalProperties.put("hasUUIDs", hasUUIDs);
708731
return objs;
709732
}
710733

734+
/**
735+
* Recursively searches for a model's properties for a UUID type field.
736+
*/
737+
private boolean hasUuidInProperties(List<CodegenProperty> properties) {
738+
for (CodegenProperty property : properties) {
739+
if (property.isUuid) {
740+
return true;
741+
}
742+
// Check nested properties
743+
if (property.items != null && hasUuidInProperties(Collections.singletonList(property.items))) {
744+
return true;
745+
}
746+
if (property.additionalProperties != null && hasUuidInProperties(Collections.singletonList(property.additionalProperties))) {
747+
return true;
748+
}
749+
if (property.vars != null && hasUuidInProperties(property.vars)) {
750+
return true;
751+
}
752+
}
753+
return false;
754+
}
755+
711756
@Override
712757
public String toDefaultValue(Schema p) {
713758
if (p.getDefault() != null) {

modules/openapi-generator/src/main/resources/JavaSpring/pojo.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public class {{classname}}{{#parent}} extends {{{parent}}}{{/parent}}{{^parent}}
156156
{{! begin feature: fluent setter methods }}
157157
public {{classname}} {{name}}({{{datatypeWithEnum}}} {{name}}) {
158158
{{#openApiNullable}}
159-
this.{{name}} = {{#isNullable}}JsonNullable.of({{/isNullable}}{{#useOptional}}{{^required}}{{^isNullable}}{{^isContainer}}Optional.of({{/isContainer}}{{/isNullable}}{{/required}}{{/useOptional}}{{name}}{{#isNullable}}){{/isNullable}}{{#useOptional}}{{^required}}{{^isNullable}}{{^isContainer}}){{/isContainer}}{{/isNullable}}{{/required}}{{/useOptional}};
159+
this.{{name}} = {{#isNullable}}JsonNullable.of({{/isNullable}}{{#useOptional}}{{^required}}{{^isNullable}}{{^isContainer}}Optional.ofNullable({{/isContainer}}{{/isNullable}}{{/required}}{{/useOptional}}{{name}}{{#isNullable}}){{/isNullable}}{{#useOptional}}{{^required}}{{^isNullable}}{{^isContainer}}){{/isContainer}}{{/isNullable}}{{/required}}{{/useOptional}};
160160
{{/openApiNullable}}
161161
{{^openApiNullable}}
162162
this.{{name}} = {{name}};

modules/openapi-generator/src/main/resources/dart/libraries/dio/pubspec.mustache

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,26 @@ repository: {{.}}
99
publish_to: {{.}}
1010
{{/pubPublishTo}}
1111

12+
1213
environment:
13-
sdk: '>={{#useJsonSerializable}}2.17.0{{/useJsonSerializable}}{{^useJsonSerializable}}2.15.0{{/useJsonSerializable}} <4.0.0'
14+
sdk: '>={{^useJsonSerializable}}2.18.0{{/useJsonSerializable}}{{#useJsonSerializable}}3.5.0{{/useJsonSerializable}} <4.0.0'
1415
1516
dependencies:
16-
dio: '^5.2.0'
17+
dio: '^5.7.0'
1718
{{#useBuiltValue}}
1819
one_of: '>=1.5.0 <2.0.0'
1920
one_of_serializer: '>=1.5.0 <2.0.0'
2021
built_value: '>=8.4.0 <9.0.0'
2122
built_collection: '>=5.1.1 <6.0.0'
2223
{{/useBuiltValue}}
2324
{{#useEquatable}}
24-
equatable: '^2.0.5'
25+
equatable: '^2.0.7'
2526
{{/useEquatable}}
2627
{{#useJsonSerializable}}
27-
json_annotation: '^4.4.0'
28+
json_annotation: '^4.9.0'
2829
{{/useJsonSerializable}}
2930
{{#useDateLibTimeMachine}}
30-
time_machine: ^0.9.16
31+
time_machine: ^0.9.17
3132
{{/useDateLibTimeMachine}}
3233
3334
dev_dependencies:
@@ -37,6 +38,6 @@ dev_dependencies:
3738
{{/useBuiltValue}}
3839
{{#useJsonSerializable}}
3940
build_runner: any
40-
json_serializable: '^6.1.5'
41+
json_serializable: '^6.9.3'
4142
{{/useJsonSerializable}}
42-
test: ^1.16.0
43+
test: '^1.16.0'

modules/openapi-generator/src/main/resources/rust-axum/Cargo.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ conversion = [
4040

4141
[dependencies]
4242
async-trait = "0.1"
43-
axum = "0.7"
44-
axum-extra = { version = "0.9", features = ["cookie", "multipart"] }
43+
axum = { version = "0.8", features = ["multipart"] }
44+
axum-extra = { version = "0.10", features = ["cookie"] }
4545
base64 = "0.22"
4646
bytes = "1"
4747
chrono = { version = "0.4", features = ["serde"] }

modules/openapi-generator/src/main/resources/rust-axum/apis-mod.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub trait ErrorHandler<E: std::fmt::Debug + Send + Sync + 'static = ()> {
3737
async fn handle_error(
3838
&self,
3939
method: &::http::Method,
40-
host: &axum::extract::Host,
40+
host: &axum_extra::extract::Host,
4141
cookies: &axum_extra::extract::CookieJar,
4242
error: E
4343
) -> Result<axum::response::Response, http::StatusCode> {
@@ -47,4 +47,4 @@ pub trait ErrorHandler<E: std::fmt::Debug + Send + Sync + 'static = ()> {
4747
.body(axum::body::Body::empty())
4848
.map_err(|_| http::StatusCode::INTERNAL_SERVER_ERROR)
4949
}
50-
}
50+
}

modules/openapi-generator/src/main/resources/rust-axum/apis.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use async_trait::async_trait;
22
use axum::extract::*;
3-
use axum_extra::extract::{CookieJar, Multipart};
3+
use axum_extra::extract::{CookieJar, Host};
44
use bytes::Bytes;
55
use http::Method;
66
use serde::{Deserialize, Serialize};

modules/openapi-generator/src/main/resources/rust-axum/server-imports.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::collections::HashMap;
22

33
use axum::{body::Body, extract::*, response::Response, routing::*};
4-
use axum_extra::extract::{CookieJar, Multipart};
4+
use axum_extra::extract::{CookieJar, Host};
55
use bytes::Bytes;
66
use http::{header::CONTENT_TYPE, HeaderMap, HeaderName, HeaderValue, Method, StatusCode};
77
use tracing::error;

modules/openapi-generator/src/main/resources/rust/Cargo.mustache

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ serde_with = { version = "^3.8", default-features = false, features = ["base64",
3939
serde_json = "^1.0"
4040
serde_repr = "^0.1"
4141
url = "^2.5"
42+
{{#hasUUIDs}}
4243
uuid = { version = "^1.8", features = ["serde", "v4"] }
44+
{{/hasUUIDs}}
4345
{{#hyper}}
4446
{{#hyper0x}}
4547
hyper = { version = "~0.14", features = ["full"] }

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ public void doAnnotateDatesOnModelParametersWithOptionalAndJsonNullable() throws
228228
.containsWithNameAndAttributes("DateTimeFormat", ImmutableMap.of("iso", "DateTimeFormat.ISO.DATE_TIME"))
229229
.toProperty().toType()
230230
.assertMethod("born", "LocalDate")
231-
.bodyContainsLines("this.born = Optional.of(born)")
231+
.bodyContainsLines("this.born = Optional.ofNullable(born)")
232232
.doesNotHaveComment();
233233
}
234234

@@ -4397,9 +4397,10 @@ private void assertJsonNullableMethod(JavaFileAssert javaFileAssert, String type
43974397

43984398
private void assertWrapperMethod(JavaFileAssert javaFileAssert, String wrapperType, String type, String expectedName, String getterReturnType){
43994399
String methodName = StringUtils.capitalize(expectedName);
4400+
var of = wrapperType.equals("Optional") ? "ofNullable" : "of";
44004401
javaFileAssert.assertMethod(expectedName)
44014402
.hasReturnType("Animal")
4402-
.bodyContainsLines("this."+expectedName+" = "+wrapperType+".of("+expectedName+");", "return this;")
4403+
.bodyContainsLines("this." + expectedName + " = "+wrapperType+ "." + of + "(" +expectedName+");", "return this;")
44034404
.assertParameter(expectedName)
44044405
.hasType(type)
44054406
.toMethod()

0 commit comments

Comments
 (0)