Code Monkey home page Code Monkey logo

springfox's Introduction

Springfox

Join the chat at https://gitter.im/springfox/springfox FOSSA Status Download Project Stats

Build Status Coverage Code Analysis
Circle CI codecov Quality Gate Status
Sonar Cloud
Security Rating
Vulnerabilities
Maintainability Rating
Reliability Rating
Technical Debt
Coverage

About

For more information on this project visit the Springfox Website or http://springfox.github.io/springfox/

Useful links

Getting Started

For new projects

For Maven

<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-boot-starter</artifactId>
    <version>3.0.0</version>
</dependency>

For Gradle

  implementation "io.springfox:springfox-boot-starter:<version>"

Migrating from earlier snapshot

Spring Boot Applications

NOTE: Would love feedback to make this better

  1. Remove explicit dependencies on springfox-swagger2
  2. Remove any @EnableSwagger2... annotations
  3. Add the springfox-boot-starter dependency
  4. Springfox 3.x removes dependencies on guava and other 3rd party libraries (not zero dep yet! depends on spring plugin and open api libraries for annotations and models) so if you used guava predicates/functions those will need to transition to java 8 function interfaces.

Migrating from existing 2.x version

Spring Boot Applications

NOTE: Would love feedback to make this better

  1. Remove explicit dependencies on springfox-swagger2
  2. Remove the @EnableSwagger2 annotations
  3. Add the springfox-boot-starter dependency
  4. Springfox 3.x removes dependencies on guava and other 3rd party libraries (not zero dep yet! depends on spring plugin and open api libraries for annotations and models) so if you used guava predicates/functions those will need to transition to java 8 function interfaces
  5. If you are using WebMvc but you don't use the @EnableWebMvc annotation yet, add this annotation.

Regular spring mvc

NOTE: Would love feedback to make this experience better

  1. Remove explicit dependencies on springfox-swagger2
  2. Add @EnableOpenApi for open API (and @EnableSwagger2WebMvc or @EnableSwagger2WebFlux for older versions)
  3. Added the springfox-oas library
  4. Springfox 3.x removes dependencies on guava and other 3rd party libraries (not zero dep yet! depends on spring plugin and open api libraries for annotations and models) so if you used guava predicates/functions those will need to transition to java 8 function interfaces

License

Copyright 2015 Marty Pitt - @martypitt, Dilip Krishnan - @dilipkrish, Adrian Kelly - @adrianbk,

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 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.

License

FOSSA Status

springfox's People

Contributors

acwatson avatar adrianbk avatar batkinsonidexx avatar cbornet avatar dbaje avatar dependabot-preview[bot] avatar dependabot[bot] avatar dilipkrish avatar dschulten avatar fgaule avatar heapifyman avatar iles-2e avatar jamesecahill avatar jfiala avatar jogir avatar kasecato avatar ligasgr avatar maksimorlov avatar masterspb avatar mate1983 avatar mathieuales avatar matrosovs avatar mazday avatar mzeijen avatar olowolo avatar robwin avatar shouldnotappearcalm avatar tbruyelle avatar thomseno avatar williamvoor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

springfox's Issues

support nested controllers

Hi,

I have controllers that are mapped like this:

@Controller
@RequestMapping("/foo")
public class FooController {

    @ResponseBody
    @RequestMapping(method = RequestMethod.GET)
    public String getFoo() {
        return "foo";
    }

}

@Controller
@RequestMapping("/foo/bar")
public class BarController {

    @ResponseBody
    @RequestMapping(method = RequestMethod.GET)
    public String getBar() {
        return "bar";
    }

}

This results in spring endpoints like:

GET /foo
GET /foo/bar

Swagger-springmvc seems to group swagger "APIs" on a per controller level. But for my usecase to work in swagger I guess it would need to somehow merge both controllers into the "/foo" api. Therefore at the moment only my "root" controllers are browsable in swagger-ui as springmvc does not call the DocumentationController.getApiDocumentation if apiName contains slashes like it would be the case with "/foo/bar".

Is something like this possible with swagger-springmvc? I can't simply merge all controller classes as the web service sports a lot of endpoints that are grouped hierarchically.

Logger output: Class null has no @RequestMapping

Hi,

On server's startup I receive plenty of messages in a log file about absence @RequestMapping annotation in a class. This is good but such message doesn't contain information which class it is actually. The output message in log file looks like the following:

INFO - Class null has no @RequestMapping

And code that produces this output:

protected static String resolveRequestUri(RequestMapping requestMapping) {
   if (requestMapping == null) {
     log.info("Class {} has no @RequestMapping", requestMapping);
     return null;
   }
   ...
}

The reason is using requestMapping method parameter as a parameter for log message - it is always null. There should be a second parameter provided which should be currently scanned class (or method - but in this case the output message should be changed as well).

The issue is not critical one :)

Cheers,
Michaล‚

Ignore parameters and resources path.

Hello,

we are setting up spring swagger on our rest apis and are facing 2 problems :

1 - our methods have some spring parameters that are not used for rest :

public void doSomething ( ... ,ModelMap modelMap, HttpServletRequest request) {
}

is there a way to exclude modelMap and request from the API Parameters ?

2 - api path

we would like to have our path start with some parameters, not with a resource :
in spite of :
@RequestMapping("/users")

we would like :
@RequestMapping("{customer_id}/users")

Do you know anyway to achieve that ?

Many thanks for your kind support,

Patrick

java.lang.StackOverflowError

complex schema with loops generate SOE but not trough spring integration

Is there a way to exclude schema scan?

thanks

