v0.9.0
Added
-
Array parameters and slice fields can document their elements. A
repeated query filter —?severity=high&severity=low— now carries a
machine-readable element enum instead of an opaqueitems: {type}:stdocs.QueryParam("severity", "array", "Repeated severity filter", stdocs.ParamItems("string", stdocs.ItemEnum("info", "low", "high")))
A new
ItemOptfamily —ItemEnum,ItemFormat,ItemPattern,
ItemMinLength,ItemMaxLength,ItemMinimum,ItemMaximum,
ItemExclusiveMinimum,ItemExclusiveMaximum— nests inside
ParamItems, which owns the element schema. There is deliberately no
ItemDefaultorItemExample: a default or an example is a value for
the parameter, not for one of its elements. -
On a slice or array field the scalar constraint tags now describe the
elements rather than panicking, soSeverity []string \query:"severity" enum:"info,low,high"`emitsitems.enum. This covers request bodies, responses, and webhook payloads as well as parameters, and the two parameter paths produce the same document. OnlyminItems,maxItems, anduniqueItemsdescribe the array, sominLengthon a[]stringmeans "each element is at least that long"; "at least that many elements" isminItems. Elements that cannot carry a constraint (slices of structs, of slices, or of maps) panic and name the elements.tsgenrenders an element enum as a union array (("info" | "low" | "high")[]`).
Changed
ParamItemsnow takes optionalItemOptmodifiers. Existing direct
calls are unaffected; a reference toParamItemsas a function
value is not, as withWithUIin v0.7.0.ParamFormatnow rejects an array parameter: an array has no format
of its own, and its elements' format comes fromItemFormat. This
aligns the modifier with theformat:tag, which describes the
elements.- Declaring
ParamItemstwice on one parameter panics when the first
call carried element options — the second call replaces the element
schema and would silently discard them. Re-declaring the element type
alone stays the no-op it has always been. default:andexample:on a slice or array field now explain why
they are rejected (a lone value cannot say whether it is the whole
array or one element), andParamEnumon an array parameter points at
ParamItems/ItemEnum.enum,format, and the bounds on a[N]bytefield now apply to its
integer elements instead of panicking. A byte array is an array of
numbers on the wire; to document one as a string, use
openapi:"type=string,format=uuid".
Fixed
Lintnow inspects array element schemas, so theexclusive-bounds
advisory sees an exclusive bound on a slice field's elements. It was
blind to them, which would have let the generator-hostile numeric
3.1/3.2 form ship unreported.- A
WithParamsstruct field whose elements have no JSON representation
(a slice of functions or channels) is rejected as a parameter instead
of being accepted with an empty element schema.