Skip to content

Commit 86e2d4c

Browse files
authored
Model track_total_hits with enum (#52)
This commit updates track_total_hits param to model it as an enum. Track total hits accepts either a boolean or an integer.
1 parent fb457fd commit 86e2d4c

File tree

35 files changed

+151
-121
lines changed

35 files changed

+151
-121
lines changed

api_generator/src/api_generator/code_gen/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,10 @@ fn typekind_to_ty(name: &str, kind: TypeKind, required: bool) -> syn::Ty {
133133
TypeKind::Enum => v.push_str(name.to_pascal_case().as_str()),
134134
TypeKind::String => v.push_str(str_type),
135135
TypeKind::Text => v.push_str(str_type),
136-
TypeKind::Boolean => v.push_str("bool"),
136+
TypeKind::Boolean => match name {
137+
"track_total_hits" => v.push_str("TrackTotalHits"),
138+
_ => v.push_str("bool"),
139+
},
137140
TypeKind::Number => v.push_str("i64"),
138141
TypeKind::Float => v.push_str("f32"),
139142
TypeKind::Double => v.push_str("f64"),

api_generator/src/api_generator/code_gen/params.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ fn generate_param(tokens: &mut Tokens, e: &ApiEnum) {
3131
static ref PARENS_REGEX: Regex = Regex::new(r"^(.*?)\s*\(.*?\)\s*$").unwrap();
3232
}
3333
if let Some(c) = PARENS_REGEX.captures(v) {
34-
(c.get(1).unwrap().as_str().to_owned(), syn::Ident::from(c.get(1).unwrap().as_str().to_pascal_case()))
34+
(
35+
c.get(1).unwrap().as_str().to_owned(),
36+
syn::Ident::from(c.get(1).unwrap().as_str().to_pascal_case()),
37+
)
3538
} else {
3639
(v.to_owned(), syn::Ident::from(v.to_pascal_case()))
3740
}

api_generator/src/api_generator/code_gen/request/request_builder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ use crate::api_generator::{
44
};
55
use inflector::Inflector;
66
use quote::{ToTokens, Tokens};
7+
use reqwest::Url;
78
use std::{collections::BTreeMap, str};
89
use syn::{Field, FieldValue, ImplItem};
9-
use reqwest::Url;
1010

1111
/// Builder that generates the AST for a request builder struct
1212
pub struct RequestBuilder<'a> {
@@ -392,7 +392,7 @@ impl<'a> RequestBuilder<'a> {
392392

393393
// add a field for HTTP headers
394394
fields.push(syn::Field {
395-
ident: Some(headers_field_ident.clone()),
395+
ident: Some(headers_field_ident.clone()),
396396
vis: syn::Visibility::Inherited,
397397
attrs: vec![],
398398
ty: syn::parse_type("HeaderMap").unwrap(),

api_generator/src/api_generator/code_gen/url/enum_builder.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
* limitations under the License.
1616
*/
1717

18-
1918
use crate::api_generator::code_gen::url::url_builder::{IntoExpr, UrlBuilder};
2019
use crate::api_generator::{code_gen::*, ApiEndpoint, Path};
2120
use inflector::Inflector;

elasticsearch/src/cat/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@
3030
//!
3131
//!
3232
33-
pub use super::generated::namespace_clients::cat::*;
33+
pub use super::generated::namespace_clients::cat::*;

elasticsearch/src/ccr/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
//! - Disaster recovery in case a primary cluster fails. A secondary cluster can serve as a hot backup
77
//! - Geo-proximity so that reads can be served locally
88
9-
pub use super::generated::namespace_clients::ccr::*;
9+
pub use super::generated::namespace_clients::ccr::*;

elasticsearch/src/client.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{
2-
http::{request::Body, response::Response, transport::Transport, Method, headers::HeaderMap},
2+
http::{headers::HeaderMap, request::Body, response::Response, transport::Transport, Method},
33
Error,
44
};
55

@@ -50,6 +50,8 @@ impl Elasticsearch {
5050
B: Body,
5151
Q: Serialize + ?Sized,
5252
{
53-
self.transport.send(method, path, headers, query_string, body).await
53+
self.transport
54+
.send(method, path, headers, query_string, body)
55+
.await
5456
}
5557
}

elasticsearch/src/cluster/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
//! [Manage settings](https://www.elastic.co/guide/en/elasticsearch/reference/master/cluster.html),
44
//! perform operations, and retrieve information about an Elasticsearch cluster.
55
6-
pub use super::generated::namespace_clients::cluster::*;
6+
pub use super::generated::namespace_clients::cluster::*;

elasticsearch/src/enrich/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
//! as part of an [ingest pipeline](../ingest/index.html), to add data from your existing indices
66
//! to incoming documents during ingest.
77
8-
pub use super::generated::namespace_clients::enrich::*;
8+
pub use super::generated::namespace_clients::enrich::*;

elasticsearch/src/error.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,39 +58,39 @@ impl From<io::Error> for Error {
5858
impl From<reqwest::Error> for Error {
5959
fn from(err: reqwest::Error) -> Error {
6060
Error {
61-
kind: Kind::Http(err)
61+
kind: Kind::Http(err),
6262
}
6363
}
6464
}
6565

6666
impl From<serde_json::error::Error> for Error {
6767
fn from(err: serde_json::error::Error) -> Error {
6868
Error {
69-
kind: Kind::Json(err)
69+
kind: Kind::Json(err),
7070
}
7171
}
7272
}
7373

7474
impl From<url::ParseError> for Error {
7575
fn from(err: url::ParseError) -> Error {
7676
Error {
77-
kind: Kind::Lib(err.to_string())
77+
kind: Kind::Lib(err.to_string()),
7878
}
7979
}
8080
}
8181

8282
impl From<BuildError> for Error {
8383
fn from(err: BuildError) -> Error {
8484
Error {
85-
kind: Kind::Build(err)
85+
kind: Kind::Build(err),
8686
}
8787
}
8888
}
8989

9090
impl Error {
9191
pub(crate) fn lib(err: impl Into<String>) -> Self {
9292
Error {
93-
kind: Kind::Lib(err.into())
93+
kind: Kind::Lib(err.into()),
9494
}
9595
}
9696
}

0 commit comments

Comments
 (0)