Skip to content

Commit 8e2dcdb

Browse files
azriel-healthpointdsteeley
authored andcommitted
[Rust Server] Update client example to compile (OpenAPITools#17876)
1 parent cc07c81 commit 8e2dcdb

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

modules/openapi-generator/src/main/resources/rust-server/example-client-main.mustache

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use {{{externCrateName}}}::{Api, ApiNoContext, Claims, Client, ContextWrapperExt
1818
{{/apis}}
1919
{{/apiInfo}}
2020
};
21-
use clap::{App, Arg};
21+
use clap::{Command, Arg};
2222

2323
// NOTE: Set environment variable RUST_LOG to the name of the executable (or "cargo run") to activate console logging for all loglevels.
2424
// See https://docs.rs/env_logger/latest/env_logger/ for more details
@@ -41,10 +41,10 @@ use client_auth::build_token;
4141
fn main() {
4242
env_logger::init();
4343
44-
let matches = App::new("client")
45-
.arg(Arg::with_name("operation")
44+
let matches = Command::new("client")
45+
.arg(Arg::new("operation")
4646
.help("Sets the operation to run")
47-
.possible_values(&[
47+
.value_parser([
4848
{{#apiInfo}}
4949
{{#apis}}
5050
{{#operations}}
@@ -61,17 +61,15 @@ fn main() {
6161
])
6262
.required(true)
6363
.index(1))
64-
.arg(Arg::with_name("https")
64+
.arg(Arg::new("https")
6565
.long("https")
6666
.help("Whether to use HTTPS or not"))
67-
.arg(Arg::with_name("host")
67+
.arg(Arg::new("host")
6868
.long("host")
69-
.takes_value(true)
7069
.default_value("{{{serverHost}}}")
7170
.help("Hostname to contact"))
72-
.arg(Arg::with_name("port")
71+
.arg(Arg::new("port")
7372
.long("port")
74-
.takes_value(true)
7573
.default_value("{{{serverPort}}}")
7674
.help("Port to contact"))
7775
.get_matches();
@@ -106,22 +104,22 @@ fn main() {
106104
b"secret").unwrap();
107105

108106
let auth_data = if !auth_token.is_empty() {
109-
Some(AuthData::Bearer(swagger::auth::Bearer { token: auth_token}))
107+
Some(AuthData::Bearer(auth_token))
110108
} else {
111109
// No Bearer-token available, so return None
112110
None
113111
};
114112

115-
let is_https = matches.is_present("https");
113+
let is_https = matches.contains_id("https");
116114
let base_url = format!("{}://{}:{}",
117115
if is_https { "https" } else { "http" },
118-
matches.value_of("host").unwrap(),
119-
matches.value_of("port").unwrap());
116+
matches.get_one::<String>("host").unwrap(),
117+
matches.get_one::<u16>("port").unwrap());
120118

121119
let context: ClientContext =
122120
swagger::make_context!(ContextBuilder, EmptyContext, auth_data, XSpanIdString::default());
123121

124-
let mut client : Box<dyn ApiNoContext<ClientContext>> = if matches.is_present("https") {
122+
let mut client : Box<dyn ApiNoContext<ClientContext>> = if is_https {
125123
// Using Simple HTTPS
126124
let client = Box::new(Client::try_new_https(&base_url)
127125
.expect("Failed to create HTTPS client"));
@@ -141,7 +139,7 @@ fn main() {
141139
rt.spawn(server::create("127.0.0.1:8081", false));
142140
{{/hasCallbacks}}
143141

144-
match matches.value_of("operation") {
142+
match matches.get_one::<String>("operation") {
145143
{{#apiInfo}}
146144
{{#apis}}
147145
{{#operations}}

0 commit comments

Comments
 (0)