Skip to content

Commit e473a92

Browse files
tharropoulosFanis
andauthored
V30.0 spec updates (#99)
* fix(analytics): fix analytics types based on api spec changes * chore: patch spec generation for synonymset items --------- Co-authored-by: Fanis <[email protected]>
1 parent 9e7514d commit e473a92

File tree

4 files changed

+76
-24
lines changed

4 files changed

+76
-24
lines changed

buildSrc/src/main/groovy/DownloadSpecsPlugin.groovy

Lines changed: 62 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,68 @@ class DownloadSpecsPlugin implements Plugin<Project> {
1111
@Override
1212
void apply(Project project) {
1313
project.tasks.register("downloadApiSpec") {
14-
println('Downloading spec')
15-
File file = new File("${project.buildDir}/openapi.yml")
16-
if (!file.getParentFile().exists())
17-
file.getParentFile().mkdirs();
18-
if (!file.exists())
19-
file.createNewFile();
20-
file.withOutputStream { out ->
21-
new URL(specUrl).withInputStream { from -> out << from }
14+
doLast {
15+
println('Downloading spec')
16+
File file = new File("${project.buildDir}/openapi.yml")
17+
if (!file.getParentFile().exists())
18+
file.getParentFile().mkdirs();
19+
if (!file.exists())
20+
file.createNewFile();
21+
file.withOutputStream { out ->
22+
new URL(specUrl).withInputStream { from -> out << from }
23+
}
24+
25+
// Patch the OpenAPI spec to fix SynonymItemSchema allOf issue
26+
// The swagger code generator doesn't handle allOf correctly, so we convert it
27+
// to a direct definition that includes all fields
28+
println('Patching OpenAPI spec for SynonymItemSchema')
29+
String content = file.text
30+
31+
// Find and replace the allOf structure with a direct definition
32+
String allOfBlock = ''' SynonymItemSchema:
33+
allOf:
34+
- type: object
35+
required:
36+
- id
37+
properties:
38+
id:
39+
type: string
40+
description: Unique identifier for the synonym item
41+
- $ref: "#/components/schemas/SynonymItemUpsertSchema"'''
42+
43+
String replacement = ''' SynonymItemSchema:
44+
type: object
45+
required:
46+
- id
47+
- synonyms
48+
properties:
49+
id:
50+
type: string
51+
description: Unique identifier for the synonym item
52+
synonyms:
53+
type: array
54+
description: Array of words that should be considered as synonyms
55+
items:
56+
type: string
57+
root:
58+
type: string
59+
description: For 1-way synonyms, indicates the root word that words in the synonyms parameter map to
60+
locale:
61+
type: string
62+
description: Locale for the synonym, leave blank to use the standard tokenizer
63+
symbols_to_index:
64+
type: array
65+
description: By default, special characters are dropped from synonyms. Use this attribute to specify which special characters should be indexed as is
66+
items:
67+
type: string'''
68+
69+
if (content.contains(allOfBlock)) {
70+
content = content.replace(allOfBlock, replacement)
71+
file.text = content
72+
println('Successfully patched SynonymItemSchema')
73+
} else {
74+
println('Warning: SynonymItemSchema allOf block not found, skipping patch')
75+
}
2276
}
2377
}
2478
}

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.typesense.model.AnalyticsRule;
77
import org.typesense.model.AnalyticsRuleCreate;
88
import org.typesense.model.AnalyticsRuleCreateParams;
9+
import org.typesense.model.AnalyticsRuleType;
910
import java.util.List;
1011
import java.util.ArrayList;
1112

@@ -34,14 +35,9 @@ public AnalyticsRule parseFromJsonNode(JsonNode node) {
3435

3536
if (node.has("type")) {
3637
String typeStr = node.get("type").asText();
37-
if ("counter".equals(typeStr)) {
38-
rule.type(AnalyticsRuleCreate.TypeEnum.COUNTER);
39-
} else if ("popular_queries".equals(typeStr)) {
40-
rule.type(AnalyticsRuleCreate.TypeEnum.POPULAR_QUERIES);
41-
} else if ("nohits_queries".equals(typeStr)) {
42-
rule.type(AnalyticsRuleCreate.TypeEnum.NOHITS_QUERIES);
43-
} else if ("log".equals(typeStr)) {
44-
rule.type(AnalyticsRuleCreate.TypeEnum.LOG);
38+
AnalyticsRuleType type = AnalyticsRuleType.fromValue(typeStr);
39+
if (type != null) {
40+
rule.type(type);
4541
}
4642
}
4743

src/test/java/org/typesense/api/AnalyticsRulesTest.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.typesense.model.AnalyticsRule;
88
import org.typesense.model.AnalyticsRuleCreate;
99
import org.typesense.model.AnalyticsRuleCreateParams;
10+
import org.typesense.model.AnalyticsRuleType;
1011

1112
import java.util.ArrayList;
1213
import java.util.List;
@@ -77,7 +78,7 @@ void testCreate() throws Exception {
7778

7879
AnalyticsRuleCreate analyticsRule = new AnalyticsRuleCreate()
7980
.name(ruleName)
80-
.type(AnalyticsRuleCreate.TypeEnum.COUNTER)
81+
.type(AnalyticsRuleType.COUNTER)
8182
.collection("analytics_data")
8283
.eventType("click")
8384
.params(new AnalyticsRuleCreateParams()
@@ -95,7 +96,7 @@ void testCreate() throws Exception {
9596
AnalyticsRule createdRule = result.getFirstRule();
9697
assertNotNull(createdRule);
9798
assertEquals(ruleName, createdRule.getName());
98-
assertEquals(AnalyticsRuleCreate.TypeEnum.COUNTER, createdRule.getType());
99+
assertEquals(AnalyticsRuleType.COUNTER, createdRule.getType());
99100
assertEquals("analytics_data", createdRule.getCollection());
100101
assertEquals("click", createdRule.getEventType());
101102
}
@@ -107,7 +108,7 @@ void testRetrieve() throws Exception {
107108

108109
AnalyticsRuleCreate analyticsRule = new AnalyticsRuleCreate()
109110
.name(ruleName)
110-
.type(AnalyticsRuleCreate.TypeEnum.COUNTER)
111+
.type(AnalyticsRuleType.COUNTER)
111112
.collection("analytics_data")
112113
.eventType("click")
113114
.params(new AnalyticsRuleCreateParams()
@@ -133,7 +134,7 @@ void testRetrieve() throws Exception {
133134

134135
assertNotNull(foundRule, "rule not found");
135136
assertEquals(ruleName, foundRule.getName());
136-
assertEquals(AnalyticsRuleCreate.TypeEnum.COUNTER, foundRule.getType());
137+
assertEquals(AnalyticsRuleType.COUNTER, foundRule.getType());
137138
assertEquals("analytics_data", foundRule.getCollection());
138139
assertEquals("click", foundRule.getEventType());
139140
}
@@ -145,7 +146,7 @@ void testRetrieveSingle() throws Exception {
145146

146147
AnalyticsRuleCreate analyticsRule = new AnalyticsRuleCreate()
147148
.name(ruleName)
148-
.type(AnalyticsRuleCreate.TypeEnum.COUNTER)
149+
.type(AnalyticsRuleType.COUNTER)
149150
.collection("analytics_data")
150151
.eventType("click")
151152
.params(new AnalyticsRuleCreateParams()
@@ -160,7 +161,7 @@ void testRetrieveSingle() throws Exception {
160161
AnalyticsRule result = this.client.analytics().rules(ruleName).retrieve();
161162
assertNotNull(result);
162163
assertEquals(ruleName, result.getName());
163-
assertEquals(AnalyticsRuleCreate.TypeEnum.COUNTER, result.getType());
164+
assertEquals(AnalyticsRuleType.COUNTER, result.getType());
164165
assertEquals("analytics_data", result.getCollection());
165166
assertEquals("click", result.getEventType());
166167
}
@@ -172,7 +173,7 @@ void testDelete() throws Exception {
172173

173174
AnalyticsRuleCreate analyticsRule = new AnalyticsRuleCreate()
174175
.name(ruleName)
175-
.type(AnalyticsRuleCreate.TypeEnum.COUNTER)
176+
.type(AnalyticsRuleType.COUNTER)
176177
.collection("analytics_data")
177178
.eventType("click")
178179
.params(new AnalyticsRuleCreateParams()

src/test/java/org/typesense/api/Helper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.typesense.model.AnalyticsRuleCreate;
3434
import org.typesense.model.AnalyticsRuleCreateParams;
3535
import org.typesense.model.AnalyticsRule;
36+
import org.typesense.model.AnalyticsRuleType;
3637
import org.typesense.api.AnalyticsRules;
3738

3839
public class Helper {
@@ -170,7 +171,7 @@ public String createTestAnalyticsRule() throws Exception {
170171

171172
AnalyticsRuleCreate analyticsRule = new AnalyticsRuleCreate()
172173
.name(ruleName)
173-
.type(AnalyticsRuleCreate.TypeEnum.COUNTER)
174+
.type(AnalyticsRuleType.COUNTER)
174175
.collection("analytics_data")
175176
.eventType("click")
176177
.params(new AnalyticsRuleCreateParams()

0 commit comments

Comments
 (0)