Override Accept Headers
The OpenAPI specification makes it easy to use the content
directive to specify which endpoints in an API support multiple content types.
In this example, our get-all-users endpoint can return a response encoded either as unstructured text/plain
data or as a structured application/json
document.
When invoking the operation normally, the Speakeasy SDK automatically defaults to the first option in the list, in this case, text/plain
.
For any API operations that specify multiple accept headers in the OpenAPI specification, the Speakeasy SDK provides a mechanism to override the accept header to receive data in the preferred format.
Accept Header Override in Go
In Go, all types from all operations are collected into a global AcceptHeaderEnum
type that can be found in sdk/operations/options.go
.
Invoking the WithAcceptHeaderOverride
function with the appropriate AcceptHeaderEnum
creates the optional parameter to pass to the operation:
Accept Header Override in Python and TypeScript
In Python and TypeScript, each operation with multiple specified accept headers will have an enum created that provides the acceptable options. The name of the enum will be the tag name, followed by the operation name, followed by AcceptEnum
. For the example above, that would be UsersGetAllAcceptEnum
.
Unspecified Accept Headers
While it is strongly recommended to add all accept headers to the OpenAPI spec, in Go, it is possible to override the accept header to an unspecified value.
There is no support for unspecified accept headers in Python or TypeScript.
Last updated on