Search code examples
restgoswaggergo-swagger

Golang Swagger annotation for enum input parameter


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.


Solution

  • 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"`
    }