Skip to content

Commit e236905

Browse files
committed
Owned data in API response models
1 parent df48edb commit e236905

16 files changed

+98
-32
lines changed

openapi-generator-template/model.mustache

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,9 @@ impl Default for {{classname}} {
127127
#[derive(bon::Builder)]
128128
#[builder(on(Cow<'_, str>, into))]
129129
#[builder(on(String, into))]
130-
{{/vendorExtensions.x-rust-builder}}
131-
{{#vendorExtensions.x-rust-has-byte-array}}#[serde_as]
132-
{{/vendorExtensions.x-rust-has-byte-array}}{{#oneOf.isEmpty}}#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
130+
{{/vendorExtensions.x-rust-builder}}{{!
131+
}}{{#vendorExtensions.x-rust-has-byte-array}}#[serde_as]{{/vendorExtensions.x-rust-has-byte-array}}{{!
132+
}}{{#oneOf.isEmpty}}#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
133133
pub struct {{{classname}}}<'a{{#vendorExtensions.x-rust-generic-parameter}}, {{{.}}}{{/vendorExtensions.x-rust-generic-parameter}}> {
134134
{{#vars}}
135135
{{#description}}
@@ -153,7 +153,7 @@ pub struct {{{classname}}}<'a{{#vendorExtensions.x-rust-generic-parameter}}, {{{
153153
### ByteArray
154154
}}{{^isModel}}{{#isByteArray}}Vec<u8>{{/isByteArray}}{{!
155155
### String
156-
}}{{^isByteArray}}{{#isString}}Cow<'a, str>{{/isString}}{{!
156+
}}{{^isByteArray}}{{#isString}}{{#model}}{{#vendorExtensions.x-rust-is-owned-data}}String{{/vendorExtensions.x-rust-is-owned-data}}{{^vendorExtensions.x-rust-is-owned-data}}Cow<'a, str>{{/vendorExtensions.x-rust-is-owned-data}}{{/model}}{{/isString}}{{!
157157
### Arrays
158158
}}{{^isString}}{{#isArray}}Vec<{{#items}}{{!
159159
### Array Models
@@ -186,7 +186,7 @@ impl<'a{{#vendorExtensions.x-rust-generic-parameter}}, {{{.}}}{{/vendorExtension
186186
}}{{^vendorExtensions.x-rust-type}}{{#isNullable}}Option<{{/isNullable}}{{!
187187
}}{{#isEnum}}{{#isArray}}{{#uniqueItems}}std::collections::HashSet<{{/uniqueItems}}{{^uniqueItems}}Vec<{{/uniqueItems}}{{/isArray}}{{{enumName}}}{{#isArray}}>{{/isArray}}{{/isEnum}}{{!
188188
}}{{^isEnum}}{{#isByteArray}}Vec<u8>{{/isByteArray}}{{!
189-
}}{{^isByteArray}}{{#isString}}Cow<'a, str>{{/isString}}{{!
189+
}}{{^isByteArray}}{{#isString}}{{#model}}{{#vendorExtensions.x-rust-is-owned-data}}String{{/vendorExtensions.x-rust-is-owned-data}}{{^vendorExtensions.x-rust-is-owned-data}}Cow<'a, str>{{/vendorExtensions.x-rust-is-owned-data}}{{/model}}{{/isString}}{{!
190190
}}{{^isString}}{{#isArray}}Vec<{{#items}}{{!
191191
}}{{#isModel}}{{{dataType}}}<'a>{{/isModel}}{{!
192192
}}{{^isModel}}{{{dataType}}}{{/isModel}}{{/items}}>{{/isArray}}{{!

preprocessed_openapi.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3226,6 +3226,7 @@ components:
32263226
description: Timestamp of when the collection was created (Unix epoch in seconds)
32273227
format: int64
32283228
readOnly: true
3229+
x-rust-is-owned-data: true
32293230
Field:
32303231
required:
32313232
- name
@@ -3381,6 +3382,7 @@ components:
33813382
x-go-type: '[]*CollectionAlias'
33823383
items:
33833384
$ref: '#/components/schemas/CollectionAlias'
3385+
x-rust-is-owned-data: true
33843386
SearchResult:
33853387
type: object
33863388
properties:
@@ -3429,7 +3431,9 @@ components:
34293431
type: object
34303432
description: Custom JSON object that can be returned in the search response
34313433
additionalProperties: true
3434+
x-rust-is-owned-data: true
34323435
x-rust-generic-parameter: D
3436+
x-rust-is-owned-data: true
34333437
SearchRequestParams:
34343438
type: object
34353439
required:
@@ -3448,6 +3452,8 @@ components:
34483452
properties:
34493453
transcribed_query:
34503454
type: string
3455+
x-rust-is-owned-data: true
3456+
x-rust-is-owned-data: true
34513457
SearchResultConversation:
34523458
type: object
34533459
required:
@@ -3466,6 +3472,7 @@ components:
34663472
type: string
34673473
query:
34683474
type: string
3475+
x-rust-is-owned-data: true
34693476
SearchGroupedHit:
34703477
type: object
34713478
required:
@@ -3484,6 +3491,7 @@ components:
34843491
$ref: '#/components/schemas/SearchResultHit'
34853492
x-rust-type: Vec<models::SearchResultHit<'a, D>>
34863493
x-rust-generic-parameter: D
3494+
x-rust-is-owned-data: true
34873495
SearchResultHit:
34883496
type: object
34893497
properties:
@@ -3496,12 +3504,14 @@ components:
34963504
type: object
34973505
description: Highlighted version of the matching document
34983506
additionalProperties: true
3507+
x-rust-is-owned-data: true
34993508
document:
35003509
type: object
35013510
description: Can be any key-value pair
35023511
additionalProperties:
35033512
type: object
35043513
x-rust-type: Option<D>
3514+
x-rust-is-owned-data: true
35053515
text_match:
35063516
type: integer
35073517
format: int64
@@ -3524,11 +3534,13 @@ components:
35243534
type: integer
35253535
typo_prefix_score:
35263536
type: integer
3537+
x-rust-is-owned-data: true
35273538
geo_distance_meters:
35283539
type: object
35293540
description: Can be any key-value pair
35303541
additionalProperties:
35313542
type: integer
3543+
x-rust-is-owned-data: true
35323544
vector_distance:
35333545
type: number
35343546
format: float
@@ -3541,6 +3553,7 @@ components:
35413553
type: number
35423554
format: float
35433555
description: Combined score from rank fusion of text and vector search
3556+
x-rust-is-owned-data: true
35443557
search_index:
35453558
type: integer
35463559
description: Returned only for union query response. Indicates the index of the query which this document matched to.
@@ -3556,6 +3569,7 @@ components:
35563569
country: USA
35573570
text_match: 1234556
35583571
x-rust-generic-parameter: D
3572+
x-rust-is-owned-data: true
35593573
SearchHighlight:
35603574
type: object
35613575
properties:
@@ -3597,6 +3611,7 @@ components:
35973611
items:
35983612
type: object
35993613
x-go-type: interface{}
3614+
x-rust-is-owned-data: true
36003615
SearchSynonymSchema:
36013616
type: object
36023617
required:
@@ -3636,6 +3651,7 @@ components:
36363651
id:
36373652
type: string
36383653
description: The id of the synonym that was deleted
3654+
x-rust-is-owned-data: true
36393655
SearchSynonymsResponse:
36403656
type: object
36413657
required:
@@ -3646,13 +3662,15 @@ components:
36463662
x-go-type: '[]*SearchSynonym'
36473663
items:
36483664
$ref: '#/components/schemas/SearchSynonym'
3665+
x-rust-is-owned-data: true
36493666
HealthStatus:
36503667
type: object
36513668
required:
36523669
- ok
36533670
properties:
36543671
ok:
36553672
type: boolean
3673+
x-rust-is-owned-data: true
36563674
SchemaChangeStatus:
36573675
type: object
36583676
properties:
@@ -3665,20 +3683,23 @@ components:
36653683
altered_docs:
36663684
type: integer
36673685
description: Number of documents that have been altered
3686+
x-rust-is-owned-data: true
36683687
SuccessStatus:
36693688
type: object
36703689
required:
36713690
- success
36723691
properties:
36733692
success:
36743693
type: boolean
3694+
x-rust-is-owned-data: true
36753695
ApiResponse:
36763696
type: object
36773697
required:
36783698
- message
36793699
properties:
36803700
message:
36813701
type: string
3702+
x-rust-is-owned-data: true
36823703
ApiKeySchema:
36833704
type: object
36843705
required:
@@ -3722,6 +3743,7 @@ components:
37223743
type: integer
37233744
format: int64
37243745
description: The id of the API key that was deleted
3746+
x-rust-is-owned-data: true
37253747
ApiKeysResponse:
37263748
type: object
37273749
required:
@@ -3732,6 +3754,7 @@ components:
37323754
x-go-type: '[]*ApiKey'
37333755
items:
37343756
$ref: '#/components/schemas/ApiKey'
3757+
x-rust-is-owned-data: true
37353758
MultiSearchResult:
37363759
type: object
37373760
required:
@@ -3745,6 +3768,7 @@ components:
37453768
conversation:
37463769
$ref: '#/components/schemas/SearchResultConversation'
37473770
x-rust-generic-parameter: D
3771+
x-rust-is-owned-data: true
37483772
MultiSearchResultItem:
37493773
allOf:
37503774
- $ref: '#/components/schemas/SearchResult'
@@ -3758,6 +3782,7 @@ components:
37583782
type: string
37593783
description: Error description
37603784
x-rust-generic-parameter: D
3785+
x-rust-is-owned-data: true
37613786
SearchParameters:
37623787
type: object
37633788
properties:
@@ -4355,6 +4380,7 @@ components:
43554380
properties:
43564381
ok:
43574382
type: boolean
4383+
x-rust-is-owned-data: true
43584384
AnalyticsEvent:
43594385
type: object
43604386
required:
@@ -4413,6 +4439,7 @@ components:
44134439
type: string
44144440
query:
44154441
type: string
4442+
x-rust-is-owned-data: true
44164443
AnalyticsRuleCreate:
44174444
type: object
44184445
required:
@@ -4503,6 +4530,7 @@ components:
45034530
type: integer
45044531
doc_counter_events:
45054532
type: integer
4533+
x-rust-is-owned-data: true
45064534
APIStatsResponse:
45074535
type: object
45084536
properties:
@@ -4521,6 +4549,7 @@ components:
45214549
latency_ms:
45224550
type: object
45234551
x-go-type: map[string]float64
4552+
x-rust-is-owned-data: true
45244553
overloaded_requests_per_second:
45254554
type: number
45264555
format: double
@@ -4530,6 +4559,7 @@ components:
45304559
requests_per_second:
45314560
type: object
45324561
x-go-type: map[string]float64
4562+
x-rust-is-owned-data: true
45334563
search_latency_ms:
45344564
type: number
45354565
format: double
@@ -4545,6 +4575,7 @@ components:
45454575
write_requests_per_second:
45464576
type: number
45474577
format: double
4578+
x-rust-is-owned-data: true
45484579
StopwordsSetUpsertSchema:
45494580
type: object
45504581
properties:

typesense/src/traits/multi_search_ext.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ impl<'a> MultiSearchResultExt<'a> for MultiSearchResult<'a, Value> {
119119
if let Some(error_msg) = &raw_item.error {
120120
return Err(MultiSearchParseError::ApiError {
121121
index,
122-
message: error_msg.clone().into_owned(),
122+
message: error_msg.clone(),
123123
});
124124
}
125125

typesense_codegen/src/models/api_response.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ use serde::{Deserialize, Serialize};
1515
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
1616
pub struct ApiResponse<'a> {
1717
#[serde(rename = "message")]
18-
pub message: Cow<'a, str>,
18+
pub message: String,
1919
#[serde(skip)]
2020
pub _phantom: PhantomData<&'a ()>,
2121
}
2222

2323
impl<'a> ApiResponse<'a> {
24-
pub fn new(message: Cow<'a, str>) -> Self {
24+
pub fn new(message: String) -> Self {
2525
Self {
2626
message,
2727
_phantom: PhantomData,

typesense_codegen/src/models/collection_response.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use serde::{Deserialize, Serialize};
1616
pub struct CollectionResponse<'a> {
1717
/// Name of the collection
1818
#[serde(rename = "name")]
19-
pub name: Cow<'a, str>,
19+
pub name: String,
2020
/// A list of fields for querying, filtering and faceting
2121
#[serde(rename = "fields")]
2222
pub fields: Vec<models::Field<'a>>,
@@ -25,7 +25,7 @@ pub struct CollectionResponse<'a> {
2525
rename = "default_sorting_field",
2626
skip_serializing_if = "Option::is_none"
2727
)]
28-
pub default_sorting_field: Option<Cow<'a, str>>,
28+
pub default_sorting_field: Option<String>,
2929
/// List of symbols or special characters to be used for splitting the text into individual words in addition to space and new-line characters.
3030
#[serde(rename = "token_separators", skip_serializing_if = "Option::is_none")]
3131
pub token_separators: Option<Vec<String>>,
@@ -58,7 +58,7 @@ pub struct CollectionResponse<'a> {
5858

5959
impl<'a> CollectionResponse<'a> {
6060
pub fn new(
61-
name: Cow<'a, str>,
61+
name: String,
6262
fields: Vec<models::Field<'a>>,
6363
num_documents: i64,
6464
created_at: i64,

typesense_codegen/src/models/multi_search_result_item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub struct MultiSearchResultItem<'a, D> {
5656
pub code: Option<i64>,
5757
/// Error description
5858
#[serde(rename = "error", skip_serializing_if = "Option::is_none")]
59-
pub error: Option<Cow<'a, str>>,
59+
pub error: Option<String>,
6060
#[serde(skip)]
6161
pub _phantom: PhantomData<&'a ()>,
6262
}

typesense_codegen/src/models/schema_change_status.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use serde::{Deserialize, Serialize};
1616
pub struct SchemaChangeStatus<'a> {
1717
/// Name of the collection being modified
1818
#[serde(rename = "collection", skip_serializing_if = "Option::is_none")]
19-
pub collection: Option<Cow<'a, str>>,
19+
pub collection: Option<String>,
2020
/// Number of documents that have been validated
2121
#[serde(rename = "validated_docs", skip_serializing_if = "Option::is_none")]
2222
pub validated_docs: Option<i32>,

typesense_codegen/src/models/search_highlight.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ use serde::{Deserialize, Serialize};
1515
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
1616
pub struct SearchHighlight<'a> {
1717
#[serde(rename = "field", skip_serializing_if = "Option::is_none")]
18-
pub field: Option<Cow<'a, str>>,
18+
pub field: Option<String>,
1919
/// Present only for (non-array) string fields
2020
#[serde(rename = "snippet", skip_serializing_if = "Option::is_none")]
21-
pub snippet: Option<Cow<'a, str>>,
21+
pub snippet: Option<String>,
2222
/// Present only for (array) string[] fields
2323
#[serde(rename = "snippets", skip_serializing_if = "Option::is_none")]
2424
pub snippets: Option<Vec<String>>,
2525
/// Full field value with highlighting, present only for (non-array) string fields
2626
#[serde(rename = "value", skip_serializing_if = "Option::is_none")]
27-
pub value: Option<Cow<'a, str>>,
27+
pub value: Option<String>,
2828
/// Full field value with highlighting, present only for (array) string[] fields
2929
#[serde(rename = "values", skip_serializing_if = "Option::is_none")]
3030
pub values: Option<Vec<String>>,

typesense_codegen/src/models/search_request_params.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ use serde::{Deserialize, Serialize};
1515
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
1616
pub struct SearchRequestParams<'a> {
1717
#[serde(rename = "collection_name")]
18-
pub collection_name: Cow<'a, str>,
18+
pub collection_name: String,
1919
#[serde(rename = "q")]
20-
pub q: Cow<'a, str>,
20+
pub q: String,
2121
#[serde(rename = "per_page")]
2222
pub per_page: i32,
2323
#[serde(rename = "voice_query", skip_serializing_if = "Option::is_none")]
@@ -27,7 +27,7 @@ pub struct SearchRequestParams<'a> {
2727
}
2828

2929
impl<'a> SearchRequestParams<'a> {
30-
pub fn new(collection_name: Cow<'a, str>, q: Cow<'a, str>, per_page: i32) -> Self {
30+
pub fn new(collection_name: String, q: String, per_page: i32) -> Self {
3131
Self {
3232
collection_name,
3333
q,

typesense_codegen/src/models/search_request_params_voice_query.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use serde::{Deserialize, Serialize};
1515
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
1616
pub struct SearchRequestParamsVoiceQuery<'a> {
1717
#[serde(rename = "transcribed_query", skip_serializing_if = "Option::is_none")]
18-
pub transcribed_query: Option<Cow<'a, str>>,
18+
pub transcribed_query: Option<String>,
1919
#[serde(skip)]
2020
pub _phantom: PhantomData<&'a ()>,
2121
}

0 commit comments

Comments
 (0)