The openapi spec that I want to drive has some routes for uploading files that expect multipart/form-data bodies:
"put": {
"tags": ["Recipe: CRUD", "Recipe: Images and Assets"],
"summary": "Update Recipe Image",
"operationId": "update_recipe_image_api_recipes__slug__image_put",
"security": [{ "OAuth2PasswordBearer": [] }],
"parameters": [
{
"name": "slug",
"in": "path",
"required": true,
"schema": { "type": "string", "title": "Slug" }
},
{
"name": "accept-language",
"in": "header",
"required": false,
"schema": {
"anyOf": [{ "type": "string" }, { "type": "null" }],
"title": "Accept-Language"
}
}
],
"requestBody": {
"required": true,
"content": {
"multipart/form-data": {
"schema": {
"$ref": "#/components/schemas/Body_update_recipe_image_api_recipes__slug__image_put"
}
}
}
},
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": { "$ref": "#/components/schemas/UpdateImageResponse" }
}
}
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": { "$ref": "#/components/schemas/HTTPValidationError" }
}
}
}
}
},
The generated operation method however submits "application/json" data, which does not work:
// UpdateRecipeImageAPIRecipesSlugImagePut - Update Recipe Image
func (c *Client) UpdateRecipeImageAPIRecipesSlugImagePut(ctx context.Context, slug string, body BodyUpdateRecipeImageAPIRecipesSlugImagePut, opts ...UpdateRecipeImageAPIRecipesSlugImagePutParams) (*UpdateImageResponse, error) {
path := "/api/recipes/{slug}/image"
path = pathReplace(path, "slug", slug)
var headers http.Header
if len(opts) > 0 {
params := opts[0]
headers = make(http.Header)
if params.AcceptLanguage != nil {
headers.Set("accept-language", fmt.Sprintf("%v", *params.AcceptLanguage))
}
}
var result UpdateImageResponse
if err := c.do(ctx, "PUT", path, body, &result, "application/json", headers); err != nil {
return nil, parseHTTPValidationErrorError(err)
}
return &result, nil
}
It should submit multipart/form-data, as specified above.
The openapi spec that I want to drive has some routes for uploading files that expect multipart/form-data bodies:
The generated operation method however submits "application/json" data, which does not work:
It should submit multipart/form-data, as specified above.