|
38 | 38 | import org.openapitools.codegen.CodegenConstants; |
39 | 39 | import org.openapitools.codegen.CodegenModel; |
40 | 40 | import org.openapitools.codegen.CodegenOperation; |
41 | | -import org.openapitools.codegen.CodegenProperty; |
42 | 41 | import org.openapitools.codegen.CodegenParameter; |
| 42 | +import org.openapitools.codegen.CodegenProperty; |
43 | 43 | import org.openapitools.codegen.CodegenType; |
44 | 44 | import org.openapitools.codegen.SupportingFile; |
45 | | -import org.openapitools.codegen.VendorExtension; |
46 | 45 | import org.openapitools.codegen.meta.features.ClientModificationFeature; |
47 | 46 | import org.openapitools.codegen.meta.features.DocumentationFeature; |
48 | 47 | import org.openapitools.codegen.meta.features.GlobalFeature; |
@@ -109,6 +108,10 @@ public class RustClientCodegen extends AbstractRustCodegen implements CodegenCon |
109 | 108 | protected String modelDocPath = "docs/"; |
110 | 109 | protected String apiFolder = "src/apis"; |
111 | 110 | 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 | + |
112 | 115 |
|
113 | 116 | @Override |
114 | 117 | public CodegenType getTag() { |
@@ -253,6 +256,7 @@ public RustClientCodegen() { |
253 | 256 | supportedLibraries.put(REQWEST_LIBRARY, "HTTP client: Reqwest."); |
254 | 257 | supportedLibraries.put(REQWEST_TRAIT_LIBRARY, "HTTP client: Reqwest (trait based)."); |
255 | 258 |
|
| 259 | + |
256 | 260 | CliOption libraryOption = new CliOption(CodegenConstants.LIBRARY, "library template (sub-template) to use."); |
257 | 261 | libraryOption.setEnum(supportedLibraries); |
258 | 262 | // set reqwest as the default |
@@ -642,6 +646,13 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo |
642 | 646 | } |
643 | 647 | } |
644 | 648 |
|
| 649 | + for (var param : operation.allParams) { |
| 650 | + if (!hasUUIDs && param.isUuid) { |
| 651 | + hasUUIDs = true; |
| 652 | + break; |
| 653 | + } |
| 654 | + } |
| 655 | + |
645 | 656 | // http method verb conversion, depending on client library (e.g. Hyper: PUT => Put, Reqwest: PUT => put) |
646 | 657 | if (HYPER_LIBRARY.equals(getLibrary())) { |
647 | 658 | operation.httpMethod = StringUtils.camelize(operation.httpMethod.toLowerCase(Locale.ROOT)); |
@@ -705,9 +716,43 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo |
705 | 716 | }*/ |
706 | 717 | } |
707 | 718 |
|
| 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); |
708 | 731 | return objs; |
709 | 732 | } |
710 | 733 |
|
| 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 | + |
711 | 756 | @Override |
712 | 757 | public String toDefaultValue(Schema p) { |
713 | 758 | if (p.getDefault() != null) { |
|
0 commit comments