Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/generators/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|packageName|Rust package name (convention: lowercase).| |openapi|
|packageVersion|Rust package version.| |1.0.0|
|preferUnsignedInt|Prefer unsigned integers where minimum value is >= 0| |false|
|reqwestDefaultFeatures|Default features for the reqwest dependency (comma-separated). Use empty for no defaults. This option is for 'reqwest' and 'reqwest-trait' library only.| |native-tls|
|supportAsync|If set, generate async function call instead. This option is for 'reqwest' library only| |true|
|supportMiddleware|If set, add support for reqwest-middleware. This option is for 'reqwest' and 'reqwest-trait' library only| |false|
|supportMultipleResponses|If set, return type wraps an enum of all possible 2xx schemas. This option is for 'reqwest' and 'reqwest-trait' library only| |false|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public class RustClientCodegen extends AbstractRustCodegen implements CodegenCon
@Setter private boolean preferUnsignedInt = false;
@Setter private boolean bestFitInt = false;
@Setter private boolean avoidBoxedModels = false;
private List<String> reqwestDefaultFeatures = Arrays.asList("native-tls");

public static final String PACKAGE_NAME = "packageName";
public static final String EXTERN_CRATE_NAME = "externCrateName";
Expand All @@ -77,6 +78,7 @@ public class RustClientCodegen extends AbstractRustCodegen implements CodegenCon
public static final String TOP_LEVEL_API_CLIENT = "topLevelApiClient";
public static final String MOCKALL = "mockall";
public static final String BON_BUILDER = "useBonBuilder";
public static final String REQWEST_DEFAULT_FEATURES = "reqwestDefaultFeatures";

@Setter protected String packageName = "openapi";
@Setter protected String packageVersion = "1.0.0";
Expand Down Expand Up @@ -227,6 +229,8 @@ public RustClientCodegen() {
.defaultValue(Boolean.FALSE.toString()));
cliOptions.add(new CliOption(BON_BUILDER, "Use the bon crate for building parameter types. This option is for the 'reqwest-trait' library only", SchemaTypeUtil.BOOLEAN_TYPE)
.defaultValue(Boolean.FALSE.toString()));
cliOptions.add(new CliOption(REQWEST_DEFAULT_FEATURES, "Default features for the reqwest dependency (comma-separated). Use empty for no defaults. This option is for 'reqwest' and 'reqwest-trait' library only.")
.defaultValue("native-tls"));

supportedLibraries.put(HYPER_LIBRARY, "HTTP client: Hyper (v1.x).");
supportedLibraries.put(HYPER0X_LIBRARY, "HTTP client: Hyper (v0.x).");
Expand Down Expand Up @@ -431,6 +435,21 @@ public void processOpts() {
}
writePropertyBack(AVOID_BOXED_MODELS, getAvoidBoxedModels());

if (additionalProperties.containsKey(REQWEST_DEFAULT_FEATURES)) {
Object value = additionalProperties.get(REQWEST_DEFAULT_FEATURES);
if (value instanceof List) {
reqwestDefaultFeatures = (List<String>) value;
} else if (value instanceof String) {
String str = (String) value;
if (str.isEmpty()) {
reqwestDefaultFeatures = new ArrayList<>();
} else {
reqwestDefaultFeatures = Arrays.asList(str.split(",\\s*"));
}
}
}
additionalProperties.put(REQWEST_DEFAULT_FEATURES, reqwestDefaultFeatures);

additionalProperties.put(CodegenConstants.PACKAGE_NAME, packageName);
additionalProperties.put(CodegenConstants.PACKAGE_VERSION, packageVersion);
additionalProperties.put(EXTERN_CRATE_NAME, getExternCrateName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ google-cloud-token = "^0.1"
{{/supportAsync}}

[features]
default = ["native-tls"]
default = [{{#reqwestDefaultFeatures}}"{{.}}"{{^-last}}, {{/-last}}{{/reqwestDefaultFeatures}}]
native-tls = ["reqwest/native-tls"]
rustls-tls = ["reqwest/rustls-tls"]
{{/reqwest}}
Expand All @@ -109,7 +109,7 @@ mockall = { version = "^0.13", optional = true}
bon = { version = "2.3", optional = true }
{{/useBonBuilder}}
[features]
default = ["native-tls"]
default = [{{#reqwestDefaultFeatures}}"{{.}}"{{^-last}}, {{/-last}}{{/reqwestDefaultFeatures}}]
native-tls = ["reqwest/native-tls"]
rustls-tls = ["reqwest/rustls-tls"]
{{#mockall}}
Expand Down
Loading