Skip to content
Closed
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 bin/configs/rust-reqwest-name-mapping.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ templateDir: modules/openapi-generator/src/main/resources/rust
additionalProperties:
supportAsync: false
packageName: petstore-name-mapping
varPrefix: ""
nameMappings:
_type: underscore_type
type_: type_with_underscore
Expand Down
1 change: 1 addition & 0 deletions docs/generators/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|topLevelApiClient|Creates a top level `Api` trait and `ApiClient` struct that contain all Apis. This option is for 'reqwest-trait' library only| |false|
|useBonBuilder|Use the bon crate for building parameter types. This option is for the 'reqwest-trait' library only| |false|
|useSingleRequestParameter|Setting this property to true will generate functions with a single argument containing all API endpoint parameters instead of one argument per parameter.| |false|
|varPrefix|Local variable prefix| |local_var_|
|withAWSV4Signature|whether to include AWS v4 signature support| |false|

## IMPORT MAPPING
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,4 +453,7 @@ public static enum ENUM_PROPERTY_NAMING_TYPE {camelCase, PascalCase, snake_case,
public static final String WAIT_TIME_OF_THREAD = "waitTimeMillis";

public static final String USE_DEFAULT_VALUES_FOR_REQUIRED_VARS = "useDefaultValuesForRequiredVars";

public static final String VAR_PREFIX = "varPrefix";
public static final String VAR_PREFIX_DESC = "Local variable prefix";
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,13 @@ public class RustClientCodegen extends AbstractRustCodegen implements CodegenCon

@Setter protected String packageName = "openapi";
@Setter protected String packageVersion = "1.0.0";
@Setter protected String varPrefix = "local_var_";
protected String apiDocPath = "docs/";
protected String modelDocPath = "docs/";
protected String apiFolder = "src/apis";
protected String modelFolder = "src/models";


@Override
public CodegenType getTag() {
return CodegenType.CLIENT;
Expand Down Expand Up @@ -242,6 +244,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(CodegenConstants.VAR_PREFIX, CodegenConstants.VAR_PREFIX_DESC)
.defaultValue("local_var_"));

supportedLibraries.put(HYPER_LIBRARY, "HTTP client: Hyper (v1.x).");
supportedLibraries.put(HYPER0X_LIBRARY, "HTTP client: Hyper (v0.x).");
Expand Down Expand Up @@ -371,6 +375,11 @@ public void processOpts() {
setPackageVersion(openAPI.getInfo().getVersion());
}

// set varPrefix to default if none is provided
if (!additionalProperties.containsKey(CodegenConstants.VAR_PREFIX)) {
additionalProperties.put(CodegenConstants.VAR_PREFIX, varPrefix);
}

if (additionalProperties.containsKey(CodegenConstants.USE_SINGLE_REQUEST_PARAMETER)) {
this.setUseSingleRequestParameter(convertPropertyToBoolean(CodegenConstants.USE_SINGLE_REQUEST_PARAMETER));
}
Expand Down

Large diffs are not rendered by default.

186 changes: 93 additions & 93 deletions modules/openapi-generator/src/main/resources/rust/reqwest/api.mustache

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,34 @@ pub enum GetParameterNameMappingError {


pub fn get_parameter_name_mapping(configuration: &configuration::Configuration, underscore_type: i64, r#type: &str, type_with_underscore: &str, dash_type: &str, http_debug_option: &str) -> Result<(), Error<GetParameterNameMappingError>> {
let local_var_configuration = configuration;
let configuration = configuration;

let local_var_client = &local_var_configuration.client;
let client = &configuration.client;

let local_var_uri_str = format!("{}/fake/parameter-name-mapping", local_var_configuration.base_path);
let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
let uri_str = format!("{}/fake/parameter-name-mapping", configuration.base_path);
let mut req_builder = client.request(reqwest::Method::GET, uri_str.as_str());

local_var_req_builder = local_var_req_builder.query(&[("type", &r#type.to_string())]);
local_var_req_builder = local_var_req_builder.query(&[("http_debug_option", &http_debug_option.to_string())]);
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
req_builder = req_builder.query(&[("type", &r#type.to_string())]);
req_builder = req_builder.query(&[("http_debug_option", &http_debug_option.to_string())]);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
local_var_req_builder = local_var_req_builder.header("_type", underscore_type.to_string());
local_var_req_builder = local_var_req_builder.header("type_", type_with_underscore.to_string());
local_var_req_builder = local_var_req_builder.header("-type", dash_type.to_string());
req_builder = req_builder.header("_type", underscore_type.to_string());
req_builder = req_builder.header("type_", type_with_underscore.to_string());
req_builder = req_builder.header("-type", dash_type.to_string());

let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req)?;
let req = req_builder.build()?;
let resp = client.execute(req)?;

let local_var_status = local_var_resp.status();
let status = resp.status();

if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
if !status.is_client_error() && !status.is_server_error() {
Ok(())
} else {
let local_var_content = local_var_resp.text()?;
let local_var_entity: Option<GetParameterNameMappingError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
let content = resp.text()?;
let entity: Option<GetParameterNameMappingError> = serde_json::from_str(&content).ok();
let error = ResponseContent { status: status, content: content, entity: entity };
Err(Error::ResponseError(error))
}
}