Swagger UI not able to render resources in swagger 1.3-RC2

1,951 views
Skip to first unread message

prateek sharma

unread,
Aug 1, 2013, 9:11:49 AM8/1/13
to swagger-sw...@googlegroups.com
I upgraded my project to Swagger_2.9.1-1.3.0-RC2. Now when I access the base URL I get proper response.
For ex : accessing http://localhost:8002/api/api-docs
I get below response

{
  "apiVersion": "4.6",
  "swaggerVersion": "1.2",
  "apis": [
    {
      "path": "/user",
      "description": "get users by id and criteria"
    }
  ],
  "info": {
    "title": "My REST Apis",
    "description": "My REST Apis.",
    "contact": "api...@wordnik.com",
    "license": "Apache 2.0 License",
    "licenseUrl": "http://www.apache.org/licenses/LICENSE-2.0.html"
  }
}

But when I try to access any entity I get "requested resource not available" error.
For ex : If I try to access user
http://localhost:8002/api/api-docs/user

I get HTTP Status 404 error with description requested resource not found.

Is the URL to access entities/resources using swagger changed?

Thanks,
Pratz

tony tam

unread,
Aug 1, 2013, 10:27:40 AM8/1/13
to swagger-sw...@googlegroups.com
You are requesting it the right way, my guess is you're hitting a bug with the @Api value.. can you please post your @Api annotation on the user class?

prateek sharma

unread,
Aug 1, 2013, 12:56:41 PM8/1/13
to swagger-sw...@googlegroups.com
Below is one complete set of annotation including a class and method.

@Service("userRest")
@Path("/user")
@Api(value = "/user", description = "get users by id and criteria")
public class UserResourceImpl implements UserResource{

    @GET
    @Path("/{userId}")
    @Produces("application/json")
    @ApiOperation(value = "Get user by ID",  response = RemoteUser.class)
    @ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid ID supplied"),
                                          @ApiResponse(code = 404, message = "User not found") })
    public Response getUserById(
            @ApiParam(value = "ID of user that needs to be fetched", required = true)
            @PathParam("userId") String userId,
            @ApiParam(value = "Token stored in cookie", required = false)
            @CookieParam("token") Cookie token) {
                    

            }
}

Thanks,
Pratz

tony tam

unread,
Aug 1, 2013, 1:02:01 PM8/1/13
to swagger-sw...@googlegroups.com
I believe I fixed this this morning in the RC3 source code.  Some containers (tomcat for example) seem to be adding a trailing slash to the resource route (i.e. api-docs/pet => pet/) and that was failing to match the resource cache (it would be under /pet).

Can you please try using RC3 from source and report back?

To build from source, you can just run `mvn clean install` from the 1.3-RC3 branch.

prateek sharma

unread,
Aug 1, 2013, 3:18:04 PM8/1/13
to swagger-sw...@googlegroups.com
Hey Tony,
Thanks for the quick reply. I upgraded swagger to RC3 and now its working as intended.

But now I am getting an error, when I use swagger UI, which is as follows.

Now my base path is
http://localhost:8002/services/rest/latest/api-docs

To use swagger UI in my project I directly copied the dist folder to deployed tomcat project and accessed index.html.
When I give this base path to swagger UI and click explore I get this below error.

Unable to read api 'project' from path http://localhost:8002/services/rest/latest/user?api_key=special-key (server returned Bad Request)

Now if you observe the URL in the eror message above you can easily figure out that "api-docs" is missing from the URL. I believe swagger UI generates this URL dynamically.
What could be the reason of this problem?

Thanks,
Pratz

tony tam

unread,
Aug 1, 2013, 3:21:09 PM8/1/13
to swagger-sw...@googlegroups.com
I think that was a bug fixed last night in swagger-ui.  Can you grab the latest from here:

prateek sharma

unread,
Aug 1, 2013, 11:28:12 PM8/1/13
to swagger-sw...@googlegroups.com
Hey Tony,
I tried using swagger-ui_develop-2.0 but again getting the same error. It is not appending api-docs to the base path because of which it is not able to fetch JSON for particular resource.
Is there any other mailing list for swagger UI?

Thanks,
Pratz


--
You received this message because you are subscribed to a topic in the Google Groups "Swagger" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/swagger-swaggersocket/mbiU-jD_b0g/unsubscribe.
To unsubscribe from this group and all its topics, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

tony tam

unread,
Aug 2, 2013, 10:39:52 AM8/2/13
to swagger-sw...@googlegroups.com
Hi, can you please open the network tab in chrome and look at what it's trying to fetch?
To unsubscribe from this group and all its topics, send an email to swagger-swaggersocket+unsub...@googlegroups.com.

prateek sharma

unread,
Aug 3, 2013, 1:40:04 PM8/3/13
to swagger-sw...@googlegroups.com
Bingo.. It worked using swagger-UI-develop-2.0... I think it was my mistake because I was not specifying base path properly.

Thanks,
Pratz


To unsubscribe from this group and all its topics, send an email to swagger-swaggers...@googlegroups.com.

tony tam

unread,
Aug 3, 2013, 7:50:17 PM8/3/13
to swagger-sw...@googlegroups.com
great, thanks for following up
To unsubscribe from this group and all its topics, send an email to swagger-swaggersocket+unsubscri...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.
 
 
Reply all
Reply to author
Forward
0 new messages