[Fix #3052] Add support for optional query parameters#3250
[Fix #3052] Add support for optional query parameters#3250jonahgeorge wants to merge 2 commits intoOpenAPITools:masterfrom
Conversation
fn update_pet_with_form(&self, pet_id: i64, name: Option<&str>, status: Option<&str>) -> Result<(), Error> {
let configuration: &configuration::Configuration = self.configuration.borrow();
let client = &configuration.client;
let uri_str = format!("{}/pet/{petId}", configuration.base_path, petId=pet_id);
let mut req_builder = client.post(uri_str.as_str());
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let mut form_params = std::collections::HashMap::new();
form_params.insert("name", name.to_string());
form_params.insert("status", status.to_string());
req_builder = req_builder.form(&form_params);Doing some more testing, it looks like this has issues due to the Option on the form parameters. Curious if anyone has input on a better way to address this: seems like I could either add the same changes to the form parameters as well or break the operation parameters into queryParams and formParams. |
|
Hi @jonahgeorge, IMO, this PR is a must have. I already forked it for one of my projects and it gave expected results. I think you forgot to regenerate OpenAPI generator general doocumentation, which explain the CI failure for your PR. The new parameter have to be added to this documentation ( |
|
@jonahgeorge thanks for the PR. Instead of introducing a new option, what about using |
|
@wing328 Agree that using Also, wouldn't it still be considered a breaking change to make |
You can use
To me, it's more like correcting the behavior. For other languages/generators, we do not consider it as a breaking change but of course, I like your suggestion to give a proper heads-up to the user and how they can use |
|
Any news for this PR? If nobody is working on it anymore, I can try to fix it… |
|
@bcourtine please kindly go ahead. What about merging it into a branch (in this project) so that more people can work on it? |
As stated in OpenAPITools#3250 * Making this optinal gives more complicated templates, harder to maintain. * Such breaking change is acceptable, since it's more a behavior correction.
|
Sorry for the radio silence, I haven't had time to polish this up. |
|
Hello @wing328 @jonahgeorge I completed this PR and proposed a new one here: #4016 IMO, it should be mergeable (hyper/reqwest sample code compiles without error). |
|
PR #4016 (which includes and completes this one) has been merged. So this PR can be closed. |
PR checklist
./bin/to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.sh,./bin/openapi3/{LANG}-petstore.shif updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in.\bin\windows\. If contributing template-only or documentation-only changes which will change sample output, be sure to build the project first.master,4.1.x,5.0.x. Default:master.Description of the PR
Addresses #3052.
This adds a new feature flag for the two Rust clients named
generateOptionQueryParamswhich when enabled wraps any non-required query parameters inOption<T>and does not add them to the request ifNone.@frol @farcaller @bjgill