📖 2 min read (~ 400 words).

swagger:patternProperties

Usage

// swagger:patternProperties "<regex>": <type> [ , "<regex>": <type> … ]

What it does

Adds typed patternProperties entries — each maps a property-name regex to a value schema.

It is the typed counterpart of the regex-only patternProperties: keyword (which uses an empty, any-value schema).

Note

patternProperties is a JSON-Schema (draft-4) keyword, beyond the Swagger 2.0 subset. codescan emits it ungated — your downstream tooling must understand it.

Where it goes

On a type declaration (alongside swagger:model).

Grammar (EBNF)

PatternPropertiesAnnotation = ANN_PATTERN_PROPERTIES , PatternPair , { "," , PatternPair } ;
PatternPair                 = STRING_VALUE , ":" , ValueType ;
ValueType                   = TYPE_REF | IDENT_NAME | "[]" , ValueType ;

A comma-separated list of "<regex>": <spec> pairs. The regex (STRING_VALUE) is double-quoted — it may contain spaces, colons, commas; only \" is an escape inside it, other backslashes like \d are preserved. Each <spec> reuses the /codescan/maintainers/annotations/swagger-type/ value grammar (primitive / []T / type-name → $ref).

Supported keywords

None of its own. It composes with maxProperties / minProperties / additionalProperties.

Example

Annotated Go
// TypedPatterns maps property-name regexes to typed value schemas. Each quoted
// regex pairs with a value spec — a primitive or a model name (which becomes a
// $ref). The pattern-properties keyword is JSON-Schema, beyond the Swagger 2.0
// subset; codescan emits it ungated.
//
// swagger:model
// swagger:patternProperties "^x-": string, "^\d+$": integer, "^item-": Thing
type TypedPatterns struct {
	Known string `json:"known"`
}

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

Generated spec
{
  "description": "TypedPatterns maps property-name regexes to typed value schemas. Each quoted\nregex pairs with a value spec — a primitive or a model name (which becomes a\n$ref). The pattern-properties keyword is JSON-Schema, beyond the Swagger 2.0\nsubset; codescan emits it ungated.",
  "type": "object",
  "properties": {
    "known": {
      "type": "string",
      "x-go-name": "Known"
    }
  },
  "patternProperties": {
    "^\\d+$": {
      "type": "integer"
    },
    "^item-": {
      "$ref": "#/definitions/Thing"
    },
    "^x-": {
      "type": "string"
    }
  },
  "x-go-package": "github.com/go-openapi/codescan/docs/examples/concepts/maps"
}

Full source: docs/examples/concepts/maps/testdata/patterntyped.json

Precedence. Same lowest-priority, object-only rule as swagger:additionalProperties. Each regex is RE2-hygiene-checked: one that does not compile raises a CodeInvalidAnnotation warning but is preserved; a structurally malformed pair list is dropped with a diagnostic.

Full example. fixtures/enhancements/pattern-properties-typed/api.go.