Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for uri/uriabs from Quarkus Renarde #586

Merged
merged 1 commit into from
Jan 31, 2023

Conversation

angelozerr
Copy link
Contributor

@angelozerr angelozerr commented Mar 8, 2022

Support for uri/uriabs from Quarkus Renarde

Fixes #571

This PR uses those renarde validation rules:

  • all parameters which are annotated with @RestPath (or @PathParam) are considered as required
  • all parameters which are annotated with @restquery (or @QueryParam) are optional
  • all parameters which are annotated with @restform (or @FormParam) cannot appear in the method of uri.

Signed-off-by: azerr azerr@redhat.com

@angelozerr
Copy link
Contributor Author

Here a little demo with renarde uri:

RenardeDemo

//c @FroMage

@FroMage
Copy link

FroMage commented Mar 8, 2022

Wow, super nice!

@angelozerr angelozerr force-pushed the uri-renarde branch 2 times, most recently from c9bd18b to ac04ded Compare March 8, 2022 16:15
@angelozerr
Copy link
Contributor Author

angelozerr commented Mar 8, 2022

There are 2 problems with diagnostics in quarkus-renarde-todo in Login.html:

  • Problem 1:

image

It's because we check that allowed method doesn't return void according to this rule https://github.com/quarkusio/quarkus/blob/ce19ff75e9f732ff731bb30c2141b44b42c66050/independent-projects/qute/core/src/main/java/io/quarkus/qute/ReflectionValueResolver.java#L176

@mkouba why ReflectionValueResolver forbids the void although renarde value resolver doesn't forbid it? If we want to keep this behavior,it means that we must provide custom validation for renarde.

  • Problem 2:

image

It's because manualLogin expect 2 parameters:

    @POST
    public Response manualLogin(@NotBlank @RestForm String userName, 
            @NotBlank @RestForm String password) {

It seems that userName and password comes from #formElement

image

How to manage this rule with generic mean?

@FroMage @mkouba have you some idea?

@FroMage
Copy link

FroMage commented Mar 8, 2022

@mkouba why ReflectionValueResolver forbids the void although renarde value resolver doesn't forbid it? If we want to keep this behavior,it means that we must provide custom validation for renarde.

Actually this doesn't go through ReflectionValueResolver, because custom namespaces can do whatever they want.

How to manage this rule with generic mean?

Well, this is because the method only requires parameters that end up in the URI, such as @PathParam, but all the others can be ignored when calling uri (those that are context, or headers, cookies, or form params in this case).

So yeah, namespace resolvers are really like primitives and must be hard-coded: you can't guess what they do.

@mkouba
Copy link
Collaborator

mkouba commented Mar 8, 2022

@mkouba why ReflectionValueResolver forbids the void although renarde value resolver doesn't forbid it? If we want to keep this behavior,it means that we must provide custom validation for renarde.

Actually this doesn't go through ReflectionValueResolver, because custom namespaces can do whatever they want.

Stef is correct that we only validate output expressions where a namespace is mapped to a @TemplateExtension method or @TemplateData with a namespace. Otherwise there is no type info available. In this case, I assume that uri:RenardeSecurityController.loginUsingOidc does not invoke the controller method at all.

@FroMage
Copy link

FroMage commented Mar 8, 2022

Indeed. It's only used to invoke the reverse-router.

@angelozerr
Copy link
Contributor Author

Thanks @FroMage @mkouba for our feedback.

It wil require to support custom validation for a given namespace.

I will do that in an another issues. For the moment we will have those errors.

@mkouba
Copy link
Collaborator

mkouba commented Mar 9, 2022

It wil require to support custom validation for a given namespace.

In general, an output expression that starts with a namespace should only be validated (java model) if the namespace is inject, cdi or corresponds to a @TemplateEnum, @TemplateData#namespace() and a namespace extension method. All other namespaces should be ignored.

@angelozerr angelozerr force-pushed the uri-renarde branch 2 times, most recently from 7511b79 to 6076d7f Compare March 9, 2022 08:28
@angelozerr angelozerr marked this pull request as ready for review March 9, 2022 08:28
@angelozerr
Copy link
Contributor Author

All other namespaces should be ignored.

I understand the idea, but my idea is to provide the capability to provide custom validation like renarde validation.

@fbricon
Copy link
Collaborator

fbricon commented Mar 9, 2022

So if I'm using the uri: or uriabs: namespace on a non-renarde project (renarde jars not on the project's classpath), the tool behaves as if the resolver was known and available, as opposed to actually complaining about an unknown namespace.

Screenshot 2022-03-09 at 12 14 21

@angelozerr
Copy link
Contributor Author

So if I'm using the uri: or uriabs: namespace on a non-renarde project (renarde jars not on the project's classpath), the tool behaves as if the resolver was known and available, as opposed to actually complaining about an unknown namespace.

Good catch! It should be fixed now.

@fbricon
Copy link
Collaborator

fbricon commented Mar 9, 2022