java.lang.StackOverflowError
at com.fasterxml.jackson.databind.JsonNode.(JsonNode.java:43)
at com.fasterxml.jackson.databind.node.BaseJsonNode.(BaseJsonNode.java:23)
at com.fasterxml.jackson.databind.node.ContainerNode.(ContainerNode.java:27)
at com.fasterxml.jackson.databind.node.ObjectNode.(ObjectNode.java:22)
at com.fasterxml.jackson.databind.node.JsonNodeFactory.objectNode(JsonNodeFactory.java:287)
at com.fasterxml.jackson.databind.ser.std.StdSerializer.createObjectNode(StdSerializer.java:107)
at com.fasterxml.jackson.databind.ser.std.StdSerializer.createSchemaNode(StdSerializer.java:112)
at com.fasterxml.jackson.databind.ser.std.StdSerializer.createSchemaNode(StdSerializer.java:119)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.getSchema(BeanSerializerBase.java:641)
at com.fasterxml.jackson.databind.ser.std.StdSerializer.getSchema(StdSerializer.java:99)
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.depositSchemaProperty(BeanPropertyWriter.java:488)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.getSchema(BeanSerializerBase.java:665)

Methods with java.lang.Object breaks the parser

If a method returns Object or uses Object as a parameter, the parser fails. It is found to be compatible with List.class (it's assignable from).

A fix that works for me is by detecting java.lang.Object as a primitive in the Models class. But that does not seem to cover the case where SimpleModelTest is modified to include an Object property.

Support for Iterable (as List)

Since you can make a List from Iterable it should be supported in the model. Resthub (based on Spring MVC) uses this extensively.

Can't use with swagger-ui

I've implement an API and annotated it with this project. However, I'm not able to use swagger-ui to explore the api. The raw JSON produced by the apidoc controller seems to be fine. Here's the resources listing JSON

{
  "apiVersion" : "1.0",
  "swaggerVersion" : "1.0",
  "basePath" : "http://localhost:8080/workflow-api/api/apidoc",
  "apis" : [ {
    "path" : "/wf",
    "description" : "Operation on Workflows"
  } ]
}

There's a single API ("wf"). The JSON for it has some empty fields, but in general it looks OK.

{
  "apiVersion" : "1.0",
  "swaggerVersion" : "1.0",
  "basePath" : "http://localhost:8080/workflow-api/api/apidoc",
  "resourcePath" : "/wf",
  "apis" : [ {
    "path" : "/wf/{id}",
    "description" : "Operation on Workflows",
    "operations" : [ {
      "httpMethod" : "GET",
      "summary" : "Gets a workflow by ID",
      "notes" : "",
      "deprecated" : false,
      "nickname" : "getWorkflow",
      "tags" : [ "" ],
      "parameters" : [ {
        "description" : "Workflow ID",
        "notes" : "",
        "paramType" : "path",
        "defaultValue" : "",
        "required" : true,
        "allowMultiple" : false,
        "dataType" : "String"
      } ]
    }, {
      "httpMethod" : "PUT",
      "summary" : "Update a workflow's name or description",
      "notes" : "",
      "deprecated" : false,
      "nickname" : "updateWorkflow",
      "tags" : [ "" ],
      "parameters" : [ {
        "description" : "Workflow object containg a user id, workflow name and description",
        "notes" : "",
        "paramType" : "path",
        "defaultValue" : "",
        "required" : true,
        "allowMultiple" : false,
        "dataType" : "Workflow"
      } ]
    }, {
      "httpMethod" : "DELETE",
      "summary" : "Delete a workflow by ID",
      "notes" : "",
      "deprecated" : false,
      "nickname" : "deleteWorkflow",
      "tags" : [ "" ],
      "parameters" : [ {
        "description" : "Workflow ID",
        "notes" : "",
        "paramType" : "path",
        "defaultValue" : "",
        "required" : true,
        "allowMultiple" : false,
        "dataType" : "String"
      } ]
    } ]
  }, {
    "path" : "/wf",
    "description" : "Operation on Workflows",
    "operations" : [ {
      "httpMethod" : "GET",
      "summary" : "Gets all workflows",
      "notes" : "",
      "deprecated" : false,
      "nickname" : "getAllWorkflows",
      "tags" : [ "" ]
    }, {
      "httpMethod" : "POST",
      "summary" : "Create a new workflow",
      "notes" : "",
      "deprecated" : false,
      "nickname" : "createWorkflow",
      "tags" : [ "" ],
      "parameters" : [ {
        "description" : "Workflow object containg a user id, workflow name and description",
        "notes" : "",
        "paramType" : "path",
        "defaultValue" : "",
        "required" : true,
        "allowMultiple" : false,
        "dataType" : "Workflow"
      } ]
    } ]
  } ]
}

The error I see on swagger-ui is:
0 : error http://localhost:8080/workflow-api/api/apidoc.json

I've done some debugging, with breakpoints, and found the code is failing when jQuery tries to read the JSON from the server (swagger.js:52)

return jQuery.getJSON(this.discoveryUrl, function(response) {

Please let me know if there's some better way of debugging, and what else should I include in this report.

swagger UI doesn't work if the annotation Introspector is changed.

If you change out the jacksonAnnotationIntrospector for the JaxbAnnotationIntrospector, or just add the jaxb to the pair, then swagger UI will show your controllers, but not the list of methods under them. See the following for how our spring-mvc webservices are exposed:

<context:component-scan base-package="com.mycompany.controllers"/>


<bean id="jaxbAnnIntrospector" class="com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector" />
<bean id="jacksonAnnIntrospector" class="com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector" />
<bean id="pairIntrospector" class="com.fasterxml.jackson.databind.introspect.AnnotationIntrospectorPair" >
    <constructor-arg index="0" ref="jacksonAnnIntrospector"/>
    <constructor-arg index="1" ref="jaxbAnnIntrospector"/>
</bean>

<bean id="jacksonObjectMapper" class="com.fasterxml.jackson.databind.ObjectMapper">
    <property name="serializationInclusion" value="NON_NULL"/>
    <property name="annotationIntrospector" ref="pairIntrospector" />
</bean>

<mvc:annotation-driven>
    <mvc:message-converters register-defaults="true">
        <bean class="org.springframework.http.converter.StringHttpMessageConverter">
            <property name="supportedMediaTypes" value="text/plain;charset=UTF-8"/>
        </bean>
        <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
            <property name="objectMapper" ref="jacksonObjectMapper"/>
            <property name="supportedMediaTypes" >
                <list>
                    <value>application/json</value>
                    <value>application/xml</value>
                </list>
            </property>
        </bean>
    </mvc:message-converters>
</mvc:annotation-driven>

Improve the schema generation

Currently the schema generation relies on the fasterxml implementation which does not work very well when

  • There are recursive/cyclic class definitions (Stackoverflow described in Issue #45)
  • The jackson schema generator inlines model definitions which swagger specification does not like (Issue #46)
  • Enums do not get generated with allowable values.

Make configuration story cohesive

Currently extensibility is available via config. As well as annotations. These should be more cohesive.

Whether described in annotations (ApiIgnore/ApiInclude) or via xml configration extensions. The configuration model should isomorphic

Can basePath be set to webapp context?

The documented way to set up the SwaggerConfiguration bean is to hardcode the basePath. Is there a way to pick up the current webapp context instead?
I understand that when finally publishing it would be better to use properties, since public URL isn't necessarily the same as the webapps deployed context (proxies in front etc).

Implementing ApiParamsImplicit

Hi there,

I'm trying to use the @ApiParamsImplicit annotation. Has this been implemented?

@RequestMapping(method = RequestMethod.GET)
@ResponseBody
@ApiParamsImplicit({@ApiParamImplicit(name="X-Header-1", dataType = "String", paramType = "header"), @ApiParamImplicit(name="X-Header-2", dataType = "String", paramType = "header")})
public RestApiResponse getUser(@RequestParam("userId") String userId) throws UserNotFoundException, UserDeletedException, InvalidUserException, InvalidUserFieldException, InvalidTokenException {
// code
    }

Mvc's @ApiErrors should take a list of @ApiError

Currently, the swagger-springmvc version of @ApiErrors doesn't accept a list of @ApiError, which makes it incompatiable with the corresponding swagger annotation.

This is annoying, and means you end up with long, ugly fully-qualified annotation names all over the class.

The swagger-springmvc annotation should accept a list of ApiError, like so:

@ApiErrors(errors={
        @ApiError(code=302,reason="Malformed request"),
        @ApiError(code=404,reason="Not found")
    })
    public void exceptionMethodD() {}

Maven Repo

Do you by chance have your artifact out in a maven repo anywhere? Reason being... I would much rather add a dependency to my local project as opposed to building swagger-springmvc locally and then including it into my project. Thanks.

Swagger ui displays the resourcepath as the root

Hi,
I am using swagger 0.3.1 to generate API documentation for my application. It displays the Controller Name as the root.
For example, it displays the apis in the Login Controller as follows:
/login-controller
/login
/logout
That is clicling on /login-controller exapnds to give the apis in that controller.
I want to display the apis without the first level being the controller name.
I want the ui to have only the name of the apis and not which class it belongs to.
Can you please help me with that?

P.S.
When I am using 0.3.0 version then I am able to see only the name of the apis. But the names of the apis which is of the form say test/app is displayed only as /app and not test/app.

Thank you for your help

NullPointerException on 0.3.1 maven artifact

Using the following maven artifact I get a null point exception on application start.

com.mangofactory swagger-springmvc 0.3.1

Mar 07, 2013 8:59:33 AM org.apache.catalina.core.ApplicationContext log
SEVERE: StandardWrapper.Throwable
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'documentationController' defined in URL [jar:file:/mnt/data/workspace/rds/modules/server/rds-web/target/rds/WEB-INF/lib/swagger-springmvc-0.3.1.jar!/com/mangofactory/swagger/spring/controller/DocumentationController.class]: Initialization of bean failed; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:609)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:469)
at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:631)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:588)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:645)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:508)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:449)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:133)
at javax.servlet.GenericServlet.init(GenericServlet.java:212)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1173)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:993)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4350)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4659)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:445)
at org.apache.catalina.startup.Embedded.start(Embedded.java:825)
at org.codehaus.mojo.tomcat.AbstractRunMojo.startContainer(AbstractRunMojo.java:558)
at org.codehaus.mojo.tomcat.AbstractRunMojo.execute(AbstractRunMojo.java:255)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
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 org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: java.lang.NullPointerException
at com.mangofactory.swagger.spring.OperationReader.readOperation(OperationReader.java:46)
at com.mangofactory.swagger.spring.DocumentationReader.appendOperationsToEndpoint(DocumentationReader.java:127)
at com.mangofactory.swagger.spring.DocumentationReader.appendOperationsToEndpoint(DocumentationReader.java:117)
at com.mangofactory.swagger.spring.DocumentationReader.processMethod(DocumentationReader.java:100)
at com.mangofactory.swagger.spring.DocumentationReader.buildMappingDocuments(DocumentationReader.java:53)
at com.mangofactory.swagger.spring.DocumentationReader.(DocumentationReader.java:48)
at com.mangofactory.swagger.spring.controller.DocumentationController.setServletContext(DocumentationController.java:54)
at org.springframework.web.context.support.ServletContextAwareProcessor.postProcessBeforeInitialization(ServletContextAwareProcessor.java:75)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:394)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1448)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
... 47 more

