Skip to content

Generates multipart/form-data requests as submitting application/json content type #17

Description

@antifuchs

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions