zeromicro / goctl-swagger

MIT License
208 stars 133 forks source link

fix go validator in api #72

Open dxyinme opened 1 year ago

dxyinme commented 1 year ago

I found a bug if I use validator in *.api file. This plugin will generate the illegal swagger file like this.

        // API body
    AddTaskTypeReq {
        SessionId         string `json:"session_id"`
        Name              string `json:"name" validate:"gte=1,lte=64"`
        MaxTaskInQueLimit int64  `json:"max_task_in_que_limit" validate:"min=-1,max=100000"`
        ExtraInfo         string `json:"extra_info,optional"`
    }

swagger json

"AddTaskTypeReq": {
      "type": "object",
      "properties": {
        "session_id": {
          "type": "string"
        },
        "name": {
          "type": "string"
        },
        "max_task_in_que_limit": {
          "type": "integer",
          "format": "int64"
        },
        "extra_info": {
          "type": "string"
        }
      },
      "title": "AddTaskTypeReq",
      "required": [
        "session_id",
        "name",
        "gte=1",
        "max_task_in_que_limit",
        "min=-1"
      ]
    }

the gte=1 and min=-1 in output file is unexpected. so I create a PR to fix this bug