Skip to content

v1.27.0

Latest

Choose a tag to compare

@ernado ernado released this 02 Dec 13:52
· 5 commits to main since this release
5953d4d

Breaking changes

Regenerating code with this release may require changes in code that uses it.

  • Convenient errors for decode errors (#1825, fixes #1514). When convenient errors are enabled, *ogenerrors.DecodeParamsError and *ogenerrors.DecodeRequestError are passed to Handler.NewError and encoded as the error response, the same way security errors are. Previously they always went to ServerConfig.ErrorHandler. Implementations that return a fixed 500 for every error should check for these types to keep a 400 response:
    func (h *handler) NewError(ctx context.Context, err error) *api.ErrorStatusCode {
    	var (
    		paramsErr  *ogenerrors.DecodeParamsError
    		requestErr *ogenerrors.DecodeRequestError
    	)
    	if errors.As(err, &paramsErr) || errors.As(err, &requestErr) {
    		return &api.ErrorStatusCode{StatusCode: http.StatusBadRequest /* ... */}
    	}
    	// ...
    }
    Webhooks and servers without convenient errors are unchanged.
  • Length of JSON byte strings (#1816, fixes #1504 and #1570). pattern, minLength and maxLength of format: byte and format: base64 strings in JSON are checked against the base64 string, as the spec says, not against decoded bytes. Specs that used maxLength as a limit on decoded bytes become stricter. Parameters and form fields are validated as before.
  • YAML 1.2 raw values (#1820, fixes #1317). enum, default, example, const and extension values follow YAML 1.2, like the rest of the spec: only true and false are booleans, so enum: [ON, OFF] is a string enum now. A spec that relied on YAML 1.1 booleans, like default: yes for a boolean schema, fails with a type mismatch.
  • MarshalJSON of unset optional values (#1828, fixes #660). json.Marshal of an unset Opt* or OptNil* value returns null instead of failing with unexpected end of JSON input, and UnmarshalJSON of Opt* decodes null as unset. Only the encoding/json methods change; the generated client and server still reject null for non-nullable fields.

Features

  • Numeric exclusiveMinimum and exclusiveMaximum from OpenAPI 3.1 (JSON Schema 2020-12) are supported (#1821, fixes #1366). Both numeric and boolean forms are accepted regardless of the spec version.

Fixes

  • Complex uniqueItems (#1833): Equal and Hash code is generated recursively, so maps of structs or slices, optional arrays, arrays of aliases, sums, maps, arrays and untyped items are supported. The code is written to oas_equal_gen.go instead of a pair of files per type. --clean doesn't remove the old api_validators_unique_gen.go, delete it manually.
  • Inlined schemas no longer conflict with component schemas of the same name, and enum constants no longer conflict with type names (#1832). With #1833, the Mist spec from #1507 generates and compiles.
  • uniqueItems is ignored for non-array types (#1819, fixes #1507).
  • Sum selector type <Sum>Type no longer conflicts with a schema of the same name (#1826, fixes #990).
  • null variants of sum types are supported in parameters (#1827), e.g. anyOf: [integer, string, null] from FastAPI specs.
  • Optional nullable recursive fields reference a defined type (#1822, fixes #1488), and optional types of recursive structs no longer conflict (#1830).
  • Sums of several object sums are not discriminated by JSON type (#1818, fixes #1480).
  • Properties with format but without type compile (#1817, fixes #1471).
  • Forms with additionalProperties, patternProperties or oneOf/anyOf inline fields no longer panic (#1815).

Dependencies

  • github.com/dlclark/regexp2/v2 2.13.3.

Full Changelog: v1.26.0...v1.27.0