springfox / springfox

Automated JSON API documentation for API's built with Spring
http://springfox.io
Apache License 2.0
5.93k stars 1.54k forks source link

Controllers with @RequestMapping below the root are not detected (eg., @RequestMapping("/api/pets") instead of @RequestMapping("/pets") #26

Closed martypitt closed 11 years ago

Miamoto-Musashi commented 11 years ago

Any news about it? i have all my REST services under http://localhost/rest/* and i cannot document any of them.

thanks

ankurvsoni commented 11 years ago

Same here. Any updates on this?

dilipkrish commented 11 years ago

@ankurvsoni @Miamoto-Musashi This issue should be fixed now. Do let me know if it doesnt work for you.

ankurvsoni commented 11 years ago

@dilipkrish will check it out. Is there an official version where the fix is available?

martypitt commented 11 years ago

Version 0.3.0 has just been released, should sync to maven central shortly.

Please test, and close this bug if resolved.

ankurvsoni commented 11 years ago

I see /api-docs and /api-docs/\ mapped. /api-docs works fine. But if I try to access one of my api's i.e. /api-docs/api/pets - I get:

Caused by: java.lang.IllegalArgumentException: Class org.springframework.web.util.UriComponentsBuilder would not be serialized as a JSON object and therefore has no schema at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.generateJsonSchema(DefaultSerializerProvider.java:260) at com.fasterxml.jackson.databind.ObjectMapper.generateJsonSchema(ObjectMapper.java:2539) at com.mangofactory.swagger.ControllerDocumentation$1.apply(ControllerDocumentation.java:84) at com.mangofactory.swagger.ControllerDocumentation$1.apply(ControllerDocumentation.java:76) at com.google.common.collect.Maps$2.transformEntry(Maps.java:1252) at com.google.common.collect.Maps$TransformedEntriesMap$1$1$1.getValue(Maps.java:1542) at java.util.HashMap.putAllForCreate(HashMap.java:534) at java.util.HashMap.(HashMap.java:320) at com.google.common.collect.Maps.newHashMap(Maps.java:144) at com.mangofactory.swagger.ControllerDocumentation.getModels(ControllerDocumentation.java:76) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.get(BeanPropertyWriter.java:653) at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:509) at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:551) ... 42 more

Not sure what might be causing this?

dilipkrish commented 11 years ago

Most likely you have UriComponentsBuilder as a method parameter which isn't really a model and we cannot infer the schema. Try adding UriComponentsBuilder to the ignorableParameterTypes collection to the swagger configuration extension bean … I think that should fix your problem

Example below:

<bean id="swaggerConfiguration" class="com.mangofactory.swagger.SwaggerConfiguration">
    <property name="basePath" value="${service.documentation.base-url}"/>

ankurvsoni commented 11 years ago

Thanks. With minor modification I was able to get this working. However, I see another issue - When I access

http://localhost:8080/example-service/api-docs - I get:

{"apiVersion":"1.0","swaggerVersion":"1.0","basePath":"http://localhost:8080/example-service","apis":[{"path":"/api-docs/api/examples"}]}

But for - http://localhost:8080/example-service/api-docs/api/examples - I get:

{"apiVersion":"1.0","swaggerVersion":"1.0","basePath":"http://localhost:8080/example-service","resourcePath":"api/examples","models":{}}

I don't any "apis" here. Any ideas why?

Thanks!

dilipkrish commented 11 years ago

Thats not enough information for me to tell whats going on. Possibly your controller methods do not have a request mapping annotation? May be posting your controller class might help. In any case, If your original problem has been fixed please move to close this open bug and open a new bug for the scenario you're now having.

dilipkrish commented 11 years ago

This bug should be fixed