Wrong ApiModel annotation taken for a method's parameters

Hi there!

I have a controller with method that accepts two parameters. The method and parameters are annotated with @apimodel annotation like the following example:

@RequestMapping(...)
@ApiOperation(...)
@apimodel(type = Result.class)
ResponseEntity process(
@apimodel(type = String.class) @ApiParam(...) @PathVariable String param1,
@apimodel(type = Param.class) @ApiParam(...) @requestbody Param param)
{ ... }

Having such scenario I see in Swagger UI that "Data type" for parameters is the same as the type specified in @apimodel annotation on method level. ApiModel annotations for parameters seems to be ignored.

Maybe I'm doing something wrong here but I found in AnnotatedParameterFilter class the following line (number 57 for v0.3.4):

ApiModel apiModel = methodParameter.getMethodAnnotation(ApiModel.class);

This could be the reason of the behavior described above. Shouldn't be there methodParameter.getParameterAnnotation(ApiModel.class) used?

Schema and complex POJOs objects

Hello guys,
I am not sure if this question should go here or on the core project so please forgive me if it is not related to the Spring MVC component.
On my swagger UI the JSON shema I have for the POST methods do not show any nested objects. I have for example a POJO with some Strings and Number fields and inside some other object as inner class with its Strings and Numbers. The inner class field is shown as "object" without its fields. I use Spring 3.2 and Jackson 1.9.9.
I tested the demo as well, since I though it has something to do with my project, but it has the same result.
Here is the Pet object with a Recipient object inside it.

