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 / TypeHintBinary constants
- BindStringToObjectWithOptions (with BindStringToObjectOptions{TypeHint: TypeHintBinary})
- StyleParamWithOptions (with StyleParamOptions{TypeHint: TypeHintBinary})
- BindQueryParameterWithOptions (with BindQueryParameterOptions{TypeHint: TypeHintBinary})
- BindStyledParameterOptions.TypeHint field
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.TypeHintBinary in BindStyledParameterOptions
- Query parameter binding — call runtime.BindQueryParameterWithOptions(...) with BindQueryParameterOptions{TypeHint: runtime.TypeHintBinary} instead of runtime.BindQueryParameter(...)
- Style parameter serialization — call runtime.StyleParamWithOptions(...) with StyleParamOptions{TypeHint: runtime.TypeHintBinary} instead of runtime.StyleParamWithLocation(...)
Blocked on
A new release of github.com/oapi-codegen/runtime containing the changes from oapi-codegen/runtime#98.
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:
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:
Blocked on
A new release of github.com/oapi-codegen/runtime containing the changes from oapi-codegen/runtime#98.