-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Description
Summary
The runtime library now supports proper base64 encoding/decoding for []byte parameters (OpenAPI type: string, format: byte) via a new TypeHint mechanism. The code generator needs to be updated to use these new WithOptions functions so that []byte fields are correctly handled at runtime.
Background
When a spec defines type: string, format: byte, oapi-codegen generates a *[]byte field. The runtime currently treats []byte as a generic []uint8 slice — splitting on commas and parsing individual integers — instead of base64-encoding/decoding it.
This was reported as oapi-codegen/runtime#97 and fixed in oapi-codegen/runtime#98, which adds:
TypeHint/TypeHintBinaryconstantsBindStringToObjectWithOptions(withBindStringToObjectOptions{TypeHint: TypeHintBinary})StyleParamWithOptions(withStyleParamOptions{TypeHint: TypeHintBinary})BindQueryParameterWithOptions(withBindQueryParameterOptions{TypeHint: TypeHintBinary})BindStyledParameterOptions.TypeHintfield
Existing functions delegate to the new variants with zero-value options, so there is no behavior change until the generator emits the new calls.
What needs to change in the generator
For any parameter or field with format: byte (Go type []byte), generated code should call the WithOptions variants with TypeHintBinary instead of the current functions. Specifically:
- Styled parameter binding — pass
TypeHint: runtime.TypeHintBinaryinBindStyledParameterOptions - Query parameter binding — call
runtime.BindQueryParameterWithOptions(...)withBindQueryParameterOptions{TypeHint: runtime.TypeHintBinary}instead ofruntime.BindQueryParameter(...) - Style parameter serialization — call
runtime.StyleParamWithOptions(...)withStyleParamOptions{TypeHint: runtime.TypeHintBinary}instead ofruntime.StyleParamWithLocation(...)
Blocked on
A new release of github.com/oapi-codegen/runtime containing the changes from oapi-codegen/runtime#98.