Skip to main content

API Documentation

By using standardized routing, GoFrame automatically generates API documentation. All API information will be automatically generated in /api.json following the OpenAPIv3 standard. By default, the framework uses redoc to generate the frontend documentation page, which can only view API information and cannot perform request tests. Therefore, it can be changed to other UI pages, such as swaggerUI or implementing a custom UI page.

  • Comment out swaggerPath: "/swagger" in manifest/config/config.yml
  • Implement the UI page and introduce the swaggerUI component

swagger.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="/swagger-ui.css">
<script src="/swagger-ui-bundle.js"></script>
<title>API Doc</title>
</head>
<body>
<div id="swagger-ui"></div>
</body>
</html>

<script type="text/javascript">
window.ui = SwaggerUIBundle({
url: '/api.json',
dom_id: '#swagger-ui'
})
</script>

If the introduced CSS and JS files are downloaded into the project, use the above method to include them, or they can be introduced through the following CDN:

<link rel="stylesheet" href="https://unpkg.com/swagger-ui-dist@latest/swagger-ui.css" />
  • Add a route
group.GET("/swagger", func(req *ghttp.Request) {
req.Response.WriteTpl("/swagger.html")
})