form:"-" Not Treated as "Ignore Field", Instead Generates Query Parameter name: "-" (And Duplicates)
Phenomenon
In the Go ecosystem, struct tags json:"-" / form:"-" semantically mean "ignore this field". However, goctl's swagger generation treats form:"-" as the actual parameter name - and outputs it to query parameters. Multiple form:"-" generate multiple name: "-", directly violating OpenAPI's "(in,name) uniqueness" constraint.
Minimal Reproduction
form_dash.api:
syntax = "v1"
info(
title: "t"
desc: "t"
author: "t"
email: "t"
)
type Req {
A string `form:"a,optional"`
Hidden1 bool `form:"-"`
Hidden2 []int `form:"-"`
}
type Resp {
Ok bool `json:"ok"`
}
@server(
prefix: /api/test
group: test
)
service t {
@handler H
get /q (Req) returns (Resp)
}
Run:
goctl api swagger --api form_dash.api --dir . --filename form_dash
Actual Result (Key Swagger Snippet)
[
{
"type": "string",
"name": "a",
"in": "query",
"allowEmptyValue": true
},
{
"type": "boolean",
"name": "-",
"in": "query",
"required": true
},
{
"type": "array",
"items": {
"type": "integer"
},
"name": "-",
"in": "query",
"required": true
}
]
Expected Result
- Fields with
form:"-" should be completely ignored and not generate any parameters.
Real-World Case
In stability-alert-center's swagger.json:
GET /api/alertcenter/alert-config/my-configs has two query parameters with name: "-" (corresponding to two form:"-" fields).
Possible Fix Directions (For PR Reference)
In tools/goctl/api/swagger/parameter.go, the current logic directly uses tag.Name for formTag / pathParameterTag, lacking special handling for "-".
Suggestions:
- When
formTag.Name == "-", directly return (skip parameter generation).
- Apply consistent handling to similar tags like
json:"-", header:"-", path:"-", etc.
- Add unit tests covering
"-" tags.
form:"-"Not Treated as "Ignore Field", Instead Generates Query Parametername: "-"(And Duplicates)Phenomenon
In the Go ecosystem, struct tags
json:"-"/form:"-"semantically mean "ignore this field". However, goctl's swagger generation treatsform:"-"as the actual parameter name-and outputs it to query parameters. Multipleform:"-"generate multiplename: "-", directly violating OpenAPI's "(in,name) uniqueness" constraint.Minimal Reproduction
form_dash.api:Run:
goctl api swagger --api form_dash.api --dir . --filename form_dashActual Result (Key Swagger Snippet)
[ { "type": "string", "name": "a", "in": "query", "allowEmptyValue": true }, { "type": "boolean", "name": "-", "in": "query", "required": true }, { "type": "array", "items": { "type": "integer" }, "name": "-", "in": "query", "required": true } ]Expected Result
form:"-"should be completely ignored and not generate any parameters.Real-World Case
In
stability-alert-center'sswagger.json:GET /api/alertcenter/alert-config/my-configshas two query parameters withname: "-"(corresponding to twoform:"-"fields).Possible Fix Directions (For PR Reference)
In
tools/goctl/api/swagger/parameter.go, the current logic directly usestag.NameforformTag/pathParameterTag, lacking special handling for"-".Suggestions:
formTag.Name == "-", directlyreturn(skip parameter generation).json:"-",header:"-",path:"-", etc."-"tags.