“This is the 13th day of my participation in the First Challenge 2022. For details: First Challenge 2022.”
Hello everyone, I’m Ah Q!
Before, the company used Swagger as a document management tool, and the original Swagger UI was very ugly. Later, it used the Swagger component of the open source project Xiao Ming/Knife4J to render swagger. After the transformation, the interface is much more beautiful and the operation is much more convenient.
Of course this is not the point, the point is that our project references Knife4J and some problems arise:
- As used in the project
spring security
, using theknife4j
And then, you need to be rightknife4j
Do rule filtering separately, otherwise it cannot be accessedknife4j
Static resources of - Whether it is
knife4j
The same as beforeswagger-ui
As soon as the service stops,swagger
I can’t open the file - Different people under the same project want to present different documents, especially in the development phase, front-end students need to save multiple
swagger
Address to view different documents - integration
knife4j
It was actually quite heavy for the project, and going through each microservice also increased the work - .
gateway
Document aggregation pattern
Someone has done document aggregation at gateway, and its aggregation pattern is shown below
Its principle is very simple: it forwards the request to the micro-service, obtains swagger’S JSON information from the Micro-service restful interface, and then renders swagger information through the front-end.
The advantage of this is that only swagger-UI needs to be integrated at the gateway, and other micro-services do not need to be integrated separately. They only need to collect Swagger information and expose the interface to the Gateway, waiting for the Gateway to fetch the information. But it doesn’t completely solve the problems mentioned above, and it introduces new ones
- Is it reasonable for gateway to do document aggregation? As the gateway itself is exposed to the outside world, such interface documents may be leaked to ordinary users, and I personally think that doing this at the gateway does not conform to the positioning of the gateway
- This pattern does not solve the problem of development-phase documentation, which is constantly updated and requires publishing to a formal environment in order to view the documentation
- Still want to be in
spring security
Add the whitelist and let goswagger
The foreignrestful
interface - Cannot solve the problem of different documents for the same project
In view of this problem, I thought about it and tried to transform it in another way. In the following, we will continue to explain!
Post off
Ah Q will continue to update the Java practice of the article, interested in the public account can pay attention to: AH Q said the code, also can come to the technical group to discuss the problem!