You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
codegen: emit TypeHintBinary for format: byte parameters #2248
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.
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.
Update: The runtime PR (#98 in oapi-codegen/runtime) has been updated. The API now uses Type and Format string fields (matching the OpenAPI spec's own type/format strings) instead of the earlier TypeHint enum approach. This is more extensible and lets the runtime make spec-informed decisions.
The new options structs accept:
Type string — the OpenAPI type (e.g. "string", "integer")
Format string — the OpenAPI format (e.g. "byte", "date-time")
When Format == "byte" and the destination is []byte, the runtime base64-encodes/decodes the value. The code generator should populate these fields from the spec when calling the WithOptions variants.
Activity
mromaszewicz commentedon Feb 25, 2026
Update: The runtime PR (#98 in oapi-codegen/runtime) has been updated. The API now uses
TypeandFormatstring fields (matching the OpenAPI spec's own type/format strings) instead of the earlierTypeHintenum approach. This is more extensible and lets the runtime make spec-informed decisions.The new options structs accept:
Type string— the OpenAPI type (e.g."string","integer")Format string— the OpenAPI format (e.g."byte","date-time")When
Format == "byte"and the destination is[]byte, the runtime base64-encodes/decodes the value. The code generator should populate these fields from the spec when calling theWithOptionsvariants.fix: pass OpenAPI type/format to runtime parameter binding and stylin…
fix: pass OpenAPI type/format to runtime parameter binding and stylin…