Hanzo
PlatformHanzo CloudDeveloper Guide

Generating Swagger Files

Generating Swagger Files

Overview

As we know, the beego framework provides support for generating swagger files to clarify the API via the command line tool called "bee". Hanzo Cloud is also built based on beego. However, we found that the swagger files generated by bee failed to categorize the APIs with the "@Tag" label. So, we modified the original bee to implement this function.

How to write the comment

Most rules are exactly identical to the original bee comment formats. The only discrepancy is that the API shall be divided into different groups according to the "@Tag" label. Therefore, developers are obliged to ensure that this tag is correctly added. Here is an example:

// @Title Login
// @Tag Login API
// @Description login
// @Param   oAuthParams     query    string  true        "oAuth parameters"
// @Param   body    body   RequestForm  true        "Login information"
// @Success 200 {object} controllers.api_controller.Response The Response object
// @router /login [post]
func (c *ApiController) Login() {

APIs with the same "@Tag" labels will be put into the same group.

## How to generate the swagger file

0. Write comments for the API in the correct format.
1. Fetch this repository: [https://github.com/hanzoai/bee](https://github.com/hanzoai/bee).
2. Build the modified bee. For example, in the root directory of hanzoai/bee, run the following command:

    ```shell
    go build -o mybee .
  1. Copy mybee to the base directory of Hanzo Cloud.
  2. In that directory, run the following command:
    mybee generate docs
  3. (Optional) If you want to generate swagger document for specific tags or apis, here are some example commands:
    mybee generate docs --tags "Adapter API"
    mybee generate docs --tags "Adapter API,Login API"
    mybee generate docs --apis "add-adapter"
    mybee generate docs --apis "add-adapter,delete-adapter"
    Notably: We only accept a comma , as the separator when multiple tags/apis provided.

Then you will find that the new swagger files are generated.

How is this guide?

Last updated on

On this page