{"id":"string,
"name":"string",
"age":"string",
"recipient":"object"
}
The model though describes the object just fine:
models": {
"Pet": {
"id": "Pet",
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
},
"age": {
"type": "integer"
},
"recipient": {
"properties": {
"msisdn": {
"type": "string"
},
"id": {
"type": "string"
}
},
"type": "object"
}
}
}

The same goes for Lists as well. Am I missing something? Is there an annotation or something that I should include? From the wiki of the core project I understand that the model data types must describe the complex and list types. I think they do for that example. And if they don't how am I supposed to make it? I don't think hacking the source code is a solution here.

Thanks,
Kosmas

Jackson Annotations?

Hi,

How can I use json produced by jackson in the api? I use few annotations like JsonProperty or JsonIgnore but swagger just produces its own content and ignores jackson. What would be the correct way?

UI stalling when API returns a ResponseEntity<String>

I'm using 0.4.0 and springMVC running in jetty.

When I have my API definitions as returning a ResponseEntity object (or any derived class from HttpEntity, the UI will stall at "fetching resource : http://localhost:8085/api-docs/core/metrics?api_key=special-key"

If I make it return a String, or Object, then it will work fine. Strangely, the XML returned when accessing the data directly is exactly the same.

Good:
@RequestMapping(method = RequestMethod.GET, value="/v0.1/test", produces = CONTENT_TYPE)
@ApiOperation(value = "Register DNS service name", notes = "A Path representing the DNS name to register is pas")
@responsebody
public Object test() {
return null;
}

Bad:
@RequestMapping(method = RequestMethod.GET, value="/v0.1/test", produces = CONTENT_TYPE)
@ApiOperation(value = "Register DNS service name", notes = "A Path representing the DNS name to register is pas")
@responsebody
public ResponseEntity test() {
return null;
}

RequestMapping paths not supported

I have a controller annotated at the class-level like so:

@RequestMapping(value="/invitations/**")
public class InvitationsController {
...
}

Then there is a method, annotated as:

@RequestMapping(value="/invitations/{userid}")
public void createInvitation(...) {
...
}

The createInvitation method is found at:

/invitations/{userid}

However, swagger creates the operation at:

/invitations/invitations/{userId}

So, either I did something wrong, or only the very simplest use cases (one URI per controller) are currently supported.

mapping into /resources

version 0.2.4 map to /resources instead of /api-docs for me
version 0.2.5-SNAPSHOT works as expected (when do you release it?)

thanks

Can't compile from master code

Any guide on how to compile the code? Seems like it has trouble finding dependency to lombok.

Thanks,

$ mvn compile

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building Swagger SpringMVC 0.5.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-enforcer-plugin:1.0:enforce (enforce-maven) @ swagger-springmvc ---
[INFO] 
[INFO] --- maven-resources-plugin:2.3:resources (default-resources) @ swagger-springmvc ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /projects/swagger-springmvc/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.0:compile (default-compile) @ swagger-springmvc ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 53 source files to /projects/swagger-springmvc/target/classes
[INFO] -------------------------------------------------------------
[WARNING] COMPILATION WARNING : 
[INFO] -------------------------------------------------------------
[WARNING] /projects/swagger-springmvc/src/main/java/com/mangofactory/swagger/spring/filters/ErrorsFilter.java: Some input files use unchecked or unsafe operations.
[WARNING] /projects/swagger-springmvc/src/main/java/com/mangofactory/swagger/spring/filters/ErrorsFilter.java: Recompile with -Xlint:unchecked for details.
[INFO] 2 warnings 
[INFO] -------------------------------------------------------------
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /projects/swagger-springmvc/src/main/java/com/mangofactory/swagger/models/ResolvedtypeMemberVisitor.java:[15,8] class ResolvedTypeMemberVisitor is public, should be declared in a file named ResolvedTypeMemberVisitor.java
[ERROR] /projects/swagger-springmvc/src/main/java/com/mangofactory/swagger/spring/EndpointReader.java:[23,46] cannot find symbol
  symbol:   method getEndpointFilters()
  location: variable configuration of type com.mangofactory.swagger.SwaggerConfiguration
[ERROR] /projects/swagger-springmvc/src/main/java/com/mangofactory/swagger/SwaggerConfiguration.java:[108,51] cannot find symbol
  symbol:   method getDocumentationFilters()
  location: variable extensions of type com.mangofactory.swagger.SwaggerConfigurationExtension
[ERROR] /projects/swagger-springmvc/src/main/java/com/mangofactory/swagger/SwaggerConfiguration.java:[109,46] cannot find symbol
  symbol:   method getEndpointFilters()
  location: variable extensions of type com.mangofactory.swagger.SwaggerConfigurationExtension
[ERROR] /projects/swagger-springmvc/src/main/java/com/mangofactory/swagger/SwaggerConfiguration.java:[110,47] cannot find symbol
  symbol:   method getOperationFilters()
  location: variable extensions of type com.mangofactory.swagger.SwaggerConfigurationExtension
[ERROR] /projects/swagger-springmvc/src/main/java/com/mangofactory/swagger/SwaggerConfiguration.java:[111,47] cannot find symbol
  symbol:   method getParameterFilters()
  location: variable extensions of type com.mangofactory.swagger.SwaggerConfigurationExtension
[ERROR] /projects/swagger-springmvc/src/main/java/com/mangofactory/swagger/SwaggerConfiguration.java:[112,43] cannot find symbol
  symbol:   method getErrorFilters()
  location: variable extensions of type com.mangofactory.swagger.SwaggerConfigurationExtension
[ERROR] /projects/swagger-springmvc/src/main/java/com/mangofactory/swagger/SwaggerConfiguration.java:[113,54] cannot find symbol
  symbol:   method getIgnorableParameterTypes()
  location: variable extensions of type com.mangofactory.swagger.SwaggerConfigurationExtension
[ERROR] /projects/swagger-springmvc/src/main/java/com/mangofactory/swagger/SwaggerConfiguration.java:[114,27] cannot find symbol
  symbol:   method getDocumentationTransformer()
  location: variable extensions of type com.mangofactory.swagger.SwaggerConfigurationExtension
[ERROR] /projects/swagger-springmvc/src/main/java/com/mangofactory/swagger/SwaggerConfiguration.java:[115,54] cannot find symbol
  symbol:   method getDocumentationTransformer()
  location: variable extensions of type com.mangofactory.swagger.SwaggerConfigurationExtension
[ERROR] /projects/swagger-springmvc/src/main/java/com/mangofactory/swagger/SwaggerConfiguration.java:[117,44] cannot find symbol
  symbol:   method getEndPointComparator()
  location: variable extensions of type com.mangofactory.swagger.SwaggerConfigurationExtension
[ERROR] /projects/swagger-springmvc/src/main/java/com/mangofactory/swagger/SwaggerConfiguration.java:[118,45] cannot find symbol
  symbol:   method getOperationComparator()
  location: variable extensions of type com.mangofactory.swagger.SwaggerConfigurationExtension
[ERROR] /projects/swagger-springmvc/src/main/java/com/mangofactory/swagger/spring/UriExtractor.java:[57,13] cannot find symbol
  symbol:   variable log
  location: class com.mangofactory.swagger.spring.UriExtractor
[ERROR] /projects/swagger-springmvc/src/main/java/com/mangofactory/swagger/spring/UriExtractor.java:[62,13] cannot find symbol
  symbol:   variable log
  location: class com.mangofactory.swagger.spring.UriExtractor
[ERROR] /projects/swagger-springmvc/src/main/java/com/mangofactory/swagger/spring/UriExtractor.java:[66,13] cannot find symbol
  symbol:   variable log
  location: class com.mangofactory.swagger.spring.UriExtractor
[ERROR] /projects/swagger-springmvc/src/main/java/com/mangofactory/swagger/spring/ControllerAdapter.java:[43,63] cannot find symbol
  symbol:   method getDocumentationBasePath()
  location: variable configuration of type com.mangofactory.swagger.SwaggerConfiguration
[ERROR] /projects/swagger-springmvc/src/main/java/com/mangofactory/swagger/DocumentationTransformer.java:[26,26] cannot find symbol
  symbol:   method getEndPointComparator()
  location: variable configuration of type com.mangofactory.swagger.SwaggerConfiguration
[ERROR] /projects/swagger-springmvc/src/main/java/com/mangofactory/swagger/DocumentationTransformer.java:[27,66] cannot find symbol
  symbol:   method getEndPointComparator()
  location: variable configuration of type com.mangofactory.swagger.SwaggerConfiguration
[ERROR] /projects/swagger-springmvc/src/main/java/com/mangofactory/swagger/DocumentationTransformer.java:[29,34] cannot find symbol
  symbol:   method getOperationComparator()
  location: variable configuration of type com.mangofactory.swagger.SwaggerConfiguration
[ERROR] /projects/swagger-springmvc/src/main/java/com/mangofactory/swagger/DocumentationTransformer.java:[30,77] cannot find symbol
  symbol:   method getOperationComparator()
  location: variable configuration of type com.mangofactory.swagger.SwaggerConfiguration
[ERROR] /projects/swagger-springmvc/src/main/java/com/mangofactory/swagger/spring/filters/ApplicationFilter.java:[13,37] cannot find symbol
  symbol:   method getSwaggerVersion()
  location: variable config of type com.mangofactory.swagger.SwaggerConfiguration
[ERROR] /projects/swagger-springmvc/src/main/java/com/mangofactory/swagger/spring/filters/ApplicationFilter.java:[14,31] cannot find symbol
  symbol:   method getBasePath()
  location: variable config of type com.mangofactory.swagger.SwaggerConfiguration
[ERROR] /projects/swagger-springmvc/src/main/java/com/mangofactory/swagger/spring/filters/ApplicationFilter.java:[15,33] cannot find symbol
  symbol:   method getApiVersion()
  location: variable config of type com.mangofactory.swagger.SwaggerConfiguration
[ERROR] /projects/swagger-springmvc/src/main/java/com/mangofactory/swagger/spring/controller/DocumentationController.java:[42,48] method getDocumentation in class com.mangofactory.swagger.spring.DocumentationReader cannot be applied to given types;
  required: java.lang.String
  found: no arguments
  reason: actual and formal argument lists differ in length
[ERROR] /projects/swagger-springmvc/src/main/java/com/mangofactory/swagger/spring/controller/DocumentationController.java:[43,68] cannot find symbol
  symbol:   method getDocumentationTransformer()
  location: variable swaggerConfiguration of type com.mangofactory.swagger.SwaggerConfiguration
[ERROR] /projects/swagger-springmvc/src/main/java/com/mangofactory/swagger/spring/DocumentationReader.java:[74,32] cannot find symbol
  symbol:   variable log
  location: class com.mangofactory.swagger.spring.DocumentationReader
[ERROR] /projects/swagger-springmvc/src/main/java/com/mangofactory/swagger/spring/DocumentationReader.java:[138,28] cannot find symbol
  symbol:   variable log
  location: class com.mangofactory.swagger.spring.DocumentationReader
[ERROR] /projects/swagger-springmvc/src/main/java/com/mangofactory/swagger/spring/OperationReader.java:[38,46] cannot find symbol
  symbol:   method getOperationFilters()
  location: variable configuration of type com.mangofactory.swagger.SwaggerConfiguration
[ERROR] /projects/swagger-springmvc/src/main/java/com/mangofactory/swagger/spring/OperationReader.java:[56,50] cannot find symbol
  symbol:   method getParameterFilters()
  location: variable configuration of type com.mangofactory.swagger.SwaggerConfiguration
[ERROR] /projects/swagger-springmvc/src/main/java/com/mangofactory/swagger/spring/OperationReader.java:[76,46] cannot find symbol
  symbol:   method getErrorFilters()
  location: variable configuration of type com.mangofactory.swagger.SwaggerConfiguration
[ERROR] /projects/swagger-springmvc/src/main/java/com/mangofactory/swagger/filters/AnnotatedParameterFilter.java:[38,37] cannot find symbol
  symbol:   variable log
  location: class com.mangofactory.swagger.filters.AnnotatedParameterFilter
[ERROR] /projects/swagger-springmvc/src/main/java/com/mangofactory/swagger/filters/AnnotatedParameterFilter.java:[42,55] incompatible types
  required: lombok.val
  found:    com.wordnik.swagger.core.DocumentationAllowableValues
[ERROR] /projects/swagger-springmvc/src/main/java/com/mangofactory/swagger/filters/AnnotatedParameterFilter.java:[55,18] method setAllowableValues in class com.wordnik.swagger.core.DocumentationParameter cannot be applied to given types;
  required: com.wordnik.swagger.core.DocumentationAllowableValues
  found: lombok.val
  reason: actual argument lombok.val cannot be converted to com.wordnik.swagger.core.DocumentationAllowableValues by method invocation conversion
[ERROR] /projects/swagger-springmvc/src/main/java/com/mangofactory/swagger/filters/AnnotatedParameterFilter.java:[78,78] incompatible types
  required: lombok.val
  found:    java.lang.String[]
[ERROR] /projects/swagger-springmvc/src/main/java/com/mangofactory/swagger/filters/AnnotatedParameterFilter.java:[79,41] method buildAllowableRangeValues in class com.mangofactory.swagger.spring.AllowableRangesParser cannot be applied to given types;
  required: java.lang.String[],java.lang.String
  found: lombok.val,java.lang.String
  reason: actual argument lombok.val cannot be converted to java.lang.String[] by method invocation conversion
[ERROR] /projects/swagger-springmvc/src/main/java/com/mangofactory/swagger/filters/AnnotatedParameterFilter.java:[81,79] incompatible types
  required: lombok.val
  found:    java.lang.String[]
[ERROR] /projects/swagger-springmvc/src/main/java/com/mangofactory/swagger/filters/AnnotatedParameterFilter.java:[82,41] method buildAllowableRangeValues in class com.mangofactory.swagger.spring.AllowableRangesParser cannot be applied to given types;
  required: java.lang.String[],java.lang.String
  found: lombok.val,java.lang.String
  reason: actual argument lombok.val cannot be converted to java.lang.String[] by method invocation conversion
[ERROR] /projects/swagger-springmvc/src/main/java/com/mangofactory/swagger/filters/AnnotatedParameterFilter.java:[88,35] incompatible types
  required: lombok.val
  found:    java.util.List<java.lang.String>
[ERROR] /projects/swagger-springmvc/src/main/java/com/mangofactory/swagger/filters/AnnotatedParameterFilter.java:[89,16] no suitable constructor found for DocumentationAllowableListValues(lombok.val)
    constructor com.wordnik.swagger.core.DocumentationAllowableListValues.DocumentationAllowableListValues(java.util.List<java.lang.String>) is not applicable
      (actual argument lombok.val cannot be converted to java.util.List<java.lang.String> by method invocation conversion)
    constructor com.wordnik.swagger.core.DocumentationAllowableListValues.DocumentationAllowableListValues() is not applicable
      (actual and formal argument lists differ in length)
[ERROR] /projects/swagger-springmvc/src/main/java/com/mangofactory/swagger/spring/AllowableRangesParser.java:[32,39] incompatible types
  required: lombok.val
  found:    com.wordnik.swagger.core.DocumentationAllowableRangeValues
[ERROR] /projects/swagger-springmvc/src/main/java/com/mangofactory/swagger/spring/AllowableRangesParser.java:[33,24] incompatible types
  required: com.wordnik.swagger.core.DocumentationAllowableRangeValues
  found:    lombok.val
[INFO] 41 errors 
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.335s
[INFO] Finished at: Mon Apr 29 08:38:39 EST 2013
[INFO] Final Memory: 22M/212M
[INFO] ------------------------------------------------------------------------

Support for multiple formats

The swagger spec allows for documentation to be generated either in Xml or Json, generally as defined in the endpoint :

http://petstore.swagger.wordnik.com/api/api-docs.json

Currenly, only Json is supported

Add includeResources property to SwaggerConfiguration

Hi,

I have a legacy project that has hundreds of RequestMappings. It's a lot easier to specify the urls I want to expose as endpoints (white-list) rather than the endpoints I want to exclude (blacklist).

Another reason I'm making this request, the sheer number of RequestMappings in my project is causing a Stackoverflow exception when using swagger-ui.

Thanks.

Issue with dependencies

Hi, interesting project.

On a fresh clone running mvn install gives me:

[ERROR] Failed to execute goal on project swagger-springmvc: Could not resolve dependencies for project com.mangofactory:swagger-springmvc:jar:0.0.1-SNAPSHOT: Could not find artifact com.wordnik:swagger-core_2.9.1:jar:1.1-SNAPSHOT in com.springsource.repository.bundles.release (http://repository.springsource.com/maven/bundles/release) ->

I also noticed the various Spring repositories. You can probably replace all of them with a single repository. Check this FAQ page regarding recent changes.

UnrecognizedPropertyException on enum serialization to schema

I'm trying to create a model schema for the service where there is a class that has one field of enum type. Attempt causes generation of an empty DocumentationSchema for this class. I've tried to reproduce the situation in unit tests and after all I'm receiving stack trace pasted below.

The cause seems to be obvious but the question is: am I doing something wrong or there is it a bug? The entity (and its fields) is not annotated with any annotations from Swagger/Jackson.

Cheers,
Michal

Unrecognized field "enum" (class com.wordnik.swagger.core.DocumentationSchema), not marked as ignorable (13 known properties: , "items", "notes", "default", "access", "allowableValues", "uniqueItems", "$ref", "properties", "additionalProperties", "type", "id", "description", "required"])
at [Source: java.io.StringReader@3e018c74; line: 1, column: 187](through reference chain: com.wordnik.swagger.core.DocumentationSchema["properties"]->com.wordnik.swagger.core.DocumentationSchema["properties"]->com.wordnik.swagger.core.DocumentationSchema["enum"])
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "enum" (class com.wordnik.swagger.core.DocumentationSchema), not marked as ignorable (13 known properties: , "items", "notes", "default", "access", "allowableValues", "uniqueItems", "$ref", "properties", "additionalProperties", "type", "id", "description", "required"])
at [Source: java.io.StringReader@3e018c74; line: 1, column: 187](through reference chain: com.wordnik.swagger.core.DocumentationSchema["properties"]->com.wordnik.swagger.core.DocumentationSchema["properties"]->com.wordnik.swagger.core.DocumentationSchema["enum"])
at com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:79)
at com.fasterxml.jackson.databind.DeserializationContext.reportUnknownProperty(DeserializationContext.java:579)
at com.fasterxml.jackson.databind.deser.std.StdDeserializer.handleUnknownProperty(StdDeserializer.java:672)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownProperty(BeanDeserializerBase.java:906)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:328)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:121)
at com.fasterxml.jackson.databind.deser.std.MapDeserializer._readAndBindStringMap(MapDeserializer.java:429)
at com.fasterxml.jackson.databind.deser.std.MapDeserializer.deserialize(MapDeserializer.java:310)
at com.fasterxml.jackson.databind.deser.std.MapDeserializer.deserialize(MapDeserializer.java:26)
at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:375)
at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:98)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:308)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:121)
at com.fasterxml.jackson.databind.deser.std.MapDeserializer._readAndBindStringMap(MapDeserializer.java:429)
at com.fasterxml.jackson.databind.deser.std.MapDeserializer.deserialize(MapDeserializer.java:310)
at com.fasterxml.jackson.databind.deser.std.MapDeserializer.deserialize(MapDeserializer.java:26)
at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:375)
at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:98)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:308)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:121)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:2796)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:1942)
...

