Kongchen Swagger ignores @ApiModelProperty annotation

I tried to add additional information about my Swagger documentation, but I have some problems with the @ApiPropertyModel annotation in a specific one.

No matter what I'm trying to do, it just doesn't work. The plugin correctly generates Swagger.json , all @ApiOperation annotations work for REST resources, but for part of the model it only examines the properties of the model classes and does not look at the annotations above them.

Here's how the plugin is configured:

 <plugin> <groupId>com.github.kongchen</groupId> <artifactId>swagger-maven-plugin</artifactId> <version>3.1.5</version> <configuration> <apiSources> <apiSource> <locations> <location>com.example.rest.resources</location> <location>com.example.rest.model</location> </locations> <swaggerDirectory>${project.build.directory}/generated-sources</swaggerDirectory> <basePath>/path/to/the/api</basePath> <info> <title>My RESTful API Documentation</title> <version>${project.version}</version> </info> </apiSource> </apiSources> </configuration> <executions> <execution> <phase>generate-sources</phase> <goals> <goal>generate</goal> </goals> </execution> </executions> </plugin> 

If I have, for example:

 @ApiModelProperty(example = "test example") public String test; 

It will generate the test property, but will not create any example or any other property that I created in this annotation. The same thing happens when used in a getter, so I think this is not a problem.

Am I doing something wrong? In addition, I looked at the Kongchen project example, and I could not see anything special to make it work.

+7
java annotations swagger
source share
2 answers

I tried to build the code again, and I found that the problem was with the structure of the project. It has different modules and has a profile for general development and a profile for RESTful API documentation only.

I was distracted for some time and started building projects using mvn clean package , and since it had a version of the project, it used it to create documentation and why it never changed after I used mvn clean install in the main source code, I could see the annotation make any effect.

I'm sorry guys, this was outside of any information that I could give about the draft documentation, as it was something like the whole structure that I use. But at least I will keep this answer so that the next person can know about it.

Thanks for attention!

+1
source share

Did you forget the @ApiModel annotation on your model classes?

how

 @ApiModel public class PostRequest { @ApiModelProperty(example = "test example") public String test; } 

or your model package does not match what is specified in pom.xml.

0
source share

All Articles