If scanning multiple packages isn’t working for you, you should open a ticket on the project. We may have some basic bugs with servlet implementation as that’s less commonly used.
The scanning should definitely pick up anything that has the @Api annotations on it. The only reason it wouldn’t is if they are not in the package you’ve set to be scanned. Have you had a look at the servlet sample? From: <swagger-swaggersocket@googlegroups.com> on behalf of janet vanderpuye <rhy...@gmail.com> Reply-To: "swagger-swaggersocket@googlegroups.com" <swagger-swaggersocket@googlegroups.com> Date: Friday, 23 December 2016 at 12:25 To: Swagger <swagger-swaggersocket@googlegroups.com> Subject: Re: Cant locate swagger.json on java + embedded jetty + httpservlet + swagger integration Thanks Ron. Last night I double-checked and made sure I had no jersey resources/dependencies in my code. I also looked through the github project link you posted and imitated his dependencies and method calls without using the web.xml ( I really want to avoid web.xml as a number of the existing projects I have run as jars with embedded jetty's and no web.xml). The two things I'm faced with now are: Adding multiple packages(separated by a comma or semi-colon) as a resource through the Servlet.setInitParam() method does not work. Multiple packages delimited by a comma or otherwise result in the default {"swagger":"2.0","info":{"version":"1.0.0","title":""}} response. Secondly, I think I still have an issue in how Swagger scans my project. When I do get the swagger.json to display my annotations, it only captures the information in the @Info annotation on my servlet. Anything withing the @Api, @ApiOperation, @ApiResponses, @ApiModel are effectively ignored. Unless I'm mistaken, all of these are supposed to show up in the swagger.json output right? Or do I have to browse to another path to view those annotations too? I seen some posts use the path http://<host>:<port>/swagger-api/<servlet_name> but that does not work for me Here is what my code for the swagger servlet initialization and configuration looks like now. The custom servlet class I posted above remains largely the same. import org.apache.log4j.Logger; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; import io.swagger.servlet.listing.ApiDeclarationServlet; import io.swagger.servlet.config.DefaultServletConfig; . . . logger.info("Initializing user profile server..."); new UserDao(); Server server = new Server(Integer.parseInt(properties.getProperty(Config.JETTY_SERVICE_PORT))); ServletContextHandler servletContextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS); servletContextHandler.setContextPath("/"); server.setHandler(servletContextHandler); //Custom servlet ServletHolder apiservlet = servletContextHandler.addServlet(ProfileServlet.class, "/user/*"); apiservlet.setInitOrder(3); logger.info("User profile server initialized."); // Swagger servlet reader ServletHolder swaggerServlet = servletContextHandler.addServlet(DefaultServletConfig.class, "/swagger-core"); swaggerServlet.setInitOrder(2); swaggerServlet.setInitParameter("api.version", "1.0.0"); //swaggerServlet.setInitParameter("swagger.resource.package", "com.coreservices.servlets,com.coreservices.datatypes"); NOTE::THIS DOES NOT WORK swaggerServlet.setInitParameter("swagger.resource.package","com.coreservices.servlets"); swaggerServlet.setInitParameter("swagger.api.basepath", "http://localhost:7000"); // Swagger api declaration servletContextHandler.addServlet(ApiDeclarationServlet.class, "/api/*"); return server; } Thanks once again for the help. On Thursday, 22 December 2016 17:57:48 UTC-5, Ron wrote: Huh, I misread it as you using jersey. You need to use a different dependency then and a different set up process. We don’t really have documentation for it, but there’s a sample - https://github.com/swagger-api/swagger-samples/tree/master/java/java-servlet From: <swagger-sw...@googlegroups.com> on behalf of janet vanderpuye <rhy...@gmail.com> Reply-To: "swagger-sw...@googlegroups.com" <swagger-sw...@googlegroups.com> Date: Thursday, 22 December 2016 at 14:39 To: Swagger <swagger-sw...@googlegroups.com> Subject: Re: Cant locate swagger.json on java + embedded jetty + httpservlet + swagger integration Oh ok. Maybe I need to read up a bit on Jax-rs but I believe application was built using only servlets. I had only the Bootstrap class and ProfileServlets class, which were written using HttpServlets. Unless one of the default package imports was built on Jax-rs. Thanks for the tip, I will double check for that. On Thursday, 22 December 2016 17:30:02 UTC-5, Ron wrote: What I’m saying is that you can’t use swagger-core for both jax-rs resources and servlets in a single app. From: <swagger-sw...@googlegroups.com> on behalf of janet vanderpuye <rhy...@gmail.com> Reply-To: "swagger-sw...@googlegroups.com" <swagger-sw...@googlegroups.com> Date: Thursday, 22 December 2016 at 14:26 To: Swagger <swagger-sw...@googlegroups.com> Subject: Re: Cant locate swagger.json on java + embedded jetty + httpservlet + swagger integration Ok thanks. On a quick scan, I used the BeanConfig class under io.swagger.jaxrs.config in the Bootstrap.java servlet. Maybe that is where the conflict arises from. Do you have any suggestions on how to initialize swagger servlet( That is the main purpose of the Bootstrap class). 90% the examples and tutorials I saw used the web.xml option and I was trying to avoid that. On Thursday, 22 December 2016 17:04:52 UTC-5, Ron wrote: The package input should be able to accept comma separated values, so you can try that. You can’t mix servlets and jax-rs resources for scanning as they use different scanners that can’t really co-exist. Do you use both? From: <swagger-sw...@googlegroups.com> on behalf of janet vanderpuye <rhy...@gmail.com> Reply-To: "swagger-sw...@googlegroups.com" <swagger-sw...@googlegroups.com> Date: Thursday, 22 December 2016 at 13:53 To: Swagger <swagger-sw...@googlegroups.com> Subject: Re: Cant locate swagger.json on java + embedded jetty + httpservlet + swagger integration WHOOHOO! We have success! Thank you, guys. You are amazing. I had spent the better part of 16 hours on this before I admitted defeat. That aside, i have a couple of questions Does the beanConfig.setResourcePackage("package name") take in only one package? If so, do I have to move all swagger resources into the package?What happens to my @ApiModel resource object which I have defined in another package? This is essentially a datatype so traditionally it is held in a different package from the servlets. I noticed that the documentation skipped the annotations i had for the HttpServlet.doGet() method. Is this normal? I was expecting it to list all functions and types that i had specified with the @ApiOperation, @ApiResponse, etc annotation. This is my current swagger.json output: { "swagger" : "2.0", "info" : { "description" : "Servlet that handles basic CRUD operations to the user profile data source", "version" : "1.0.2", "title" : "User Profile Servlet", "termsOfService" : "XYZ", "contact" : { "name" : "XYZ", "url" : "XYZ", "email" : "XYZ" }, "license" : { "name" : "XYZ", "url" : "XYZ" } }, "host" : "localhost:7000", "basePath" : "/", "tags" : [ { "name" : "users", "description" : "CRUD operations on user datatype" } ], "schemes" : [ "http", "https" ], "consumes" : [ "application/json" ], "produces" : [ "application/json" ] } Many thanks for the help. On Thursday, 22 December 2016 16:10:02 UTC-5, Ron wrote: Try keeping only beanConfig.setResourcePackage("com.coreservices.servlets"); From: <swagger-sw...@googlegroups.com> on behalf of janet vanderpuye <rhy...@gmail.com> Reply-To: "swagger-sw...@googlegroups.com" <swagger-sw...@googlegroups.com> Date: Thursday, 22 December 2016 at 13:05 To: Swagger <swagger-sw...@googlegroups.com> Subject: Re: Cant locate swagger.json on java + embedded jetty + httpservlet + swagger integration Sorry, corrected package. Same result though beanConfig.setResourcePackage("com.api.resources"); beanConfig.setResourcePackage("io.swagger.jaxrs.json"); beanConfig.setResourcePackage("io.swagger.jaxrs.listing"); beanConfig.setResourcePackage("com.coreservices.servlets"); beanConfig.setResourcePackage("com.coreservices.datatypes"); beanConfig.setScan(true); beanConfig.setPrettyPrint(true); On Thursday, 22 December 2016 16:03:57 UTC-5, janet vanderpuye wrote: Thanks Ron. I tried that and no success. The new code for the bootstrap class was beanConfig.setResourcePackage("com.api.resources"); beanConfig.setResourcePackage("io.swagger.jaxrs.json"); beanConfig.setResourcePackage("io.swagger.jaxrs.listing"); beanConfig.setResourcePackage("com.gh.cive.coreservices.servlets"); beanConfig.setResourcePackage("com.gh.cive.coreservices.datatypes"); beanConfig.setScan(true); beanConfig.setPrettyPrint(true); Looking at the logs, it shows that at least it picked up my servlet package for scanning. Could it be an error in the way I declared the annotations? Log output is: 308 [main] INFO Main - User profile server initialized. Dec 22, 2016 3:57:50 PM com.sun.jersey.api.core.PackagesResourceConfig init INFO: Scanning for root resource and provider classes in the packages: com.api.resources io.swagger.jaxrs.json io.swagger.jaxrs.listing com.coreservices.servlets com.coreservices.datatypes Dec 22, 2016 3:57:50 PM com.sun.jersey.api.core.ScanningResourceConfig logClasses INFO: Root resource classes found: class io.swagger.jaxrs.listing.AcceptHeaderApiListingResource class io.swagger.jaxrs.listing.ApiListingResource Dec 22, 2016 3:57:50 PM com.sun.jersey.api.core.ScanningResourceConfig logClasses INFO: Provider classes found: class io.swagger.jaxrs.listing.SwaggerSerializers Dec 22, 2016 3:57:50 PM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate INFO: Initiating Jersey application, version 'Jersey: 1.19.1 03/11/2016 02:08 PM' 2277 [main] INFO Main - user profile service started On Thursday, 22 December 2016 15:47:24 UTC-5, Ron wrote: Looking back, you have a Bootstrap class with the line beanConfig.setResourcePackage("io.swagger.resources"); Change “io.swagger.resources” to the package(s) of your resources and that should allow it to pick them up and scan them. From: <swagger-sw...@googlegroups.com> on behalf of janet vanderpuye <rhy...@gmail.com> Reply-To: "swagger-sw...@googlegroups.com" <swagger-sw...@googlegroups.com> Date: Thursday, 22 December 2016 at 12:28 To: Swagger <swagger-sw...@googlegroups.com> Subject: Re: Cant locate swagger.json on java + embedded jetty + httpservlet + swagger integration Yeah the Api calls work. I can make calls to my servlets without error. Its just the swagger documentation is not generating any of my annotations. On Thursday, 22 December 2016 15:25:14 UTC-5, Ron wrote: Okay, so it should work. Is your API itself accessible? Can you make any of the API calls successfully? From: <swagger-sw...@googlegroups.com> on behalf of janet vanderpuye <rhy...@gmail.com> Reply-To: "swagger-sw...@googlegroups.com" <swagger-sw...@googlegroups.com> Date: Thursday, 22 December 2016 at 11:37 To: Swagger <swagger-sw...@googlegroups.com> Subject: Re: Cant locate swagger.json on java + embedded jetty + httpservlet + swagger integration In my pom file, I have 1.19.1 <dependency> <groupId>io.swagger</groupId> <artifactId>swagger-annotations</artifactId> <version>1.5.10</version> </dependency> <dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> <version>2.7</version> </dependency> <dependency> <groupId>io.swagger</groupId> <artifactId>swagger-jaxrs</artifactId> <version>1.5.10</version> </dependency> <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-servlet</artifactId> <version>1.19.1</version> </dependency> On Thursday, 22 December 2016 14:34:08 UTC-5, Ron wrote: Which version of Jersey do you use? From: <swagger-sw...@googlegroups.com> on behalf of janet vanderpuye <rhy...@gmail.com> Reply-To: "swagger-sw...@googlegroups.com" <swagger-sw...@googlegroups.com> Date: Thursday, 22 December 2016 at 11:10 To: Swagger <swagger-sw...@googlegroups.com> Subject: Re: Cant locate swagger.json on java + embedded jetty + httpservlet + swagger integration So for my servlets, I just tried: apiservlet = servletContextHandler.addServlet(ProfileServlet.class, "/user/*"); apiservlet.setInitOrder(3); apiservlet.setInitParameter("com.sun.jersey.config.property.packages", "com.coreservices.servlets;package com.coreservices.datatypes"); and apiservlet = servletContextHandler.addServlet(ProfileServlet.class, "/user/*"); apiservlet.setInitOrder(3); apiservlet.setInitParameter("com.sun.jersey.config.property.packages", "com.api.resources;io.swagger.jaxrs.json;io.swagger.jaxrs.listing;com.coreservices.servlets;package com.coreservices.datatypes"); I am still getting the default swagger response {"swagger":"2.0","info":{"version":"1.0.0","title":""}} Am I missing any annotation or configuration in the files? Secondly to access the swagger ui annotation for my custom servlet "ProfileServlet.class", do I use the same url as "http://host:7000/api/swagger.json"? Really appreciate the quick feedback on this On Thursday, 22 December 2016 13:52:18 UTC-5, tony tam wrote: Sounds like the issue then is how it’s scanning your code. Put your API package here: apiservlet.setInitParameter("com.sun.jersey.config.property.packages", "com.api.resources;io.swagger.jaxrs.json;io.swagger.jaxrs.listing"); so they can be scanned. On Dec 22, 2016, at 10:50 AM, janet vanderpuye <rhy...@gmail.com> wrote: Quick update. After modifying the initializeAPI method to the original Servlet class in the blog(see below), I was able to get some response from the swagger-ui on http://host:7000/api/swagger.json. But I it seems like swagger wasnt able to parse my servlet annotations http://host:7000/api/swagger.json ===> {"swagger":"2.0","info":{"version":"1.0.0","title":""}} private static Server initializeApi(Properties properties) { logger.info("Initializing user profile server..."); new UserDao(); Server server = new Server(Integer.parseInt(properties.getProperty(Config.JETTY_SERVICE_PORT))); ServletContextHandler servletContextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS); servletContextHandler.setContextPath("/"); server.setHandler(servletContextHandler); //Setup APIs ServletHolder apiservlet = servletContextHandler.addServlet(ServletContainer.class, "/api/*"); apiservlet.setInitOrder(1); apiservlet.setInitParameter("com.sun.jersey.config.property.packages", "com.api.resources;io.swagger.jaxrs.json;io.swagger.jaxrs.listing"); apiservlet = servletContextHandler.addServlet(ProfileServlet.class, "/user/*"); //apiservlet.setInitOrder(1); apiservlet.setInitParameter("com.sun.jersey.config.property.packages", "com.api.resources;io.swagger.jaxrs.json;io.swagger.jaxrs.listing"); logger.info("User profile server initialized."); // Setup Swagger servlet ServletHolder swaggerServlet = servletContextHandler.addServlet(DefaultJaxrsConfig.class, "/swagger-core"); swaggerServlet.setInitOrder(2); swaggerServlet.setInitParameter("api.version", "1.0.0"); // Setup Swagger-UI static resources String resourceBasePath = Main.class.getResource("/webapp").toExternalForm(); servletContextHandler.setWelcomeFiles(new String[] {"index.html"}); servletContextHandler.setResourceBase(resourceBasePath); servletContextHandler.addServlet(new ServletHolder(new DefaultServlet()), "/*"); return server; } On Thursday, 22 December 2016 13:31:03 UTC-5, janet vanderpuye wrote: I recently followed this blog to integrate swagger in my embedded jetty project but after running, I'm not able to access the swagger.json file on any path combination. Accessing the servlets for the resources work with no error but I get the following errors when I try to get the swagger.json file http://host:7000/swagger-core ===> HTTP ERROR 405 http://host:7000/swagger-core/swagger.json ===> HTTP ERROR 404 http://host:7000/user/swagger.json ===> HTTP ProfileServlet response, not swagger.json http://host:7000/user ===> HTTP ProfileServlet response, not swagger.json http://host:7000/swagger.json ===> HTTP ERROR 404 http://host:7000/api/swagger.json ===> HTTP ERROR 404 http://host:7000/ ===> Static swagger sample page (Pet store), not swagger.json Main.java public static void main(String[] args) throws Exception { Server server = initializeApi(properties); server.start(); logger.info("Api resource service started"); server.join(); } private static Server initializeApi(Properties properties) { logger.info("Initializing user profile server..."); new UserDao(); Server server = new Server(Integer.parseInt(properties.getProperty(Config.JETTY_SERVICE_PORT))); ServletContextHandler servletContextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS); servletContextHandler.setContextPath("/"); server.setHandler(servletContextHandler); //Setup APIs ServletHolder apiservlet = servletContextHandler.addServlet(ProfileServlet.class, "/user/*"); apiservlet.setInitOrder(1); apiservlet.setInitParameter("com.sun.jersey.config.property.packages", "com.api.resources;io.swagger.jaxrs.json;io.swagger.jaxrs.listing"); logger.info("User profile server initialized."); // Setup Swagger servlet ServletHolder swaggerServlet = servletContextHandler.addServlet(DefaultJaxrsConfig.class, "/swagger-core"); swaggerServlet.setInitOrder(2); swaggerServlet.setInitParameter("api.version", "1.0.0"); // Setup Swagger-UI static resources String resourceBasePath = Main.class.getResource("/webapp").toExternalForm(); servletContextHandler.setWelcomeFiles(new String[] {"index.html"}); servletContextHandler.setResourceBase(resourceBasePath); servletContextHandler.addServlet(new ServletHolder(new DefaultServlet()), "/*"); return server; } } ProfileServlet.java <pre style="backg -- You received this message because you are subscribed to the Google Groups "Swagger" group. To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "Swagger" group. To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "Swagger" group. To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "Swagger" group. To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "Swagger" group. To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "Swagger" group. To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.