swagger:file

Usage

// swagger:file

What it does

Marks a parameter or response body as a binary file ({type: file}).

The scanner emits the file-type marker without further introspection of the Go type.

Where it goes

On a struct field doc inside a swagger:parameters (multipart file upload) or swagger:response (file download) struct.

Grammar (EBNF)

FileBlock = ANN_FILE , [ Title ] , [ Description ] ;

Takes no argument — an optional title/description may follow on the doc comment.

Supported keywords

Standard parameter / response keywords; the file marker stacks with in: and other parameter shape keywords. See the keywords reference.

Example

Annotated Go
// swagger:route POST /pets/{id}/photo pets uploadPetPhoto
//
// responses:
//
//	200: petsResponse

// UploadParams is the multipart upload for the uploadPetPhoto operation.
//
// swagger:parameters uploadPetPhoto
type UploadParams struct {
	// Photo is the image to upload.
	//
	// in: formData
	// swagger:file
	Photo io.ReadCloser `json:"photo"`
}

Full source: docs/examples/concepts/routes/routes.go

Generated spec
[
  {
    "type": "file",
    "x-go-name": "Photo",
    "description": "Photo is the image to upload.",
    "name": "photo",
    "in": "formData"
  }
]

Full source: docs/examples/concepts/routes/testdata/file.json