Skip to content

Commit

Permalink
fix: fix Renarde url computation
Browse files Browse the repository at this point in the history
Signed-off-by: Fred Bricon <[email protected]>
  • Loading branch information
fbricon committed Jul 6, 2023
1 parent 3086738 commit 7da1e83
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package rest;

import javax.ws.rs.Path;
import io.quarkiverse.renarde.Controller;

@Path("/play")
public class Game extends Controller {

@Path("/id")
public String endpoint() {
return "id";
}

public String start() {
return "start";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,8 @@ public List<JaxRsMethodInfo> getJaxRsMethodInfo(PsiFile typeRoot, JaxRsContext j
if (type == null) {
return Collections.emptyList();
}
String typeSegment = JaxRsUtils.getJaxRsPathValue(type);
if (typeSegment == null) {
typeSegment = type.getName();
}
String pathSegment = JaxRsUtils.getJaxRsPathValue(type);
String typeSegment = type.getName();

List<JaxRsMethodInfo> methodInfos = new ArrayList<>();
for (PsiMethod method : type.getMethods()) {
Expand All @@ -80,10 +78,14 @@ public List<JaxRsMethodInfo> getJaxRsMethodInfo(PsiFile typeRoot, JaxRsContext j
if (methodSegment == null) {
methodSegment = method.getName();
}
String url = methodSegment.startsWith("/") ? methodSegment
: JaxRsUtils.buildURL(typeSegment, methodSegment);
url = JaxRsUtils.buildURL(jaxrsContext.getLocalBaseURL(), url);

String path;
if (pathSegment == null) {
path = methodSegment.startsWith("/") ? methodSegment : JaxRsUtils.buildURL(typeSegment, methodSegment);
} else {
path = JaxRsUtils.buildURL(pathSegment, methodSegment);
}
String url = JaxRsUtils.buildURL(jaxrsContext.getLocalBaseURL(), path);

JaxRsMethodInfo methodInfo = createMethodInfo(method, url);
if (methodInfo != null) {
methodInfos.add(methodInfo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,23 @@ public void testCodeLens() throws Exception {
cl("http://localhost:8080/Application/endpoint", "", r(34, 4, 4)));
}

@Test
public void testAbsolutePathCodeLens() throws Exception {
Module javaProject = loadMavenProject(QuarkusMavenProjectName.quarkus_renarde_todo);

assertNotNull(javaProject);

MicroProfileJavaCodeLensParams params = new MicroProfileJavaCodeLensParams();
params.setCheckServerAvailable(false);
String javaFileUri = getFileUri("src/main/java/rest/Game.java", javaProject);
params.setUri(javaFileUri);
params.setUrlCodeLensEnabled(true);

assertCodeLens(params, PsiUtilsLSImpl.getInstance(myProject), //
cl("http://localhost:8080/play/id", "", r(9, 4, 4)),
cl("http://localhost:8080/play/start", "", r(13, 4, 4)));
}

/*@Test
public void workspaceSymbols() throws Exception {
IJavaProject javaProject = loadMavenProject(quarkus_renarde_todo);
Expand All @@ -71,7 +88,9 @@ public void workspaceSymbols() throws Exception {
si("@/Todos/delete: POST", r(35, 16, 22)), //
si("@/Todos/done: POST", r(46, 16, 20)), //
si("@/Todos/index: GET", r(29, 28, 33)), //
si("@/about: GET", r(25, 28, 33)));
si("@/about: GET", r(25, 28, 33)), //
si("@/play/id: GET", r(9, 18, 26)), //
si("@/play/start: GET", r(13, 18, 23)));
}*/

}

0 comments on commit 7da1e83

Please sign in to comment.