Golang中用于枚举输入参数的Swagger注解

huangapple go评论69阅读模式
英文:

Golang Swagger annotation for enum input parameter

问题

我不确定如何为 REST 调用的输入字符串参数指定注释。输入参数可以取三个可能的字符串值之一。

如果我假设会有一个下拉菜单,其中包含这三个值(containers/bundles/web),用户将选择其中一个。之前我参考了这个文档来为输入参数创建注释。

我正在尝试注释 Go 代码,以便可以自动生成swagger.yamlswagger generate spec -o ./swagger.yaml --scan-models)。不幸的是,我找不到一个带有枚举或输入参数限制为特定值的注释示例。正在寻找一些代码示例。

英文:

I am not sure how to specify annotation for an input string parameter for a rest call. Where input parameter can take one of three possible string values.

If I have to assume there will be a drop down menu with these three value (containers/bundles/web) and the user will chose one of them. Previously I am referring to this documentation to create annotation for an in parameters.

I am trying to annotate go code, so that I can generate swagger.yaml automatically (swagger generate spec -o ./swagger.yaml --scan-models). Unfortunately, I couldn't find an annotated example that expects enums or the input parameters is limited to certain values. Looks for some code examples.

答案1

得分: 1

像这样使用枚举注释应该可以工作。

// swagger:parameters artifactInfo
type ArtifactTypeParam struct {
    // The type of artifact
    // in: path
    // enum: container,bundle,executbale
    // required: true
    ArtifactType string `json:"artifactType"`
}
英文:

some thing like this with enum annotation should work.

// swagger:parameters artifactInfo
type ArtifactTypeParam struct {
	// The type of artifact
	// in: path
	// enum: container,bundle,executbale
	// required: true
	ArtifactType string `json:"artifactType"`
}

huangapple
  • 本文由 发表于 2022年1月22日 05:49:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/70807968.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定