Skip to content

Commit e686fa7

Browse files
committed
make DEFAULT_DOC_TYPE used throughout client and generated code
1 parent f16a372 commit e686fa7

File tree

8 files changed

+17
-13
lines changed

8 files changed

+17
-13
lines changed

src/elastic/src/client/requests/document_delete.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use types::document::{
3434
StaticIndex,
3535
StaticType,
3636
};
37-
use types::DEFAULT_TYPE;
37+
use types::document::DEFAULT_DOC_TYPE;
3838

3939
/**
4040
A [delete document request][docs-delete] builder that can be configured before sending.
@@ -181,7 +181,7 @@ where
181181
self.inner,
182182
DeleteRequestInner {
183183
index: index.into(),
184-
ty: DEFAULT_TYPE.into(),
184+
ty: DEFAULT_DOC_TYPE.into(),
185185
id: id.into(),
186186
_marker: PhantomData,
187187
},

src/elastic/src/client/requests/document_get.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use types::document::{
3535
StaticIndex,
3636
StaticType,
3737
};
38-
use types::DEFAULT_TYPE;
38+
use types::document::DEFAULT_DOC_TYPE;
3939

4040
/**
4141
A [get document request][docs-get] builder that can be configured before sending.
@@ -176,7 +176,7 @@ where
176176
self.inner,
177177
GetRequestInner {
178178
index: index.into(),
179-
ty: DEFAULT_TYPE.into(),
179+
ty: DEFAULT_DOC_TYPE.into(),
180180
id: id.into(),
181181
_marker: PhantomData,
182182
},

src/elastic/src/client/requests/document_index.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ use error::{
3333
Error,
3434
Result,
3535
};
36-
use types::document::DocumentType;
37-
use types::DEFAULT_TYPE;
36+
use types::document::{DocumentType, DEFAULT_DOC_TYPE};
3837

3938
/**
4039
An [index request][docs-index] builder that can be configured before sending.
@@ -198,7 +197,7 @@ where
198197
self.inner,
199198
IndexRequestInner {
200199
index: index.into(),
201-
ty: DEFAULT_TYPE.into(),
200+
ty: DEFAULT_DOC_TYPE.into(),
202201
id: None,
203202
doc: doc,
204203
},

src/elastic/src/client/requests/document_update.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ use types::document::{
3535
DocumentType,
3636
StaticIndex,
3737
StaticType,
38+
DEFAULT_DOC_TYPE,
3839
};
39-
use types::DEFAULT_TYPE;
4040

4141
pub use client::requests::common::{
4242
DefaultParams,
@@ -287,7 +287,7 @@ where
287287
self.inner,
288288
UpdateRequestInner {
289289
index: index.into(),
290-
ty: DEFAULT_TYPE.into(),
290+
ty: DEFAULT_DOC_TYPE.into(),
291291
id: id.into(),
292292
body: Doc::empty(),
293293
_marker: PhantomData,

src/elastic/src/types.rs

-2
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,5 @@ pub use elastic_types::{
275275
string,
276276
};
277277

278-
pub(crate) const DEFAULT_TYPE: &'static str = "doc";
279-
280278
#[doc(hidden)]
281279
pub use elastic_types::derive;

src/types/src/derive.rs

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pub use document::mapping::{
3434
PropertiesMapping,
3535
};
3636
pub use document::{
37+
DEFAULT_DOC_TYPE,
3738
DocumentType,
3839
StaticIndex,
3940
StaticType,

src/types/src/document/impls.rs

+5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ use serde_json::Value;
88
use std::borrow::Cow;
99
use std::marker::PhantomData;
1010

11+
/**
12+
The default name for document types in a single document index.
13+
*/
14+
pub const DEFAULT_DOC_TYPE: &'static str = "doc";
15+
1116
/**
1217
An indexable Elasticsearch type.
1318

src/types_derive_internals/src/elastic_type/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ fn get_doc_ty_impl_block(
164164

165165
// Get the default method blocks for `DocumentType`
166166
fn get_doc_type_methods(
167+
crate_root: &Tokens,
167168
item: &syn::MacroInput,
168169
fields: &[(syn::Ident, &syn::Field)],
169170
) -> ElasticMetadataMethods {
@@ -190,7 +191,7 @@ fn get_doc_ty_impl_block(
190191
match get_method_from_struct(item, "ty") {
191192
Some(MethodFromStruct::Literal(name)) => (name, true),
192193
Some(MethodFromStruct::Expr(method)) => (quote!(#method(self)), false),
193-
_ => (quote!("doc"), true),
194+
_ => (quote!(#crate_root::derive::DEFAULT_DOC_TYPE), true),
194195
}
195196
};
196197

@@ -224,7 +225,7 @@ fn get_doc_ty_impl_block(
224225
ref ty,
225226
ty_is_static,
226227
ref id,
227-
} = get_doc_type_methods(item, fields);
228+
} = get_doc_type_methods(crate_root, item, fields);
228229

229230
let doc_ty = &item.ident;
230231

0 commit comments

Comments
 (0)