Keyword reference
This document catalogs the keyword: value forms recognised inside
annotation blocks. The keywords come in two flavours:
- Inline keywords β one line,
keyword: valueshape, with the value classified by a value shape (number, integer, boolean, string, β¦). - Body keywords β a header line followed by indented continuation
lines. The body’s interpretation depends on the keyword (a flat
token list for
Consumes:, a YAML map forSecurityDefinitions:, a per-line sub-language forParameters:/Responses:onswagger:route).
The reader-friendly orientation is in annotations.md (which annotation accepts which keywords, with examples); this file is the per-keyword reference card. Implementers wanting the formal productions should read grammar.md.
Table of contents
- Reading the tables
- Value shapes
- Annotation contexts
- Summary table
- Numeric validations β
maximum,minimum,multipleOf - Length / array validations β
maxLength,minLength,maxItems,minItems - Format validations β
pattern,unique,collectionFormat - Schema decorators β
default,example,enum,required,readOnly,discriminator,deprecated - Parameter location β
in - Meta single-line keywords β
schemes,version,host,basePath,license,contact - Body keywords β
consumes,produces,security,securityDefinitions,responses,parameters,extensions,infoExtensions,tos,externalDocs
Reading the tables
Each keyword entry carries:
- Name β canonical spelling. This is what
Property.Keyword.Namecompares equal to. Comparisons are case-insensitive on the canonical spelling and on every alias. - Aliases β alternate spellings the lexer accepts. They map to the canonical name at lex time; consumers never see alias values.
- Value shape β the lexical category of the value. See value shapes for what each one means and how it surfaces to consumers.
- Contexts β the family-level scopes where the keyword is legal.
Using a keyword outside its legal contexts emits a
CodeContextInvaliddiagnostic and the keyword is dropped from the affected block.
Value shapes
The grammar’s lexer classifies every value into one of these
shapes. The shape determines which Walker callback fires for the
property and which field of Property.Typed carries the parsed
value.
| Shape | Typed payload | Example value forms |
|---|---|---|
number | float64 (with optional </<=/>/>=/= prefix) | 5, 1.5, <10, >=0, =42 |
integer | int64 | 5, 100 |
boolean | bool | true, false, 1, 0 |
string | raw string | ^[a-z]+$, date-time, multipart/form-data |
comma-list | raw string; split on , by Property.AsList() | http, https, a,b,c |
enum-option | typed string (closed-vocab match) | csv, pipes for collectionFormat: |
raw-block | accumulated body lines on Property.Body | multi-line YAML, indented token lists |
raw-value | the verbatim post-colon text on Property.Value | 42, "orange", [1, 2, 3] |
When typing fails (e.g. maximum: notanumber) the lexer emits a
CodeInvalidNumber / CodeInvalidInteger / CodeInvalidBoolean
diagnostic and the property reaches the Walker with a zero-value
payload. Consumers gate on Property.IsTyped() to skip
malformed-typed values; the corresponding builder field stays
unwritten.
Annotation contexts
The closed set of contexts a keyword can legally appear in. A keyword
table entry’s Contexts field combines these:
| Context | Meaning |
|---|---|
param | Parameter doc on a swagger:parameters struct field, or a + name: chunk inside swagger:route Parameters: |
header | Header field on a swagger:response struct |
schema | Top-level model or struct field on a swagger:model |
items | Items-level (array element) validation on either parameter or schema |
route | Route-level metadata under swagger:route |
operation | Inline operation metadata under swagger:operation |
meta | Package-level metadata under swagger:meta |
response | Response-level decorations |
Summary table
The full keyword surface, in the order the keyword table declares them. Detailed entries follow this table.
| Keyword | Aliases | Shape | Contexts |
|---|---|---|---|
maximum | max | number | param, header, schema, items |
minimum | min | number | param, header, schema, items |
multipleOf | multiple of, multiple-of | number | param, header, schema, items |
maxLength | max length, max-length, maxLen, max len, max-len, maximum length, maximum-length, maximumLength, maximum len, maximum-len | integer | param, header, schema, items |
minLength | min length, min-length, minLen, min len, min-len, minimum length, minimum-length, minimumLength, minimum len, minimum-len | integer | param, header, schema, items |
pattern | β | string | param, header, schema, items |
maxItems | max items, max-items, max.items, maximum items, maximum-items, maximumItems | integer | param, header, schema, items |
minItems | min items, min-items, min.items, minimum items, minimum-items, minimumItems | integer | param, header, schema, items |
unique | β | boolean | param, header, schema, items |
collectionFormat | collection format, collection-format | enum-option (csv, ssv, tsv, pipes, multi) | param, header, items |
default | β | raw-value | param, header, schema, items |
example | β | raw-value | param, header, schema, items |
enum | β | raw-value | param, header, schema, items |
required | β | boolean | param, schema |
readOnly | read only, read-only | boolean | schema |
discriminator | β | boolean | schema |
deprecated | β | boolean | operation, route, schema |
in | β | enum-option (query, path, header, body, formData) | param |
schemes | β | raw-block (token list) | meta, route, operation |
version | β | string | meta |
host | β | string | meta |
basePath | base path, base-path | string | meta |
license | β | string | meta |
contact | contact info, contact-info | string | meta |
consumes | β | raw-block (token list) | meta, route, operation |
produces | β | raw-block (token list) | meta, route, operation |
security | β | raw-block (security requirements) | meta, route, operation |
securityDefinitions | security definitions, security-definitions | raw-block (YAML map) | meta |
responses | β | raw-block (response sub-language) | route, operation |
parameters | β | raw-block (parameter chunk sub-language) | route, operation |
extensions | β | raw-block (YAML map of x-* entries) | meta, route, operation, schema, param, header |
infoExtensions | info extensions, info-extensions | raw-block (YAML map of x-* entries) | meta |
tos | terms of service, terms-of-service, termsOfService | raw-block (prose paragraph) | meta |
externalDocs | external docs, external-docs | raw-block (YAML map) | meta, route, operation, schema |
Numeric validations
Apply to numeric schema types (integer, number). On a typed
schema with a non-numeric type, these keywords emit
CodeShapeMismatch and drop. On a typeless schema (no type:
declared upstream), they apply best-effort.
maximum
Upper bound on a numeric value. Alias: max.
The value may carry a leading comparison operator that becomes the exclusive/inclusive bound:
maximum: 10β inclusive (β€ 10).maximum: <10β exclusive (< 10).maximum: <=10β inclusive (same as no prefix).maximum: =10β inclusive.
Maps to schema.maximum and schema.exclusiveMaximum.
β from fixtures/enhancements/... (any numeric-validation fixture).
minimum
Lower bound on a numeric value. Alias: min. Same operator-prefix
shape as maximum. Maps to schema.minimum and
schema.exclusiveMinimum.
multipleOf
Divisibility constraint. The value must be a positive number.
Aliases: multiple of, multiple-of. Maps to schema.multipleOf.
Length / array validations
maxLength / minLength apply only to string-typed schemas;
maxItems / minItems apply only to array-typed schemas. Using
the wrong pairing emits CodeShapeMismatch and drops the keyword.
maxLength
Maximum string length. Many aliases for ergonomic spelling:
max length, max-length, maxLen, max len, max-len,
maximum length, maximum-length, maximumLength, maximum len,
maximum-len. Maps to schema.maxLength.
minLength
Minimum string length. Same alias set as maxLength with min in
place of max. Maps to schema.minLength.
maxItems
Maximum array length. Aliases: max items, max-items,
max.items, maximum items, maximum-items, maximumItems. Maps
to schema.maxItems.
minItems
Minimum array length. Same alias shape as maxItems with min in
place of max. Maps to schema.minItems.
Format validations
pattern
A regex constraint on a string value. The pattern is preserved
verbatim on schema.pattern. The grammar runs a best-effort RE2
compile (Go’s regex engine) on the value; if it fails, a
CodeInvalidAnnotation diagnostic surfaces with the compile error.
The value still lands on the schema β downstream tools may use
JSON Schema’s wider regex dialect.
unique
Marks an array-typed schema as set-valued (no duplicates). Boolean.
Maps to schema.uniqueItems.
collectionFormat
How an array value is serialised on the wire. Closed-vocab:
csvβ comma-separated (default).ssvβ space-separated.tsvβ tab-separated.pipesβ pipe-separated.multiβ repeated?key=val&key=val2(query params only).
Aliases: collection format, collection-format. Maps to
parameter.collectionFormat / items.collectionFormat. Schema-level
contexts ignore this keyword (it’s a SimpleSchema concept; schemas
serialise via application/json).
When the source value doesn’t match the closed vocab, the raw value
is preserved verbatim on the parameter (matches the original
behaviour where pipe as a typo for pipes round-trips).
Schema decorators
default
Default value for a schema or simple-schema field. Raw-value shape β
the post-colon text is captured verbatim and coerced against the
resolved schema type at write time (ParseDefault /
CoerceValue).
Multi-line bodies are accepted for complex literals:
Single-line form for primitives:
example
An example value for the schema, surfaced in tooling. Same raw-value
shape as default. Maps to schema.example (or parameter.example
for SimpleSchema parameters).
enum
A closed set of allowed values. Three accepted surface forms:
- Comma list:
enum: red, green, blueβ split on,and trimmed. - JSON array:
enum: ["red", "green", "blue"]β parsed via YAML/JSON. - Multi-line list with
-markers:
Each element is coerced against the resolved schema type. Maps to
schema.enum.
For string-typed enums driven by Go const declarations the
swagger:enum annotation is the more idiomatic surface β it picks
up the constant names AND their godoc descriptions and produces an
x-go-enum-desc extension alongside the enum values. The
enum: keyword is the manual override.
required
Marks a field as required. Boolean.
- On a
swagger:modelstruct field: adds the field’s name to the enclosing schema’srequiredarray. - On a
swagger:parametersstruct field: setsparameter.required. - On a
swagger:responseheader: not applicable; the keyword is silently dropped (response headers don’t carryrequired).
readOnly
Marks a schema property as read-only. Aliases: read only,
read-only. Maps to schema.readOnly.
Schema-only β emitting readOnly: inside a SimpleSchema context
(non-body parameter, response header) emits
CodeUnsupportedInSimpleSchema and drops the keyword.
discriminator
Marks the property as the discriminator for an allOf polymorphic
schema. Boolean. Writes the property’s name onto the enclosing
schema’s discriminator field. Schema-only.
deprecated
Marks the carrying entity as deprecated. Boolean. Legal on operations
(operation.deprecated), routes (operation.deprecated on the
synthesised op), and schemas (some downstream tools render this).
Parameter location
in
Where the parameter value comes from. Closed-vocab:
queryβ query string parameter.pathβ path-parameter substitution.headerβ request header.bodyβ request body (JSON, etc.).formDataβ form-data body field (note:formaccepted as an alias insideswagger:route Parameters:chunks; the lexer normalises toformDataat the canonical surface).
A non-matching value emits a context-invalid diagnostic; the
parameter loses its in and may end up incorrectly classified
downstream.
Meta single-line keywords
Single-line keywords under swagger:meta. Values are taken as-is
from the post-colon string.
schemes
Accepted URL schemes. Flexible list β all forms below produce the
same ["http", "https"] output:
Maps to spec.schemes. See sub-languages.md
Β§flex-lists for the unified rule.
version
API version string. Maps to info.version.
host
Default host. Defaults to localhost when empty. Maps to
spec.host.
basePath
URL base path. Maps to spec.basePath. Aliases: base path,
base-path.
license
License declaration. Two forms accepted:
β¦where the trailing token starting with a URL scheme becomes
license.url and the prefix becomes license.name. A bare name
with no URL is accepted too.
contact
Contact declaration. Author writes a Name <email> URL triple, in
any order. The grammar recognises:
Name <email@example.com>β Go’snet/mail.ParseAddressform.Name <email@example.com> http://example.comβ same + trailing URL.- Just a URL, no name.
Aliases: contact info, contact-info. Maps to info.contact.
Body keywords
Body keywords have a header line ending in : and indented
continuation lines. The body’s structure depends on the keyword.
See sub-languages.md for the full
sub-language specifications; this section covers the keyword
shape.
consumes / produces
Media-type lists. Same flex-list rule as schemes: β comma
inline, multi-line bare, YAML - markers, or any combination.
Maps to consumes / produces on the surrounding scope (spec,
operation).
security
Security-requirements list. Each line is one requirement of shape
schemeName: scope1, scope2. An empty scope list (schemeName:)
means “no scopes required, but the scheme must be active.”
Maps to security (array of single-key maps).
securityDefinitions
YAML map declaring security schemes. The body is parsed as YAML
directly into the spec.securityDefinitions shape β see
OAS v2 Β§5.2.16.
Aliases: security definitions, security-definitions. Meta-only.
responses
Per-route / per-operation response declarations. Each line is one
response in the form <code>: <tokens>. See
sub-languages.md Β§responses for the
full per-line grammar.
parameters
Per-route / per-operation parameter declarations. Body is a sequence
of + name: chunks (the + is the chunk-start sigil; - is
accepted as an alias). See
sub-languages.md Β§parameters for
the full per-chunk grammar.
extensions / infoExtensions
Vendor extension declarations as a YAML map. Keys must start with
x- or X-; non-x-* keys emit CodeInvalidAnnotation and drop.
extensions:lands the entries on the surrounding scope (spec.extensions,operation.extensions,schema.extensions, β¦).infoExtensions:is meta-only; entries land oninfo.extensions.
Aliases: info extensions, info-extensions (for infoExtensions).
tos
Terms-of-service prose paragraph. Multi-line body is joined with
\n after dropping whitespace-only lines. Aliases:
terms of service, terms-of-service, termsOfService. Maps to
info.termsOfService. Meta-only.
externalDocs
External documentation pointer as a YAML map with description and
url keys. Aliases: external docs, external-docs. Multi-context
(meta, route, operation, schema).
Cross-keyword interactions
A handful of keyword interactions are worth flagging:
default+example+enumon the same field: all three may co-occur. The values are coerced against the resolved schema type independently. Ifenumis declared anddefaultis not a member of it, no diagnostic fires today β downstream JSON Schema validation catches it.type+ numeric validations +formaton a body parameter: the schema dispatcher’scheckShapegates numeric / length validations against the resolved type.formatis type-blind (any format string lands).requiredon a$ref'dfield: writes to the enclosing schema’srequiredarray (the standard JSON-Schema-draft-4 shape). If the field has sibling overrides, the$refrewrites into anallOfcompound β see grammar.md Β§refoverride.