Nested objects don't generate or render properly

It would appear that rest methods that recieve or return an object that has properties that are themselves objects fail to render properly in swagger-ui. Looking at the pet shop example, this is because the model section in the pet shop defines multiple model elements and references one model from the next using the type attribute. The swagger-springmvc renders the model as one nested json structure. The result is that in the ui, nested objects show up as properties like "email: object".

Exlude Resources

Hello,
I need to exclude some controller from being visible in the UI.
Is this configuration property supposed to do the trick?

/users

Whatever I tried it didn't work. I checked the source code and "isExcluded(String controllerUri)" method is not used. It is like it is ignored. Is this an issue or is there another way to exclude controllers?

Thank you in advance,
Kosmas

Problem listing 'apis' for /api-docs/<service-mapping>

I have the following controller:

@Controller
@RequestMapping("api/examples")
public class ExampleServiceController {

   private static final String EFFECTIVE = "/effective";

   @RequestMapping(value = "/effective", method = GET)
   @ResponseBody
   public ResponseEntity<Example> getEffective(UriComponentsBuilder builder) {
   ....
   }

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?

This is in my spring config :

   <context:component-scan base-package="com.mangofactory.swagger.spring.controller" use-default-filters="false">
    <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
   </context:component-scan>

   <bean id="swaggerConfiguration" class="com.mangofactory.swagger.SwaggerConfiguration">
    <property name="basePath" value="http://localhost:8080/example-service"/>
    <property name="apiVersion" value="1.0"/>
    <property name="extensions">
      <bean class="com.mangofactory.swagger.SwaggerConfigurationExtension" >
         <property name="ignorableParameterTypes">
            <list>
               <value type="java.lang.Class">org.springframework.web.util.UriComponentsBuilder</value>
            </list>
         </property>
      </bean>
    </property>
   </bean>

Thanks!

NullPointerException when trying to generate controller which extends base class

I encounter NPE when running swagger-springmvc 0.4.2 with our project when trying to generate documentation for Controller which extends a base class.

Example of the structure

public abstract class BaseController<T extends BaseClass> {
   // some dependency here
   // some crud here
   // e.g.
   @RequestMapping(method= RequestMethod.POST)
   public @ResponseBody int createObject(@RequestBody T object) {
      // do some logic here
      return someId;
   }
}

@Controller
@RequestMapping("/suburl")
public class SubController extends BaseController<SubClass> {