try {
// Find all classes which extends 'io.quarkiverse.renarde.Controller'
ITypeHierarchy typeHierarchy = type.newTypeHierarchy(monitor);
IType[] controllerTypes = typeHierarchy.getAllClasses();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rgrunber here I need to collect all classes which extends "io.quarkiverse.renarde.Controller" class. I have a usecase with :

  • Application which extends Controller
  • Todos which extends ControllerWithUser which extends Controller.

When Controller and ControllerWithUser comes from sources (I copied/pasted thoses sources in my project), I can get Application and Todos.

But when Controller and ControllerWithUser comes from JAR,it seems (according the problem with @fbricon with Todos), that it get only Application (notTodos which extends ControllerWithUser which extends Controller).

At first do you think my code is correct? Have you some idea about this problem?

Copy link
Member

@rgrunber rgrunber Mar 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it the same result if you try using IType[] getAllSubtypes(IType type); from ITypeHierarchy ?

Copy link
Member

@rgrunber rgrunber Mar 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first thing I notice from running the test case is that

/qute-renarde/lib/quarkus-renarde-1.0.0-SNAPSHOT.jar[CPE_LIBRARY][K_BINARY][isExported:false][attributes:module=true]
/qute-renarde/lib/quarkus-renarde-oidc-1.0.0-SNAPSHOT.jar[CPE_LIBRARY][K_BINARY][isExported:false][attributes:module=true]

don't exist. They're defined in the .classpath so they show, but there's no lib folder in the qute-renard project so no way to even get the type. I assume you may have them locally so I think they probably need to be added to the commit.

Update : In fact, If I run javaProject.getResource().findMarkers(null, true, org.eclipse.core.resources.IResource.DEPTH_INFINITE), I get :

Marker [on: /qute-renarde, id: 5, type: org.eclipse.jdt.core.buildpath_problem, attributes: [arguments: 0:, categoryId: 10, classpathFileFormat: false, cycleDetected: false, id: 964, location: Build path, message: Project 'qute-renarde' is missing required library: 'lib/quarkus-renarde-oidc-1.0.0-SNAPSHOT.jar', outputOverlappingSource: false, severity: 2, sourceId: JDT], created: 3/10/22, 4:15 PM]
Marker [on: /qute-renarde, id: 4, type: org.eclipse.jdt.core.buildpath_problem, attributes: [arguments: 0:, categoryId: 10, classpathFileFormat: false, cycleDetected: false, id: 964, location: Build path, message: Project 'qute-renarde' is missing required library: 'lib/quarkus-renarde-1.0.0-SNAPSHOT.jar', outputOverlappingSource: false, severity: 2, sourceId: JDT], created: 3/10/22, 4:15 PM]

@angelozerr angelozerr force-pushed the uri-renarde branch 5 times, most recently from 5ffd259 to 5925a6c Compare March 10, 2022 13:01
@angelozerr
Copy link
Contributor Author

Okay. Makes sense. Be sure to leave a comment or open an issue for that.

See #780

@datho7561
Copy link
Contributor

If I have a method, and I "pass" it more parameters than it has, then there is no error. I don't know if this is intentional

@angelozerr do you want to handle this in this PR or should I open an issue for it?

@angelozerr
Copy link
Contributor Author

@angelozerr do you want to handle this in this PR or should I open an issue for it?

I think it is a bug with space. If you write

<a href={uri:Login.foo(null,"1234")}>click me</a>

it should work, no?

I would like to do that in a separate PR since it is not linked to this PR

@angelozerr
Copy link
Contributor Author

@datho7561 I need to write JDT test to collect ResolvedJavaTypeInfo for renarde.

@datho7561
Copy link
Contributor

datho7561 commented Jan 31, 2023

I think it is a bug with space.

You're right, I can confirm it works if I don't add spaces.

The qute-ls server is not shutting down properly, but I think that is also not related to this PR.

@angelozerr angelozerr force-pushed the uri-renarde branch 2 times, most recently from 3dc2cac to 8725b66 Compare January 31, 2023 16:33
@angelozerr
Copy link
Contributor Author

@datho7561 I need to write JDT test to collect ResolvedJavaTypeInfo for renarde.

done quickly

@angelozerr angelozerr force-pushed the uri-renarde branch 3 times, most recently from 09558c9 to 24b7dea Compare January 31, 2023 16:49
@angelozerr
Copy link
Contributor Author

The qute-ls server is not shutting down properly, but I think that is also not related to this PR.

No, but it is not related with new vscode language client?

@angelozerr angelozerr force-pushed the uri-renarde branch 5 times, most recently from c1c3c3c to 6885ba3 Compare January 31, 2023 17:03
@datho7561
Copy link
Contributor

I did some testing, and it looks like you were right: it's related to the new language client.

Fixes redhat-developer#571

This PR uses those renarde validation rules:
 * all parameters which are annotated with @RestPath (or @PathParam) are
considered as required
 * all parameters which are annotated with @restquery (or @QueryParam)
are optional
 * all parameters which are annotated with @restform (or @FormParam)
cannot appear in the method of uri.

Signed-off-by: azerr <azerr@redhat.com>
@angelozerr
Copy link
Contributor Author

I did some testing, and it looks like you were right: it's related to the new language client.

I removed https://github.com/redhat-developer/vscode-quarkus/pull/506/files#diff-c1b7030f8c5f91b6d8690295e037104c11aecfc6d7eb7a9bd531aa0a9c5547fdL40 because I though this language client fix the problem. If you add again shouldLanguageServerExitOnShutdown: true is shutdown working better?

If it works better,it mean that we have the same problem with vscode-microprofile and vscode-xml -(

@angelozerr
Copy link
Contributor Author

@datho7561 tests pass now, if you think it is good, please merge it.

Copy link
Contributor

@datho7561 datho7561 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Thanks, Angelo!

@datho7561 datho7561 merged commit 05e23f9 into redhat-developer:master Jan 31, 2023
@angelozerr
Copy link
Contributor Author

Thanks so much @datho7561 for your great review!

@FroMage to have been patient and give us great feedback. This PR is à good start for supporting renarde but we need to improve again the support.

@FroMage when you will have time please install vscode quarkus prerelease when it will be available. I think tomorrow prerelease should be available.

Please install too vscode microprofile prerelease to avoid having problem with quarkus support

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Support for uri/uriabs from Quarkus Renarde
6 participants