Routes & operations
These keywords live inside a swagger:route or swagger:operation block. They
carry the operation’s transport metadata β the URL schemes, the media types it
consumes and produces β and the two sub-language bodies that declare its
parameters and responses. Several of them double as document-wide defaults under
swagger:meta (Spec metadata), where an
operation-level value overrides the default.
Summary
| Keyword | Aliases | Shape | Contexts |
|---|---|---|---|
schemes | β | flex-list | meta, route, operation |
consumes | β | flex-list | meta, route, operation |
produces | β | flex-list | meta, route, operation |
responses | β | sub-language (<code>: <tokens>) | route, operation |
parameters | β | sub-language (+ name: chunks) | route, operation |
tags | β | string list / tag objects | meta, route, operation |
deprecated | β | boolean | operation, route, schema |
security | β | YAML sequence (raw-block) | meta, route, operation |
externalDocs | external docs, external-docs | {description, url} | meta, route, operation, schema |
extensions | β | x-* YAML map | route, operation (cross-cutting) |
The visiting rows are documented where they primarily apply: deprecated is
detailed under
Schema validations & decorators;
security (and its securityDefinitions catalogue) under
Security; externalDocs and extensions under
Spec metadata.
Worked examples
A swagger:route block β the path-line annotation plus its transport metadata
and a Responses: body β side by side with the path item it produces:
// swagger:route GET /pets pets listPets
//
// Lists pets in the store, optionally filtered by tag.
//
// responses:
//
// 200: petsResponse
// default: errorResponseFull source: docs/examples/concepts/routes/routes.go
{
"get": {
"tags": [
"pets"
],
"summary": "Lists pets in the store, optionally filtered by tag.",
"operationId": "listPets",
"parameters": [
{
"type": "string",
"x-go-name": "Tag",
"description": "Tag filters pets by tag.",
"name": "tag",
"in": "query"
},
{
"maximum": 100,
"minimum": 1,
"type": "integer",
"format": "int32",
"x-go-name": "Limit",
"description": "Limit caps the number of results.",
"name": "limit",
"in": "query"
}
],
"responses": {
"200": {
"$ref": "#/responses/petsResponse"
},
"default": {
"$ref": "#/responses/errorResponse"
}
}
}
}
Full source: docs/examples/concepts/routes/testdata/route.json
The swagger:operation long form carries the same metadata in a YAML body,
including an inline parameters sequence:
// swagger:operation GET /pets/{id} pets getPet
//
// ---
// summary: Get a pet by ID.
// parameters:
// - name: id
// in: path
// required: true
// type: integer
// format: int64
// responses:
// '200':
// description: the requested pet
// schema:
// $ref: '#/definitions/Pet'
// default:
// $ref: '#/responses/errorResponse'Full source: docs/examples/concepts/routes/routes.go
{
"get": {
"tags": [
"pets"
],
"summary": "Get a pet by ID.",
"operationId": "getPet",
"parameters": [
{
"type": "integer",
"format": "int64",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "the requested pet",
"schema": {
"$ref": "#/definitions/Pet"
}
},
"default": {
"$ref": "#/responses/errorResponse"
}
}
}
}
Full source: docs/examples/concepts/routes/testdata/operation.json
Transport metadata
schemes
Accepted URL schemes for the operation. Flexible list β comma inline, multi-line
bare, YAML - markers, or any combination all produce the same output
(Schemes: http, https β‘ a - http / - https block). See
sub-languages Β§flex-lists for the unified rule.
Maps to schemes on the enclosing operation. It is also a document default
under swagger:meta (spec.schemes), where an operation-level value overrides
the meta-level one β see Spec metadata.
consumes / produces
Media-type lists β the request body MIME types the operation consumes and the
response MIME types it produces. Same flex-list rule as schemes: comma
inline, multi-line bare, YAML - markers, or any combination.
Map to consumes / produces on the surrounding scope. Like schemes, both are
also swagger:meta document defaults overridden per operation.
Body sub-languages
responses
Per-route / per-operation response declarations. The body is one response per
line in the form <code>: <tokens>, where <code> is an HTTP status (or
default) and <tokens> names the body schema and/or description:
The full per-line grammar lives at sub-languages Β§responses.
parameters
Per-route / per-operation parameter declarations. The body is a sequence of
+ name: chunks β the + is the chunk-start sigil (- is accepted as an
alias) β each chunk a small key/value block describing one parameter:
The full per-chunk grammar lives at sub-languages Β§parameters.
tags
Tag declarations whose shape depends on context:
In
swagger:route/swagger:operationthe body is a plain string list. It is unioned and deduplicated with the tags written on the annotation’s header line, and the result lands on the operation’stags:In
swagger:metathe body is instead a YAML sequence of tag objects emitted into the spec’s top-leveltagsβ each with aname, an optionaldescription, a nestedexternalDocs, and anyx-*vendor extensions:The meta tag-objects form is also referenced from Spec metadata.
Visiting keywords
These keywords also appear in a route/operation block but are detailed on their home page:
deprecatedβ marks the operation deprecated (native OAS 2.0deprecated). See Schema validations & decorators.securityβ the per-route / per-operation requirement list (an emptySecurity: []on an operation is an explicit public opt-out). See Security.externalDocsβ the operation’s external-documentation pointer. See Spec metadata.extensionsβ vendorx-*entries on the operation. See Spec metadata.