   // some subclass dependency here
   // override one of superclass
   @Override
   public @ResponseBody int createObject(@RequestBody SubClass object) {
      int id = super.createObject(object);
      // do some logic with sub class
      return id;
   }
}

The error only happens if the subclass extends one of the method from super class. If I rename the method in subclass to be something like 'createChild' , swagger works normally.

The stacktrace is something like

SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'documentationController' defined in URL [jar:file:/${PROJECT_DIR}/WEB-INF/lib/swagger-springmvc-0.4.2.jar!/com/mangofactory/swagger/spring/controller/DocumentationController.class]: Initialization of bean failed; nested exception is java.lang.NullPointerException
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:609)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:469)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:383)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4135)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4630)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:445)
    at org.apache.catalina.startup.Embedded.start(Embedded.java:825)
    at org.codehaus.mojo.tomcat.AbstractRunMojo.startContainer(AbstractRunMojo.java:558)
    at org.codehaus.mojo.tomcat.AbstractRunMojo.execute(AbstractRunMojo.java:255)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
    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 org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: java.lang.NullPointerException
    at com.mangofactory.swagger.spring.OperationReader.readOperation(OperationReader.java:50)
    at com.mangofactory.swagger.spring.DocumentationReader.appendOperationsToEndpoint(DocumentationReader.java:127)
    at com.mangofactory.swagger.spring.DocumentationReader.appendOperationsToEndpoint(DocumentationReader.java:117)
    at com.mangofactory.swagger.spring.DocumentationReader.processMethod(DocumentationReader.java:100)
    at com.mangofactory.swagger.spring.DocumentationReader.buildMappingDocuments(DocumentationReader.java:53)
    at com.mangofactory.swagger.spring.DocumentationReader.<init>(DocumentationReader.java:48)
    at com.mangofactory.swagger.spring.controller.DocumentationController.setServletContext(DocumentationController.java:58)
    at org.springframework.web.context.support.ServletContextAwareProcessor.postProcessBeforeInitialization(ServletContextAwareProcessor.java:75)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:394)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1448)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
    ... 41 more

