diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustClientCodegen.java index 3f8ba7bb3b5..9a287f7a3fd 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustClientCodegen.java @@ -38,11 +38,10 @@ import org.openapitools.codegen.CodegenConfig; import org.openapitools.codegen.CodegenConstants; import org.openapitools.codegen.CodegenModel; import org.openapitools.codegen.CodegenOperation; -import org.openapitools.codegen.CodegenProperty; import org.openapitools.codegen.CodegenParameter; +import org.openapitools.codegen.CodegenProperty; import org.openapitools.codegen.CodegenType; import org.openapitools.codegen.SupportingFile; -import org.openapitools.codegen.VendorExtension; import org.openapitools.codegen.meta.features.ClientModificationFeature; import org.openapitools.codegen.meta.features.DocumentationFeature; import org.openapitools.codegen.meta.features.GlobalFeature; @@ -109,6 +108,10 @@ public class RustClientCodegen extends AbstractRustCodegen implements CodegenCon protected String modelDocPath = "docs/"; protected String apiFolder = "src/apis"; protected String modelFolder = "src/models"; + // The API has at least one UUID type. + // If the API does not contain any UUIDs we do not need depend on the `uuid` crate + private boolean hasUUIDs = false; + @Override public CodegenType getTag() { @@ -253,6 +256,7 @@ public class RustClientCodegen extends AbstractRustCodegen implements CodegenCon supportedLibraries.put(REQWEST_LIBRARY, "HTTP client: Reqwest."); supportedLibraries.put(REQWEST_TRAIT_LIBRARY, "HTTP client: Reqwest (trait based)."); + CliOption libraryOption = new CliOption(CodegenConstants.LIBRARY, "library template (sub-template) to use."); libraryOption.setEnum(supportedLibraries); // set reqwest as the default @@ -642,6 +646,13 @@ public class RustClientCodegen extends AbstractRustCodegen implements CodegenCon } } + for (var param : operation.allParams) { + if (!hasUUIDs && param.isUuid) { + hasUUIDs = true; + break; + } + } + // http method verb conversion, depending on client library (e.g. Hyper: PUT => Put, Reqwest: PUT => put) if (HYPER_LIBRARY.equals(getLibrary())) { operation.httpMethod = StringUtils.camelize(operation.httpMethod.toLowerCase(Locale.ROOT)); @@ -705,9 +716,43 @@ public class RustClientCodegen extends AbstractRustCodegen implements CodegenCon }*/ } + if (!hasUUIDs) { + for (var map : allModels) { + CodegenModel m = map.getModel(); + if (m.getIsUuid() || hasUuidInProperties(m.vars)) { + hasUUIDs = true; + LOGGER.debug("found UUID in model: " + m.name); + break; + } + } + } + + this.additionalProperties.put("hasUUIDs", hasUUIDs); return objs; } + /** + * Recursively searches for a model's properties for a UUID type field. + */ + private boolean hasUuidInProperties(List properties) { + for (CodegenProperty property : properties) { + if (property.isUuid) { + return true; + } + // Check nested properties + if (property.items != null && hasUuidInProperties(Collections.singletonList(property.items))) { + return true; + } + if (property.additionalProperties != null && hasUuidInProperties(Collections.singletonList(property.additionalProperties))) { + return true; + } + if (property.vars != null && hasUuidInProperties(property.vars)) { + return true; + } + } + return false; + } + @Override public String toDefaultValue(Schema p) { if (p.getDefault() != null) { diff --git a/modules/openapi-generator/src/main/resources/rust/Cargo.mustache b/modules/openapi-generator/src/main/resources/rust/Cargo.mustache index 55d75560fd7..6a9676d733f 100644 --- a/modules/openapi-generator/src/main/resources/rust/Cargo.mustache +++ b/modules/openapi-generator/src/main/resources/rust/Cargo.mustache @@ -39,7 +39,9 @@ serde_with = { version = "^3.8", default-features = false, features = ["base64", serde_json = "^1.0" serde_repr = "^0.1" url = "^2.5" +{{#hasUUIDs}} uuid = { version = "^1.8", features = ["serde", "v4"] } +{{/hasUUIDs}} {{#hyper}} {{#hyper0x}} hyper = { version = "~0.14", features = ["full"] } diff --git a/samples/client/others/rust/hyper/api-with-ref-param/Cargo.toml b/samples/client/others/rust/hyper/api-with-ref-param/Cargo.toml index 00f46b1c7d3..ca96e317ff6 100644 --- a/samples/client/others/rust/hyper/api-with-ref-param/Cargo.toml +++ b/samples/client/others/rust/hyper/api-with-ref-param/Cargo.toml @@ -12,7 +12,6 @@ serde = { version = "^1.0", features = ["derive"] } serde_json = "^1.0" serde_repr = "^0.1" url = "^2.5" -uuid = { version = "^1.8", features = ["serde", "v4"] } hyper = { version = "^1.3.1", features = ["full"] } hyper-util = { version = "0.1.5", features = ["client", "client-legacy", "http1", "http2"] } http-body-util = { version = "0.1.2" } diff --git a/samples/client/others/rust/hyper/composed-oneof/Cargo.toml b/samples/client/others/rust/hyper/composed-oneof/Cargo.toml index 4c0a00557c5..b19d8e7b6fa 100644 --- a/samples/client/others/rust/hyper/composed-oneof/Cargo.toml +++ b/samples/client/others/rust/hyper/composed-oneof/Cargo.toml @@ -12,7 +12,6 @@ serde = { version = "^1.0", features = ["derive"] } serde_json = "^1.0" serde_repr = "^0.1" url = "^2.5" -uuid = { version = "^1.8", features = ["serde", "v4"] } hyper = { version = "^1.3.1", features = ["full"] } hyper-util = { version = "0.1.5", features = ["client", "client-legacy", "http1", "http2"] } http-body-util = { version = "0.1.2" } diff --git a/samples/client/others/rust/hyper/emptyObject/Cargo.toml b/samples/client/others/rust/hyper/emptyObject/Cargo.toml index 1efb624b65d..1b58d3838fc 100644 --- a/samples/client/others/rust/hyper/emptyObject/Cargo.toml +++ b/samples/client/others/rust/hyper/emptyObject/Cargo.toml @@ -12,7 +12,6 @@ serde = { version = "^1.0", features = ["derive"] } serde_json = "^1.0" serde_repr = "^0.1" url = "^2.5" -uuid = { version = "^1.8", features = ["serde", "v4"] } hyper = { version = "^1.3.1", features = ["full"] } hyper-util = { version = "0.1.5", features = ["client", "client-legacy", "http1", "http2"] } http-body-util = { version = "0.1.2" } diff --git a/samples/client/others/rust/hyper/oneOf-array-map/Cargo.toml b/samples/client/others/rust/hyper/oneOf-array-map/Cargo.toml index 1bb7aa7bb54..a9d45416555 100644 --- a/samples/client/others/rust/hyper/oneOf-array-map/Cargo.toml +++ b/samples/client/others/rust/hyper/oneOf-array-map/Cargo.toml @@ -12,7 +12,6 @@ serde = { version = "^1.0", features = ["derive"] } serde_json = "^1.0" serde_repr = "^0.1" url = "^2.5" -uuid = { version = "^1.8", features = ["serde", "v4"] } hyper = { version = "^1.3.1", features = ["full"] } hyper-util = { version = "0.1.5", features = ["client", "client-legacy", "http1", "http2"] } http-body-util = { version = "0.1.2" } diff --git a/samples/client/others/rust/hyper/oneOf-reuseRef/Cargo.toml b/samples/client/others/rust/hyper/oneOf-reuseRef/Cargo.toml index 07b8f6cf6d8..5367809843d 100644 --- a/samples/client/others/rust/hyper/oneOf-reuseRef/Cargo.toml +++ b/samples/client/others/rust/hyper/oneOf-reuseRef/Cargo.toml @@ -11,7 +11,6 @@ serde = { version = "^1.0", features = ["derive"] } serde_json = "^1.0" serde_repr = "^0.1" url = "^2.5" -uuid = { version = "^1.8", features = ["serde", "v4"] } hyper = { version = "^1.3.1", features = ["full"] } hyper-util = { version = "0.1.5", features = ["client", "client-legacy", "http1", "http2"] } http-body-util = { version = "0.1.2" } diff --git a/samples/client/others/rust/hyper/oneOf/Cargo.toml b/samples/client/others/rust/hyper/oneOf/Cargo.toml index fb78d69e910..d9569e6067c 100644 --- a/samples/client/others/rust/hyper/oneOf/Cargo.toml +++ b/samples/client/others/rust/hyper/oneOf/Cargo.toml @@ -12,7 +12,6 @@ serde = { version = "^1.0", features = ["derive"] } serde_json = "^1.0" serde_repr = "^0.1" url = "^2.5" -uuid = { version = "^1.8", features = ["serde", "v4"] } hyper = { version = "^1.3.1", features = ["full"] } hyper-util = { version = "0.1.5", features = ["client", "client-legacy", "http1", "http2"] } http-body-util = { version = "0.1.2" } diff --git a/samples/client/others/rust/reqwest-regression-16119/Cargo.toml b/samples/client/others/rust/reqwest-regression-16119/Cargo.toml index a1e41446d88..0712b88be4f 100644 --- a/samples/client/others/rust/reqwest-regression-16119/Cargo.toml +++ b/samples/client/others/rust/reqwest-regression-16119/Cargo.toml @@ -12,5 +12,4 @@ serde = { version = "^1.0", features = ["derive"] } serde_json = "^1.0" serde_repr = "^0.1" url = "^2.5" -uuid = { version = "^1.8", features = ["serde", "v4"] } reqwest = { version = "^0.12", features = ["json", "blocking", "multipart"] } diff --git a/samples/client/others/rust/reqwest/api-with-ref-param/Cargo.toml b/samples/client/others/rust/reqwest/api-with-ref-param/Cargo.toml index e4edc99b719..7b36f89b940 100644 --- a/samples/client/others/rust/reqwest/api-with-ref-param/Cargo.toml +++ b/samples/client/others/rust/reqwest/api-with-ref-param/Cargo.toml @@ -12,5 +12,4 @@ serde = { version = "^1.0", features = ["derive"] } serde_json = "^1.0" serde_repr = "^0.1" url = "^2.5" -uuid = { version = "^1.8", features = ["serde", "v4"] } reqwest = { version = "^0.12", features = ["json", "multipart"] } diff --git a/samples/client/others/rust/reqwest/composed-oneof/Cargo.toml b/samples/client/others/rust/reqwest/composed-oneof/Cargo.toml index f06effdcb10..2a7c3a43bb7 100644 --- a/samples/client/others/rust/reqwest/composed-oneof/Cargo.toml +++ b/samples/client/others/rust/reqwest/composed-oneof/Cargo.toml @@ -12,5 +12,4 @@ serde = { version = "^1.0", features = ["derive"] } serde_json = "^1.0" serde_repr = "^0.1" url = "^2.5" -uuid = { version = "^1.8", features = ["serde", "v4"] } reqwest = { version = "^0.12", features = ["json", "blocking", "multipart"] } diff --git a/samples/client/others/rust/reqwest/emptyObject/Cargo.toml b/samples/client/others/rust/reqwest/emptyObject/Cargo.toml index d35bad9e88d..bf65d42d4cc 100644 --- a/samples/client/others/rust/reqwest/emptyObject/Cargo.toml +++ b/samples/client/others/rust/reqwest/emptyObject/Cargo.toml @@ -12,5 +12,4 @@ serde = { version = "^1.0", features = ["derive"] } serde_json = "^1.0" serde_repr = "^0.1" url = "^2.5" -uuid = { version = "^1.8", features = ["serde", "v4"] } reqwest = { version = "^0.12", features = ["json", "blocking", "multipart"] } diff --git a/samples/client/others/rust/reqwest/oneOf-array-map/Cargo.toml b/samples/client/others/rust/reqwest/oneOf-array-map/Cargo.toml index 5f2d99d1804..509f9c6d885 100644 --- a/samples/client/others/rust/reqwest/oneOf-array-map/Cargo.toml +++ b/samples/client/others/rust/reqwest/oneOf-array-map/Cargo.toml @@ -12,5 +12,4 @@ serde = { version = "^1.0", features = ["derive"] } serde_json = "^1.0" serde_repr = "^0.1" url = "^2.5" -uuid = { version = "^1.8", features = ["serde", "v4"] } reqwest = { version = "^0.12", features = ["json", "blocking", "multipart"] } diff --git a/samples/client/others/rust/reqwest/oneOf-reuseRef/Cargo.toml b/samples/client/others/rust/reqwest/oneOf-reuseRef/Cargo.toml index 64b0d4bf92f..58b7a46e045 100644 --- a/samples/client/others/rust/reqwest/oneOf-reuseRef/Cargo.toml +++ b/samples/client/others/rust/reqwest/oneOf-reuseRef/Cargo.toml @@ -11,5 +11,4 @@ serde = { version = "^1.0", features = ["derive"] } serde_json = "^1.0" serde_repr = "^0.1" url = "^2.5" -uuid = { version = "^1.8", features = ["serde", "v4"] } reqwest = { version = "^0.12", features = ["json", "blocking", "multipart"] } diff --git a/samples/client/others/rust/reqwest/oneOf/Cargo.toml b/samples/client/others/rust/reqwest/oneOf/Cargo.toml index 8966bd1292c..0af49f66158 100644 --- a/samples/client/others/rust/reqwest/oneOf/Cargo.toml +++ b/samples/client/others/rust/reqwest/oneOf/Cargo.toml @@ -12,5 +12,4 @@ serde = { version = "^1.0", features = ["derive"] } serde_json = "^1.0" serde_repr = "^0.1" url = "^2.5" -uuid = { version = "^1.8", features = ["serde", "v4"] } reqwest = { version = "^0.12", features = ["json", "blocking", "multipart"] } diff --git a/samples/client/petstore/rust/reqwest/name-mapping/Cargo.toml b/samples/client/petstore/rust/reqwest/name-mapping/Cargo.toml index 172f74f4e1f..99c54a81fd2 100644 --- a/samples/client/petstore/rust/reqwest/name-mapping/Cargo.toml +++ b/samples/client/petstore/rust/reqwest/name-mapping/Cargo.toml @@ -11,5 +11,4 @@ serde = { version = "^1.0", features = ["derive"] } serde_json = "^1.0" serde_repr = "^0.1" url = "^2.5" -uuid = { version = "^1.8", features = ["serde", "v4"] } reqwest = { version = "^0.12", features = ["json", "blocking", "multipart"] }