Skip to content

Commit 11be8c1

Browse files
authored
Merge pull request #13 from typesense/tests
chore: model generation fix
2 parents b60bf65 + ad102fa commit 11be8c1

File tree

17 files changed

+510
-17
lines changed

17 files changed

+510
-17
lines changed

.circleci/config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ jobs:
4040
name: Run Typesense
4141
command: mkdir data && typesense-server --data-dir ./data --api-key=xyz
4242
background: true
43+
- run:
44+
name: Fetch JSONL file
45+
command: sudo bash -c "curl https://gist.githubusercontent.com/harisarang/62a43d8a6c2dcf8d51ea4eab9d90c0c3/raw/090284f8c2aefaacba161b05cf2382836cadc31f/books.jsonl > /books.jsonl"
4346

4447
# Download and cache dependencies
4548
- restore_cache:

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.gradle/
22
.idea/
33
**/build
4-
.out/
4+
.out/
5+
**/books.jsonl

src/main/java/org/typesense/api/Client.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class Client {
1414
private HashMap<String, Alias> individualAliases;
1515

1616
private Keys keys;
17-
private HashMap<String, Key> individualKeys;
17+
private HashMap<Long, Key> individualKeys;
1818

1919
public Health health;
2020
public Operations operations;
@@ -30,7 +30,7 @@ public class Client {
3030
this.aliases = new Aliases(this.apiCall);
3131
this.individualAliases = new HashMap<>();
3232
this.keys = new Keys(this.apiCall);
33-
this.individualKeys = new HashMap<>();
33+
this.individualKeys = new HashMap<Long, Key>();
3434
this.health = new Health(this.apiCall);
3535
this.operations = new Operations(this.apiCall);
3636
this.metrics = new Metrics(this.apiCall);
@@ -74,7 +74,7 @@ public Keys keys(){
7474
return this.keys;
7575
}
7676

77-
public Key keys(String id){
77+
public Key keys(Long id){
7878
Key retVal;
7979

8080
if(!this.individualKeys.containsKey(id)){

src/main/java/org/typesense/api/Key.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
public class Key {
66

7-
private String id;
7+
private Long id;
88
private ApiCall apiCall;
99

10-
public Key(String id, ApiCall apiCall) {
10+
public Key(Long id, ApiCall apiCall) {
1111
this.id = id;
1212
this.apiCall = apiCall;
1313
}

src/main/java/org/typesense/api/Keys.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ public Keys(ApiCall apiCall) {
2222
}
2323

2424
public ApiKey create(ApiKeySchema apiKeySchema){
25+
if (apiKeySchema.getExpiresAt() == null) {
26+
apiKeySchema.setExpiresAt(System.currentTimeMillis() / 1000L + 315360000); // Adding 10 years for expiration.
27+
}
2528
return this.apiCall.post(Keys.RESOURCEPATH, apiKeySchema, ApiKey.class);
2629
}
2730

src/main/java/org/typesense/api/Synonyms.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ public Synonyms(String collectionName, ApiCall apiCall) {
1616
}
1717

1818
public SearchSynonym upsert(String synonymId, SearchSynonymSchema searchSynonymSchema){
19+
if (searchSynonymSchema.getRoot() == null) {
20+
searchSynonymSchema.setRoot("");
21+
}
1922
return this.apiCall.put(getEndpoint(synonymId), searchSynonymSchema,SearchSynonym.class);
2023
}
2124

src/main/java/org/typesense/model/ApiKeySchema.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class ApiKeySchema {
2626
@Schema(required = true, description = "")
2727
private List<String> collections = new ArrayList<String>();
2828

29-
@Schema(required = true, description = "")
29+
@Schema(description = "")
3030
private Long expiresAt = null;
3131
/**
3232
* Get description

src/main/java/org/typesense/model/ExportDocumentsParameters.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@ public class ExportDocumentsParameters {
2323
**/
2424
private String filterBy = null;
2525

26-
@Schema(description = "List of fields from the document to include in the search result")
26+
@Schema(required = true, description = "List of fields from the document to include in the search result")
2727
/**
2828
* List of fields from the document to include in the search result
2929
**/
30-
private List<String> includeFields = null;
30+
private List<String> includeFields = new ArrayList<String>();
3131

32-
@Schema(description = "List of fields from the document to exclude in the search result")
32+
@Schema(required = true, description = "List of fields from the document to exclude in the search result")
3333
/**
3434
* List of fields from the document to exclude in the search result
3535
**/
36-
private List<String> excludeFields = null;
36+
private List<String> excludeFields = new ArrayList<String>();
3737
/**
3838
* Filter conditions for refining your search results. Separate multiple conditions with &amp;&amp;.
3939
* @return filterBy

src/main/java/org/typesense/model/ImportDocumentsParameters.java

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,38 @@ public class ImportDocumentsParameters {
2020

2121
@Schema(description = "")
2222
private Integer batchSize = null;
23+
public enum DirtyValuesEnum {
24+
COERCE_OR_REJECT("coerce_or_reject"),
25+
COERCE_OR_DROP("coerce_or_drop"),
26+
DROP("drop"),
27+
REJECT("reject");
28+
29+
private String value;
30+
31+
DirtyValuesEnum(String value) {
32+
this.value = value;
33+
}
34+
@JsonValue
35+
public String getValue() {
36+
return value;
37+
}
38+
39+
@Override
40+
public String toString() {
41+
return String.valueOf(value);
42+
}
43+
@JsonCreator
44+
public static DirtyValuesEnum fromValue(String text) {
45+
for (DirtyValuesEnum b : DirtyValuesEnum.values()) {
46+
if (String.valueOf(b.value).equals(text)) {
47+
return b;
48+
}
49+
}
50+
return null;
51+
}
52+
}
53+
@Schema(description = "")
54+
private DirtyValuesEnum dirtyValues = null;
2355
/**
2456
* Get action
2557
* @return action
@@ -56,6 +88,27 @@ public ImportDocumentsParameters batchSize(Integer batchSize) {
5688
return this;
5789
}
5890

91+
/**
92+
* Get dirtyValues
93+
* @return dirtyValues
94+
**/
95+
@JsonProperty("dirty_values")
96+
public String getDirtyValues() {
97+
if (dirtyValues == null) {
98+
return null;
99+
}
100+
return dirtyValues.getValue();
101+
}
102+
103+
public void setDirtyValues(DirtyValuesEnum dirtyValues) {
104+
this.dirtyValues = dirtyValues;
105+
}
106+
107+
public ImportDocumentsParameters dirtyValues(DirtyValuesEnum dirtyValues) {
108+
this.dirtyValues = dirtyValues;
109+
return this;
110+
}
111+
59112

60113
@Override
61114
public String toString() {
@@ -64,6 +117,7 @@ public String toString() {
64117

65118
sb.append(" action: ").append(toIndentedString(action)).append("\n");
66119
sb.append(" batchSize: ").append(toIndentedString(batchSize)).append("\n");
120+
sb.append(" dirtyValues: ").append(toIndentedString(dirtyValues)).append("\n");
67121
sb.append("}");
68122
return sb.toString();
69123
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package org.typesense.api;
2+
3+
import junit.framework.TestCase;
4+
import org.typesense.model.CollectionAlias;
5+
import org.typesense.model.CollectionAliasSchema;
6+
import org.typesense.model.CollectionAliasesResponse;
7+
import org.typesense.resources.Node;
8+
9+
import java.time.Duration;
10+
import java.util.ArrayList;
11+
12+
public class AliasesTest extends TestCase {
13+
14+
private Client client;
15+
private Helper helper;
16+
17+
public void setUp() throws Exception {
18+
super.setUp();
19+
helper = new Helper();
20+
client = helper.getClient();
21+
helper.createTestAlias();
22+
}
23+
24+
public void tearDown() throws Exception {
25+
super.tearDown();
26+
helper.teardown();
27+
}
28+
29+
public void testUpsert() {
30+
CollectionAliasSchema collectionAliasSchema = new CollectionAliasSchema();
31+
collectionAliasSchema.collectionName("books_june11");
32+
33+
System.out.println(client.aliases().upsert("books1", collectionAliasSchema));
34+
}
35+
36+
public void testRetrieveAll() {
37+
CollectionAliasesResponse collectionAliasesResponse = client.aliases().retrieve();
38+
39+
System.out.println(collectionAliasesResponse);
40+
}
41+
42+
public void testRetrieveSingleAlias() {
43+
CollectionAlias collectionAlias = client.aliases("books").retrieve();
44+
45+
System.out.println(collectionAlias);
46+
}
47+
48+
public void testDelete() {
49+
CollectionAlias collectionAlias = client.aliases("books").delete();
50+
51+
System.out.println(collectionAlias);
52+
}
53+
}

0 commit comments

Comments
 (0)