Skip to content

Commit 793a86e

Browse files
author
Philip Z
committed
feat: render structured checker paths
Fixes #80
1 parent 3f5fb99 commit 793a86e

37 files changed

Lines changed: 108 additions & 36 deletions

File tree

‎examples/conformance/lib/pom.xml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
<dependency>
5353
<groupId>io.teaql</groupId>
5454
<artifactId>teaql-sqlite</artifactId>
55-
<version>1.538-RELEASE</version>
55+
<version>1.539-RELEASE</version>
5656
</dependency>
5757
<dependency>
5858
<groupId>io.teaql</groupId>
@@ -124,4 +124,4 @@
124124
<url>https://maven.teaql.io/repository/maven-releases/</url>
125125
</repository>
126126
</distributionManagement>
127-
</project>
127+
</project>

‎pom.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>io.teaql</groupId>
88
<artifactId>teaql-java-parent</artifactId>
9-
<version>1.538-RELEASE</version>
9+
<version>1.539-RELEASE</version>
1010
<packaging>pom</packaging>
1111

1212
<name>teaql-java-parent</name>

‎teaql-android/pom.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>io.teaql</groupId>
99
<artifactId>teaql-java-parent</artifactId>
10-
<version>1.538-RELEASE</version>
10+
<version>1.539-RELEASE</version>
1111
</parent>
1212

1313
<artifactId>teaql-android</artifactId>

‎teaql-business-id-jdbc/pom.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>io.teaql</groupId>
99
<artifactId>teaql-java-parent</artifactId>
10-
<version>1.538-RELEASE</version>
10+
<version>1.539-RELEASE</version>
1111
<relativePath>../pom.xml</relativePath>
1212
</parent>
1313

‎teaql-cloud/pom.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>io.teaql</groupId>
88
<artifactId>teaql-java-parent</artifactId>
9-
<version>1.538-RELEASE</version>
9+
<version>1.539-RELEASE</version>
1010
</parent>
1111
<artifactId>teaql-cloud</artifactId>
1212
<name>teaql-cloud</name>

‎teaql-context-runtime-tools/pom.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>io.teaql</groupId>
88
<artifactId>teaql-java-parent</artifactId>
9-
<version>1.538-RELEASE</version>
9+
<version>1.539-RELEASE</version>
1010
</parent>
1111

1212
<artifactId>teaql-context-runtime-tools</artifactId>

‎teaql-core/pom.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>io.teaql</groupId>
99
<artifactId>teaql-java-parent</artifactId>
10-
<version>1.538-RELEASE</version>
10+
<version>1.539-RELEASE</version>
1111
<relativePath>../pom.xml</relativePath>
1212
</parent>
1313

‎teaql-core/src/main/java/io/teaql/core/checker/ObjectLocation.java‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package io.teaql.core.checker;
22

3+
import java.util.ArrayList;
4+
import java.util.List;
5+
36
public class ObjectLocation {
47
private ObjectLocation parent;
58

@@ -45,4 +48,56 @@ public boolean isSecondLevel() {
4548
public boolean isThirdLevel() {
4649
return getLevel() == 3;
4750
}
51+
52+
/** Canonical casing-neutral path using KSML property names. */
53+
public String modelPath() {
54+
return render(false, false);
55+
}
56+
57+
/** Java diagnostic path using lower-camel property names. */
58+
public String nativePath() {
59+
return render(true, false);
60+
}
61+
62+
/** RFC 6901 JSON pointer using TeaQL's default lower-camel wire policy. */
63+
public String instancePath() {
64+
return render(true, true);
65+
}
66+
67+
private String render(boolean lowerCamel, boolean pointer) {
68+
List<ObjectLocation> locations = new ArrayList<>();
69+
for (ObjectLocation current = this; current != null; current = current.getParent()) {
70+
locations.add(0, current);
71+
}
72+
StringBuilder result = new StringBuilder();
73+
for (ObjectLocation location : locations) {
74+
if (location instanceof HashLocation hash) {
75+
String member = lowerCamel ? lowerCamel(hash.getMember()) : hash.getMember();
76+
if (pointer) {
77+
result.append('/').append(escapePointer(member));
78+
} else {
79+
if (!result.isEmpty()) result.append('.');
80+
result.append(member);
81+
}
82+
} else if (location instanceof ArrayLocation array) {
83+
if (pointer) result.append('/').append(array.getIndex());
84+
else result.append('[').append(array.getIndex()).append(']');
85+
}
86+
}
87+
return result.toString();
88+
}
89+
90+
private static String lowerCamel(String name) {
91+
String[] parts = name.split("_", -1);
92+
StringBuilder result = new StringBuilder(parts.length == 0 ? "" : parts[0]);
93+
for (int i = 1; i < parts.length; i++) {
94+
if (parts[i].isEmpty()) continue;
95+
result.append(Character.toUpperCase(parts[i].charAt(0))).append(parts[i].substring(1));
96+
}
97+
return result.toString();
98+
}
99+
100+
private static String escapePointer(String value) {
101+
return value.replace("~", "~0").replace("/", "~1");
102+
}
48103
}

‎teaql-core/src/test/java/io/teaql/core/checker/ObjectLocationTest.java‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,23 @@
55

66
public class ObjectLocationTest {
77

8+
@Test
9+
public void rendersCanonicalNativeAndExternalPaths() {
10+
ObjectLocation location = ObjectLocation.hashRoot("order_items")
11+
.element(2)
12+
.member("user_url");
13+
14+
assertEquals("order_items[2].user_url", location.modelPath());
15+
assertEquals("orderItems[2].userUrl", location.nativePath());
16+
assertEquals("/orderItems/2/userUrl", location.instancePath());
17+
assertEquals("order_items[2].user_url", location.toString());
18+
}
19+
20+
@Test
21+
public void escapesJsonPointerMembers() {
22+
assertEquals("/a~0~1b", ObjectLocation.hashRoot("a~/b").instancePath());
23+
}
24+
825
@Test
926
public void testObjectLocationFormattingAndNestingLevels() {
1027
// Test hashRoot

‎teaql-data-service-sql/pom.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>io.teaql</groupId>
88
<artifactId>teaql-java-parent</artifactId>
9-
<version>1.538-RELEASE</version>
9+
<version>1.539-RELEASE</version>
1010
<relativePath>../pom.xml</relativePath>
1111
</parent>
1212

0 commit comments

Comments
 (0)