Is this a problem with swagger-springmvc, or something has to be done with our Controllers to get it working with swagger-springmvc ?

Thanks,

/apidoc not being generated

I am deploying from maven into JBoss and I can see in the server logs that it is parsing the java files.

I have made sure to set up my servlet to point to "http://localhost:8080/mysite/" but when I go to "http://localhost:8080/mysite/apidoc" the server logs, "org.springframework.web.servlet.PageNotFound No mapping found for HTTP request with URI [/mysite/apidocs.json] in DispatcherServlet with name 'mvc-dispatcher'"

I have been stuck on this issue for many days but cannot for the life of me figure out what is going on. Any direction would be much appreciated.

Thank you in advance!

Controller without @RequestMapping on class level results in NullPointerException

Gives me the warning
"Class XXX has handler methods, but no class-level @RequestMapping. No documentation will be generated"

But then later in the code a NullPointerException occur:

Caused by:
java.lang.NullPointerException
at com.mangofactory.swagger.springmvc.MvcApiReader.processMethod(MvcApiReader.java:92)
at com.mangofactory.swagger.springmvc.MvcApiReader.buildMappingDocuments(MvcApiReader.java:54)
at com.mangofactory.swagger.springmvc.MvcApiReader.(MvcApiReader.java:43)
at com.mangofactory.swagger.springmvc.controller.DocumentationController.afterPropertiesSet(DocumentationController.java:64)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.