fern icon indicating copy to clipboard operation
fern copied to clipboard

[Bug] File upload should be type of `multipart/form-data`

Open himself65 opened this issue 1 year ago • 0 comments

Describe the bug

https://fastapi.tiangolo.com/tutorial/request-files/#file-parameters-with-uploadfile

Current behavior

part of the openapi.json

"/api/data_source/file_upload": {
      "put": {
        "tags": [
          "data_source"
        ],
        "summary": "Upsert Data Source From Files",
        "description": "Upserts a data source.\nUpdates if a data source with the same name and user_id already exists.Otherwise, creates a new data source.",
        "operationId": "upsert_data_source_from_files_api_data_source_file_upload_put",
        "parameters": [
          {
            "required": false,
            "schema": {
              "type": "string",
              "title": "Session"
            },
            "name": "session",
            "in": "cookie"
          }
        ],
        "requestBody": {
          "content": {
            "multipart/form-data": {
              "schema": {
                "$ref": "#/components/schemas/Body_upsert_data_source_from_files_api_data_source_file_upload_put"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "items": {
                    "$ref": "#/components/schemas/DataSource"
                  },
                  "type": "array",
                  "title": "Response Upsert Data Source From Files Api Data Source File Upload Put"
                }
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        },
        "security": [
          {
            "HTTPBearer": []
          }
        ]
      }
    },

Generated by fern api now, you can see the contentType and body is not correct

upsertDataSourceFromFiles(request, requestOptions) {
        return __awaiter(this, void 0, void 0, function* () {
            const _response = yield core.fetcher({
                url: urlJoin(yield core.Supplier.get(this._options.environment), "api/data_source/file_upload"),
                method: "PUT",
                headers: {
                    Authorization: yield this._getAuthorizationHeader(),
                    "X-Fern-Language": "JavaScript",
                },
                contentType: "application/json",
                body: yield serializers.BodyUpsertDataSourceFromFilesApiDataSourceFileUploadPut.jsonOrThrow(request, {
                    unrecognizedObjectKeys: "strip",
                }),
                timeoutMs: (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
                maxRetries: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries,
                withCredentials: true,
            });
            if (_response.ok) {
                return yield serializers.dataSource.upsertDataSourceFromFiles.Response.parseOrThrow(_response.body, {
                    unrecognizedObjectKeys: "passthrough",
                    allowUnrecognizedUnionMembers: true,
                    allowUnrecognizedEnumValues: true,
                    breadcrumbsPrefix: ["response"],
                });
            }
            if (_response.error.reason === "status-code") {
                switch (_response.error.statusCode) {
                    case 422:
                        throw new PlatformApi.UnprocessableEntityError(yield serializers.HttpValidationError.parseOrThrow(_response.error.body, {
                            unrecognizedObjectKeys: "passthrough",
                            allowUnrecognizedUnionMembers: true,
                            allowUnrecognizedEnumValues: true,
                            breadcrumbsPrefix: ["response"],
                        }));
                    default:
                        throw new errors.PlatformApiError({
                            statusCode: _response.error.statusCode,
                            body: _response.error.body,
                        });
                }
            }
            switch (_response.error.reason) {
                case "non-json":
                    throw new errors.PlatformApiError({
                        statusCode: _response.error.statusCode,
                        body: _response.error.rawBody,
                    });
                case "timeout":
                    throw new errors.PlatformApiTimeoutError();
                case "unknown":
                    throw new errors.PlatformApiError({
                        message: _response.error.errorMessage,
                    });
            }
        });
    }

himself65 avatar Jan 04 '24 22:01 himself65