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

jamesbognar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/juneau.git


The following commit(s) were added to refs/heads/master by this push:
     new 9911d60  JUNEAU-147 Error in Swagger generator when @Example used on 
bean class.
9911d60 is described below

commit 9911d60e79db308e5aa850f8e09e1a440f0fb516
Author: JamesBognar <[email protected]>
AuthorDate: Sun Sep 8 20:09:52 2019 -0400

    JUNEAU-147 Error in Swagger generator when @Example used on bean class.
---
 .../src/main/java/org/apache/juneau/ClassMeta.java | 16 +++--
 .../juneau/httppart/bean/ResponseBeanMeta.java     |  2 +-
 .../java/org/apache/juneau/reflect/ClassInfo.java  |  2 +-
 .../org/apache/juneau/reflect/ExecutableInfo.java  | 11 ++--
 .../java/org/apache/juneau/reflect/MethodInfo.java | 16 ++++-
 .../juneau/petstore/rest/PetStoreResource.java     | 52 ---------------
 .../juneau/petstore/rest/PetStoreResource.json     | 75 ----------------------
 .../src/main/resources/META-INF/persistence.xml    |  6 +-
 .../rest/client/remote/RemoteMethodMeta.java       |  4 ++
 .../rest/client/remote/RemoteMethodReturn.java     |  4 ++
 .../org/apache/juneau/rest/SwaggerGenerator.java   |  8 ++-
 11 files changed, 46 insertions(+), 150 deletions(-)

