Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 62 additions & 8 deletions buildSrc/src/main/groovy/DownloadSpecsPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,68 @@ class DownloadSpecsPlugin implements Plugin<Project> {
@Override
void apply(Project project) {
project.tasks.register("downloadApiSpec") {
println('Downloading spec')
File file = new File("${project.buildDir}/openapi.yml")
if (!file.getParentFile().exists())
file.getParentFile().mkdirs();
if (!file.exists())
file.createNewFile();
file.withOutputStream { out ->
new URL(specUrl).withInputStream { from -> out << from }
doLast {
println('Downloading spec')
File file = new File("${project.buildDir}/openapi.yml")
if (!file.getParentFile().exists())
file.getParentFile().mkdirs();
if (!file.exists())
file.createNewFile();
file.withOutputStream { out ->
new URL(specUrl).withInputStream { from -> out << from }
}

// Patch the OpenAPI spec to fix SynonymItemSchema allOf issue
// The swagger code generator doesn't handle allOf correctly, so we convert it
// to a direct definition that includes all fields
println('Patching OpenAPI spec for SynonymItemSchema')
String content = file.text

// Find and replace the allOf structure with a direct definition
String allOfBlock = ''' SynonymItemSchema:
allOf:
- type: object
required:
- id
properties:
id:
type: string
description: Unique identifier for the synonym item
- $ref: "#/components/schemas/SynonymItemUpsertSchema"'''

String replacement = ''' SynonymItemSchema:
type: object
required:
- id
- synonyms
properties:
id:
type: string
description: Unique identifier for the synonym item
synonyms:
type: array
description: Array of words that should be considered as synonyms
items:
type: string
root:
type: string
description: For 1-way synonyms, indicates the root word that words in the synonyms parameter map to
locale:
type: string
description: Locale for the synonym, leave blank to use the standard tokenizer
symbols_to_index:
type: array
description: By default, special characters are dropped from synonyms. Use this attribute to specify which special characters should be indexed as is
items:
type: string'''

if (content.contains(allOfBlock)) {
content = content.replace(allOfBlock, replacement)
file.text = content
println('Successfully patched SynonymItemSchema')
} else {
println('Warning: SynonymItemSchema allOf block not found, skipping patch')
}
}
}
}
Expand Down
12 changes: 4 additions & 8 deletions src/main/java/org/typesense/api/AnalyticsRuleSerializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.typesense.model.AnalyticsRule;
import org.typesense.model.AnalyticsRuleCreate;
import org.typesense.model.AnalyticsRuleCreateParams;
import org.typesense.model.AnalyticsRuleType;
import java.util.List;
import java.util.ArrayList;

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

if (node.has("type")) {
String typeStr = node.get("type").asText();
if ("counter".equals(typeStr)) {
rule.type(AnalyticsRuleCreate.TypeEnum.COUNTER);
} else if ("popular_queries".equals(typeStr)) {
rule.type(AnalyticsRuleCreate.TypeEnum.POPULAR_QUERIES);
} else if ("nohits_queries".equals(typeStr)) {
rule.type(AnalyticsRuleCreate.TypeEnum.NOHITS_QUERIES);
} else if ("log".equals(typeStr)) {
rule.type(AnalyticsRuleCreate.TypeEnum.LOG);
AnalyticsRuleType type = AnalyticsRuleType.fromValue(typeStr);
if (type != null) {
rule.type(type);
}
}

Expand Down
15 changes: 8 additions & 7 deletions src/test/java/org/typesense/api/AnalyticsRulesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.typesense.model.AnalyticsRule;
import org.typesense.model.AnalyticsRuleCreate;
import org.typesense.model.AnalyticsRuleCreateParams;
import org.typesense.model.AnalyticsRuleType;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -77,7 +78,7 @@ void testCreate() throws Exception {

AnalyticsRuleCreate analyticsRule = new AnalyticsRuleCreate()
.name(ruleName)
.type(AnalyticsRuleCreate.TypeEnum.COUNTER)
.type(AnalyticsRuleType.COUNTER)
.collection("analytics_data")
.eventType("click")
.params(new AnalyticsRuleCreateParams()
Expand All @@ -95,7 +96,7 @@ void testCreate() throws Exception {
AnalyticsRule createdRule = result.getFirstRule();
assertNotNull(createdRule);
assertEquals(ruleName, createdRule.getName());
assertEquals(AnalyticsRuleCreate.TypeEnum.COUNTER, createdRule.getType());
assertEquals(AnalyticsRuleType.COUNTER, createdRule.getType());
assertEquals("analytics_data", createdRule.getCollection());
assertEquals("click", createdRule.getEventType());
}
Expand All @@ -107,7 +108,7 @@ void testRetrieve() throws Exception {

AnalyticsRuleCreate analyticsRule = new AnalyticsRuleCreate()
.name(ruleName)
.type(AnalyticsRuleCreate.TypeEnum.COUNTER)
.type(AnalyticsRuleType.COUNTER)
.collection("analytics_data")
.eventType("click")
.params(new AnalyticsRuleCreateParams()
Expand All @@ -133,7 +134,7 @@ void testRetrieve() throws Exception {

assertNotNull(foundRule, "rule not found");
assertEquals(ruleName, foundRule.getName());
assertEquals(AnalyticsRuleCreate.TypeEnum.COUNTER, foundRule.getType());
assertEquals(AnalyticsRuleType.COUNTER, foundRule.getType());
assertEquals("analytics_data", foundRule.getCollection());
assertEquals("click", foundRule.getEventType());
}
Expand All @@ -145,7 +146,7 @@ void testRetrieveSingle() throws Exception {

AnalyticsRuleCreate analyticsRule = new AnalyticsRuleCreate()
.name(ruleName)
.type(AnalyticsRuleCreate.TypeEnum.COUNTER)
.type(AnalyticsRuleType.COUNTER)
.collection("analytics_data")
.eventType("click")
.params(new AnalyticsRuleCreateParams()
Expand All @@ -160,7 +161,7 @@ void testRetrieveSingle() throws Exception {
AnalyticsRule result = this.client.analytics().rules(ruleName).retrieve();
assertNotNull(result);
assertEquals(ruleName, result.getName());
assertEquals(AnalyticsRuleCreate.TypeEnum.COUNTER, result.getType());
assertEquals(AnalyticsRuleType.COUNTER, result.getType());
assertEquals("analytics_data", result.getCollection());
assertEquals("click", result.getEventType());
}
Expand All @@ -172,7 +173,7 @@ void testDelete() throws Exception {

AnalyticsRuleCreate analyticsRule = new AnalyticsRuleCreate()
.name(ruleName)
.type(AnalyticsRuleCreate.TypeEnum.COUNTER)
.type(AnalyticsRuleType.COUNTER)
.collection("analytics_data")
.eventType("click")
.params(new AnalyticsRuleCreateParams()
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/org/typesense/api/Helper.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.typesense.model.AnalyticsRuleCreate;
import org.typesense.model.AnalyticsRuleCreateParams;
import org.typesense.model.AnalyticsRule;
import org.typesense.model.AnalyticsRuleType;
import org.typesense.api.AnalyticsRules;

public class Helper {
Expand Down Expand Up @@ -170,7 +171,7 @@ public String createTestAnalyticsRule() throws Exception {

AnalyticsRuleCreate analyticsRule = new AnalyticsRuleCreate()
.name(ruleName)
.type(AnalyticsRuleCreate.TypeEnum.COUNTER)
.type(AnalyticsRuleType.COUNTER)
.collection("analytics_data")
.eventType("click")
.params(new AnalyticsRuleCreateParams()
Expand Down