A huge pit that I always thought was the Swagger cache, finally solved it today

Recently, the project began to use Swagger as the writing tool for Api documentation. Swagger really brings a lot of convenience to the development work. But occasionally, the interface description has been modified, but the old field description is always seen on doc.html. Even sometimes the field has been deleted, no matter how to restart, how to clear the cache, it is still there.

During the period, I always thought it was a cache problem. Please ask the browser to cache, change the browser, or even delete the tmp directory of the operating system, all of which cannot be solved. During this period, the front-end developers always said that my interface did not match the description of the document. Tired.

I accidentally opened the "Swagger Models" menu today, and found that the number of models displayed on the interface is so small, which is quite different from the number of classes in my server code. So I took a look at the back-end code and compared the model details in "Swagger Models". I finally discovered the root cause of this huge pit. It turned out that the value I wrote when defining @ApiModel was the same. Swagger did not report an error, but silently helped me combine the fields of the two classes. The code and effect are shown in the figure below:
UserDto

User2Dto

Effect

As shown in the above example diagrams, if the ApiModel names of the two classes are the same, there will be various problems that are mistaken for caching. If two classes have the same field, but the descriptions of the two fields are different, there will be a problem that one covers the other. Sometimes one is deleted, because the other is not deleted, and there will be a situation where it is thought that it cannot be deleted. 

 

 

 

Guess you like

Origin blog.csdn.net/gaoshan12345678910/article/details/121087513