diff --git 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ClassMeta.java 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ClassMeta.java
index c242b78..741f19d 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ClassMeta.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ClassMeta.java
@@ -450,13 +450,13 @@ public final class ClassMeta<T> implements Type {
                        for (FieldInfo f : ci.getAllFieldsParentFirst()) {
                                if (f.hasAnnotation(ParentProperty.class)) {
                                        if (f.isStatic())
-                                               throw new 
ClassMetaRuntimeException("@ParentProperty used on invalid field ''{0}''.  Must 
be static.", f);
+                                               throw new 
ClassMetaRuntimeException(c, "@ParentProperty used on invalid field ''{0}''.  
Must be static.", f);
                                        f.setAccessible();
                                        parentPropertyMethod = new 
Setter.FieldSetter(f.inner());
                                }
                                if (f.hasAnnotation(NameProperty.class)) {
                                        if (f.isStatic())
-                                               throw new 
ClassMetaRuntimeException("@NameProperty used on invalid field ''{0}''.  Must 
be static.", f);
+                                               throw new 
ClassMetaRuntimeException(c, "@NameProperty used on invalid field ''{0}''.  
Must be static.", f);
                                        f.setAccessible();
                                        namePropertyMethod = new 
Setter.FieldSetter(f.inner());
                                }
@@ -465,7 +465,7 @@ public final class ClassMeta<T> implements Type {
                        for (FieldInfo f : ci.getDeclaredFields()) {
                                if (f.hasAnnotation(Example.class)) {
                                        if (! (f.isStatic() && 
ci.isParentOf(f.getType().inner())))
-                                               throw new 
ClassMetaRuntimeException("@Example used on invalid field ''{0}''.  Must be 
static and an instance of the type.", f);
+                                               throw new 
ClassMetaRuntimeException(c, "@Example used on invalid field ''{0}''.  Must be 
static and an instance of the type.", f);
                                        f.setAccessible();
                                        exampleField = f.inner();
                                }
@@ -475,22 +475,24 @@ public final class ClassMeta<T> implements Type {
                        for (MethodInfo m : ci.getAllMethodsParentFirst()) {
                                if (m.hasAnnotation(ParentProperty.class)) {
                                        if (m.isStatic() || ! m.hasNumParams(1))
-                                               throw new 
ClassMetaRuntimeException("@ParentProperty used on invalid method ''{0}''.  
Must not be static and have one argument.", m);
+                                               throw new 
ClassMetaRuntimeException(c, "@ParentProperty used on invalid method ''{0}''.  
Must not be static and have one argument.", m);
                                        m.setAccessible();
                                        parentPropertyMethod = new 
Setter.MethodSetter(m.inner());
                                }
                                if (m.hasAnnotation(NameProperty.class)) {
                                        if (m.isStatic() || ! m.hasNumParams(1))
-                                               throw new 
ClassMetaRuntimeException("@NameProperty used on invalid method ''{0}''.  Must 
not be static and have one argument.", m);
+                                               throw new 
ClassMetaRuntimeException(c, "@NameProperty used on invalid method ''{0}''.  
Must not be static and have one argument.", m);
                                        m.setAccessible();
                                        namePropertyMethod = new 
Setter.MethodSetter(m.inner());
                                }
                        }
 
                        for (MethodInfo m : ci.getDeclaredMethods()) {
+                               if (ci.getSimpleName().equals("Order"))
+                                       System.err.println();
                                if (m.hasAnnotation(Example.class)) {
                                        if (! (m.isStatic() && 
m.hasFuzzyParamTypes(BeanSession.class) && 
ci.isParentOf(m.getReturnType().inner())))
-                                               throw new 
ClassMetaRuntimeException("@Example used on invalid method ''{0}''.  Must be 
static and return an instance of the declaring class.", m);
+                                               throw new 
ClassMetaRuntimeException(c, "@Example used on invalid method ''{0}''.  Must be 
static and return an instance of the declaring class.", m);
                                        m.setAccessible();
                                        exampleMethod = m.inner();
                                }
@@ -721,7 +723,7 @@ public final class ClassMeta<T> implements Type {
                                        return 
(PojoSwap<T,?>)l.iterator().next();
                        }
 
-                       throw new ClassMetaRuntimeException("Invalid swap class 
''{0}'' specified.  Must extend from PojoSwap or Surrogate.", c);
+                       throw new ClassMetaRuntimeException(c, "Invalid swap 
class ''{0}'' specified.  Must extend from PojoSwap or Surrogate.", c);
                }
 
                private ClassMeta<?> findClassMeta(Class<?> c) {
diff --git 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/httppart/bean/ResponseBeanMeta.java
 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/httppart/bean/ResponseBeanMeta.java
index 7291ec2..3f0ba6e 100644
--- 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/httppart/bean/ResponseBeanMeta.java
+++ 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/httppart/bean/ResponseBeanMeta.java
@@ -67,7 +67,7 @@ public class ResponseBeanMeta {
         * @return Metadata about the class, or <jk>null</jk> if class not 
annotated with {@link Response}.
         */
        public static ResponseBeanMeta create(MethodInfo m, PropertyStore ps) {
-               if (! m.hasAnnotation(Response.class))
+               if (! (m.hasAnnotation(Response.class) || 
m.getResolvedReturnType().hasAnnotation(Response.class)))
                        return null;
                Builder b = new Builder(ps);
                b.apply(m.getReturnType().resolved().innerType());
diff --git 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ClassInfo.java
 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ClassInfo.java
index 1cc10b9..7aeb365 100644
--- 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ClassInfo.java
+++ 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ClassInfo.java
@@ -1241,7 +1241,7 @@ public final class ClassInfo {
                return m;
        }
 
-       private <T extends Annotation> T findAnnotation(Class<T> a) {
+       <T extends Annotation> T findAnnotation(Class<T> a) {
                T t2 = getDeclaredAnnotation(a);
                if (t2 != null)
                        return t2;
diff --git 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ExecutableInfo.java
 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ExecutableInfo.java
index f07c120..08313e4 100644
--- 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ExecutableInfo.java
+++ 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ExecutableInfo.java
@@ -304,10 +304,10 @@ public abstract class ExecutableInfo {
        }
 
        /**
-        * Returns <jk>true</jk> if the specified annotation is present on this 
constructor.
+        * Returns <jk>true</jk> if the specified annotation is present on this 
method.
         *
         * @param a The annotation to check for.
-        * @return <jk>true</jk> if the specified annotation is present on this 
constructor.
+        * @return <jk>true</jk> if the specified annotation is present on this 
method.
         */
        public final boolean hasAnnotation(Class<? extends Annotation> a) {
                return getAnnotation(a) != null;
@@ -321,9 +321,6 @@ public abstract class ExecutableInfo {
         * signature on the parent classes or interfaces.
         * <br>The search is performed in child-to-parent order.
         *
-        * <p>
-        * If still not found, searches for the annotation on the return type 
of the method.
-        *
         * @param a
         *      The annotation to search for.
         * @return
@@ -342,9 +339,9 @@ public abstract class ExecutableInfo {
        }
 
        /**
-        * Searched for the specified annotation.
+        * Searched for the specified annotation on the method.
         *
-        * @param a The annotation to search for.
+        * @param a The annotation to search for on the method.
         * @return The annotation if found.
         */
        protected <T extends Annotation> T findAnnotation(Class<T> a) {
diff --git 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/MethodInfo.java
 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/MethodInfo.java
index b7b910e..0cac994 100644
--- 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/MethodInfo.java
+++ 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/MethodInfo.java
@@ -311,7 +311,7 @@ public final class MethodInfo extends ExecutableInfo 
implements Comparable<Metho
                        for (Annotation a2 :  m2.getAnnotations())
                                if (a.isInstance(a2))
                                        return (T)a2;
-               return getReturnType().resolved().getAnnotation(a);
+               return null;
        }
 
        AnnotationList appendAnnotationList(AnnotationList al) {
@@ -386,6 +386,20 @@ public final class MethodInfo extends ExecutableInfo 
implements Comparable<Metho
        }
 
        /**
+        * Returns the generic return type of this method as a {@link 
ClassInfo} object.
+        * 
+        * <p>
+        * Unwraps the type if it's a {@link Value}.
+        *
+        * @return The generic return type of this method.
+        */
+       public ClassInfo getResolvedReturnType() {
+               if (returnType == null)
+                       returnType = ClassInfo.of(m.getReturnType(), 
m.getGenericReturnType());
+               return returnType.resolved();
+       }
+
+       /**
         * Returns <jk>true</jk> if this method has this return type.
         *
         * @param c The return type to test for.
diff --git 
a/juneau-examples/juneau-examples-petstore/juneau-examples-petstore-server/src/main/java/org/apache/juneau/petstore/rest/PetStoreResource.java
 
b/juneau-examples/juneau-examples-petstore/juneau-examples-petstore-server/src/main/java/org/apache/juneau/petstore/rest/PetStoreResource.java
index 05a08e3..66c42b5 100644
--- 
a/juneau-examples/juneau-examples-petstore/juneau-examples-petstore-server/src/main/java/org/apache/juneau/petstore/rest/PetStoreResource.java
+++ 
b/juneau-examples/juneau-examples-petstore/juneau-examples-petstore-server/src/main/java/org/apache/juneau/petstore/rest/PetStoreResource.java
@@ -12,7 +12,6 @@
 // 
***************************************************************************************************************************
 package org.apache.juneau.petstore.rest;
 
-import static org.apache.juneau.dto.html5.HtmlBuilder.*;
 import static org.apache.juneau.dto.swagger.ui.SwaggerUI.*;
 import static org.apache.juneau.http.HttpMethodName.*;
 import static org.apache.juneau.http.response.Ok.*;
@@ -28,7 +27,6 @@ import org.apache.juneau.petstore.dto.*;
 import org.apache.juneau.petstore.service.*;
 import org.apache.juneau.*;
 import org.apache.juneau.annotation.*;
-import org.apache.juneau.dto.html5.*;
 import org.apache.juneau.html.annotation.*;
 import org.apache.juneau.http.annotation.*;
 import org.apache.juneau.rest.*;
@@ -167,56 +165,6 @@ public class PetStoreResource extends BasicRest implements 
PetStore {
        }
 
        
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-       // Initialization
-       
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-
-       /**
-        * Initialize database form entry page.
-        *
-        * @return Initialize database form entry page contents.
-        */
-       @RestMethod(
-               summary="Initialize database form entry page"
-       )
-       public Div getInit() {
-               return div(
-                       
form("servlet:/init").method(POST).target("buf").children(
-                               table(
-                                       tr(
-                                               th("Initialize petstore 
database:"),
-                                               
td(input("radio").name("init-method").value("direct").checked(true), "direct", 
input("radio").name("init-method").value("rest"), "rest"),
-                                               td(button("submit", 
"Submit").style("float:right").onclick("scrolling=true"))
-                                       )
-                               )
-                       ),
-                       br(),
-                       
iframe().id("buf").name("buf").style("width:800px;height:600px;").onload("window.parent.scrolling=false;"),
-                       script("text/javascript",
-                               "var scrolling = false;",
-                               "function scroll() { if (scrolling) { 
document.getElementById('buf').contentWindow.scrollBy(0,50); } 
setTimeout('scroll()',200); } ",
-                               "scroll();"
-                       )
-               );
-       }
-
-       /**
-        * Initialize database.
-        *
-        * @param initMethod The method used to initialize the database.
-        * @param res HTTP request.
-        * @throws Exception Error occurred.
-        */
-       @RestMethod(
-               summary="Initialize database"
-       )
-       public void postInit(
-               RestResponse res
-       ) throws Exception {
-               res.setHeader("Content-Encoding", "identity");
-               store.initDirect(res.getDirectWriter("text/plain"));
-       }
-
-       
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
        // Pets
        
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 
diff --git 
a/juneau-examples/juneau-examples-petstore/juneau-examples-petstore-server/src/main/java/org/apache/juneau/petstore/rest/PetStoreResource.json
 
b/juneau-examples/juneau-examples-petstore/juneau-examples-petstore-server/src/main/java/org/apache/juneau/petstore/rest/PetStoreResource.json
deleted file mode 100644
index 780c654..0000000
--- 
a/juneau-examples/juneau-examples-petstore/juneau-examples-petstore-server/src/main/java/org/apache/juneau/petstore/rest/PetStoreResource.json
+++ /dev/null
@@ -1,75 +0,0 @@
-// 
***************************************************************************************************************************
-// * Licensed to the Apache Software Foundation (ASF) under one or more 
contributor license agreements.  See the NOTICE file *
-// * distributed with this work for additional information regarding copyright 
ownership.  The ASF licenses this file        *
-// * to you 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.                                              *
-// 
***************************************************************************************************************************
-
-{
-       "swagger": "2.0",
-       "info": {
-               "version": "1.0.0",
-               "title": "Swagger Petstore",
-               "termsOfService": "You are on your own.",
-               "contact": {
-                       "name": "Juneau Development Team",
-                       "email": "[email protected]",
-                       "url": "http://juneau.apache.org";
-               },
-               "license": {
-                       "name": "Apache 2.0",
-                       "url": "http://www.apache.org/licenses/LICENSE-2.0.html";
-               }
-       },
-       "externalDocs": {
-               "description": "Find out more about Juneau",
-               "url": "http://juneau.apache.org";
-       },
-       "tags": [
-               {
-                       "name": "pet",
-                       "description": "Everything about your Pets",
-                       "externalDocs": {
-                               "description": "Find out more",
-                               "url": "http://juneau.apache.org";
-                       }
-               },
-               {
-                       "name": "store",
-                       "description": "Access to Petstore orders"
-               },
-               {
-                       "name": "user",
-                       "description": "Operations about user",
-                       "externalDocs": {
-                               "description": "Find out more about our store",
-                               "url": "http://juneau.apache.org";
-                       }
-               }
-       ],
-       "schemes": [
-               "http"
-       ],
-       "securityDefinitions": {
-               "petstore_auth": {
-                       "type": "oauth2",
-                       "authorizationUrl": 
"http://petstore.swagger.io/oauth/dialog";,
-                       "flow": "implicit",
-                       "scopes": {
-                               "write:pets": "modify pets in your account",
-                               "read:pets": "read your pets"
-                       }
-               },
-               "api_key": {
-                       "type": "apiKey",
-                       "name": "api_key",
-                       "in": "header"
-               }
-       }
-}
\ No newline at end of file
diff --git 
a/juneau-examples/juneau-examples-petstore/juneau-examples-petstore-server/src/main/resources/META-INF/persistence.xml
 
b/juneau-examples/juneau-examples-petstore/juneau-examples-petstore-server/src/main/resources/META-INF/persistence.xml
index 7c0bc2c..8db6a41 100644
--- 
a/juneau-examples/juneau-examples-petstore/juneau-examples-petstore-server/src/main/resources/META-INF/persistence.xml
+++ 
b/juneau-examples/juneau-examples-petstore/juneau-examples-petstore-server/src/main/resources/META-INF/persistence.xml
@@ -17,9 +17,9 @@
        xsi:schemaLocation="http://java.sun.com/xml/ns/persistence 
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd";
        version="2.0" xmlns="http://java.sun.com/xml/ns/persistence";>
        <persistence-unit name="test" transaction-type="RESOURCE_LOCAL">
-               <class>org.apache.juneau.examples.petstore.dto.Pet</class>
-               <class>org.apache.juneau.examples.petstore.dto.Order</class>
-               <class>org.apache.juneau.examples.petstore.dto.User</class>
+               <class>org.apache.juneau.petstore.dto.Pet</class>
+               <class>org.apache.juneau.petstore.dto.Order</class>
+               <class>org.apache.juneau.petstore.dto.User</class>
                <properties>
                        <property name="javax.persistence.jdbc.driver" 
value="org.apache.derby.jdbc.EmbeddedDriver" />
                        <property name="javax.persistence.jdbc.url" 
value="jdbc:derby:target/derby/testDB;create=true" />
diff --git 
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/remote/RemoteMethodMeta.java
 
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/remote/RemoteMethodMeta.java
index c3e5cf4..667655c 100644
--- 
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/remote/RemoteMethodMeta.java
+++ 
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/remote/RemoteMethodMeta.java
@@ -91,7 +91,11 @@ public class RemoteMethodMeta {
                        MethodInfo mi = MethodInfo.of(m);
 
                        org.apache.juneau.rest.client.remote.RemoteMethod orm = 
mi.getAnnotation(org.apache.juneau.rest.client.remote.RemoteMethod.class);
+                       if (orm == null)
+                               orm = 
mi.getResolvedReturnType().getAnnotation(org.apache.juneau.rest.client.remote.RemoteMethod.class);
                        RemoteMethod rm = mi.getAnnotation(RemoteMethod.class);
+                       if (rm == null)
+                               rm = 
mi.getResolvedReturnType().getAnnotation(RemoteMethod.class);
 
                        httpMethod = rm == null ? (orm == null ? "" : 
orm.method()) : rm.method();
                        path = rm == null ? (orm == null ? "" : orm.path()) : 
rm.path();
diff --git 
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/remote/RemoteMethodReturn.java
 
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/remote/RemoteMethodReturn.java
index b474384..650c3f1 100644
--- 
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/remote/RemoteMethodReturn.java
+++ 
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/remote/RemoteMethodReturn.java
@@ -39,7 +39,11 @@ public final class RemoteMethodReturn {
                ClassInfo rt = m.getReturnType();
 
                org.apache.juneau.rest.client.remote.RemoteMethod orm = 
m.getAnnotation(org.apache.juneau.rest.client.remote.RemoteMethod.class);
+               if (orm == null)
+                       orm = 
m.getResolvedReturnType().getAnnotation(org.apache.juneau.rest.client.remote.RemoteMethod.class);
                RemoteMethod rm = m.getAnnotation(RemoteMethod.class);
+               if (rm == null)
+                       rm = 
m.getResolvedReturnType().getAnnotation(RemoteMethod.class);
 
                RemoteReturn rv = null;
                if (rt.is(void.class))
diff --git 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/SwaggerGenerator.java
 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/SwaggerGenerator.java
index dcb945a..ca67de5 100644
--- 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/SwaggerGenerator.java
+++ 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/SwaggerGenerator.java
@@ -389,8 +389,10 @@ final class SwaggerGenerator {
                                                }
                                        }
                                        for (MethodInfo ecmi : 
eci.getAllMethodsParentFirst()) {
-                                               if 
(ecmi.hasAnnotation(ResponseHeader.class)) {
-                                                       ResponseHeader a = 
ecmi.getAnnotation(ResponseHeader.class);
+                                               ResponseHeader a = 
ecmi.getAnnotation(ResponseHeader.class);
+                                               if (a == null)
+                                                       a = 
ecmi.getResolvedReturnType().getAnnotation(ResponseHeader.class);
+                                               if (a != null) {
                                                        String ha = a.name();
                                                        for (Integer code : 
codes) {
                                                                ObjectMap 
header = responses.getObjectMap(String.valueOf(code), 
true).getObjectMap("headers", true).getObjectMap(ha, true);
@@ -402,7 +404,7 @@ final class SwaggerGenerator {
                                }
                        }
 
-                       if (mi.hasAnnotation(Response.class)) {
+                       if (mi.hasAnnotation(Response.class) || 
mi.getResolvedReturnType().hasAnnotation(Response.class)) {
                                List<Response> la = 
mi.getAnnotationsParentFirst(Response.class);
                                Set<Integer> codes = getCodes(la, 200);
                                for (Response a : la) {

Reply via email to