You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by th...@apache.org on 2021/10/23 13:58:19 UTC

[tapestry-5] branch rest updated: TAP5-2696: adding @ActivactionContextParameter

This is an automated email from the ASF dual-hosted git repository.

thiagohp pushed a commit to branch rest
in repository https://gitbox.apache.org/repos/asf/tapestry-5.git


The following commit(s) were added to refs/heads/rest by this push:
     new 21f10d2  TAP5-2696: adding @ActivactionContextParameter
21f10d2 is described below

commit 21f10d2896ca65a75afbfd997225b0e5436f5b6b
Author: Thiago H. de Paula Figueiredo <th...@arsmachina.com.br>
AuthorDate: Sat Oct 23 10:57:59 2021 -0300

    TAP5-2696: adding @ActivactionContextParameter
---
 .../annotations/ActivationContextParameter.java    | 46 ++++++++++++++++++++++
 .../DefaultOpenApiDescriptionGenerator.java        |  8 +++-
 tapestry-core/src/test/app1/WEB-INF/app.properties | 10 ++---
 .../integration/app1/base/BaseRestDemoPage.java    |  3 +-
 4 files changed, 58 insertions(+), 9 deletions(-)

diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/annotations/ActivationContextParameter.java b/tapestry-core/src/main/java/org/apache/tapestry5/annotations/ActivationContextParameter.java
new file mode 100644
index 0000000..be7a109
--- /dev/null
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/annotations/ActivationContextParameter.java
@@ -0,0 +1,46 @@
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry5.annotations;
+
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import static org.apache.tapestry5.ioc.annotations.AnnotationUseContext.PAGE;
+import static org.apache.tapestry5.ioc.annotations.AnnotationUseContext.COMPONENT;
+import static org.apache.tapestry5.ioc.annotations.AnnotationUseContext.MIXIN;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import org.apache.tapestry5.ioc.annotations.UseWith;
+
+/**
+ * Annotation that may be placed on parameters of event handler methods to define their names
+ * in OpenAPI description. This is <em>not</em> needed for an event handler parameter to be
+ * a parameter in a REST endpoint event handler method.
+ *  
+ * @since 5.8.0
+ */
+@Target(
+{ PARAMETER })
+@Retention(RUNTIME)
+@Documented
+@UseWith(
+{ PAGE, COMPONENT, MIXIN })
+public @interface ActivationContextParameter
+{
+    /** 
+     * The name to be used for this parameter in the OpenAPI description.
+     */
+    String value();
+}
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/DefaultOpenApiDescriptionGenerator.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/DefaultOpenApiDescriptionGenerator.java
index 653bed5..f32c17f 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/DefaultOpenApiDescriptionGenerator.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/DefaultOpenApiDescriptionGenerator.java
@@ -27,6 +27,7 @@ import java.util.stream.Collectors;
 import javax.servlet.http.HttpServletResponse;
 
 import org.apache.tapestry5.SymbolConstants;
+import org.apache.tapestry5.annotations.ActivationContextParameter;
 import org.apache.tapestry5.annotations.OnEvent;
 import org.apache.tapestry5.annotations.RequestParameter;
 import org.apache.tapestry5.annotations.StaticActivationContextValue;
@@ -306,6 +307,11 @@ public class DefaultOpenApiDescriptionGenerator implements OpenApiDescriptionGen
         {
             name = requestParameter.value();
         }
+        ActivationContextParameter activationContextParameter = parameter.getAnnotation(ActivationContextParameter.class);
+        if (activationContextParameter != null && !CommonsUtils.isBlank(activationContextParameter.value()))
+        {
+            name = activationContextParameter.value();
+        }
         if (CommonsUtils.isBlank(name))
         {
             name = parameter.getName();
@@ -372,7 +378,7 @@ public class DefaultOpenApiDescriptionGenerator implements OpenApiDescriptionGen
 
     public Optional<String> getValue(Method method, String path, String httpMethod, Parameter parameter, String property) 
     {
-        return getValue(method, path, httpMethod, "parameter." + parameter.getName(), property);
+        return getValue(method, path, httpMethod, "parameter." + getParameterName(parameter), property);
     }
     
     public Optional<String> getValue(Method method, String path, String httpMethod, int statusCode) 
diff --git a/tapestry-core/src/test/app1/WEB-INF/app.properties b/tapestry-core/src/test/app1/WEB-INF/app.properties
index 26e9036..52ede78 100644
--- a/tapestry-core/src/test/app1/WEB-INF/app.properties
+++ b/tapestry-core/src/test/app1/WEB-INF/app.properties
@@ -36,13 +36,9 @@ openapi.put.response.200 = Generic 200
 openapi.response.200 = Generic 200
 openapi.response.201 = PUT request succesful
 
-#openapi./restwitheventhandlermethodnamedemo/parametersTest/{arg2}.get.parameter.arg2.name=path-parameter-specific
-#openapi.get.parameter.arg2.name=path-parameter-get-specific
-openapi.parameter.arg2.name = path-parameter-general
-
-#openapi./restwitheventhandlermethodnamedemo/parametersTest/{arg2}.get.parameter.arg2.description=Specific arg2 description
-#openapi.get.parameter.arg2.description=GET-specific arg2 description
-openapi.parameter.arg2.description = Generic arg2 description
+openapi./restwitheventhandlermethodnamedemo/parametersTest/pathParameter.get.parameter.pathParameter.description=Specific pathParameter description
+openapi.get.parameter.pathParameter.description=GET-specific arg2 description
+openapi.parameter.pathParameter.description = Generic pathParameter description
 
 
 openapi.org.apache.tapestry5.integration.app1.pages.RestRequestNotHandledDemo.tag.name=fcqnTag
diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/base/BaseRestDemoPage.java b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/base/BaseRestDemoPage.java
index 69d6294..6838c53 100644
--- a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/base/BaseRestDemoPage.java
+++ b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/base/BaseRestDemoPage.java
@@ -12,6 +12,7 @@
 package org.apache.tapestry5.integration.app1.base;
 
 import org.apache.tapestry5.EventConstants;
+import org.apache.tapestry5.annotations.ActivationContextParameter;
 import org.apache.tapestry5.annotations.OnEvent;
 import org.apache.tapestry5.annotations.RequestParameter;
 import org.apache.tapestry5.annotations.StaticActivationContextValue;
@@ -52,7 +53,7 @@ public class BaseRestDemoPage extends AbstractRestDemoPage {
     public Object withParameters(
             @StaticActivationContextValue("parametersTest") String staticParameter,
             @RequestParameter(value = "fromQueryString", allowBlank = true) String queryParameter,
-            String pathParameter)
+            @ActivationContextParameter("pathParameter") String pathParameter)
     {
         return new JSONObject("staticParameter", staticParameter, 
                 "pathParameter", pathParameter,