openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

[BUG] Typescript-axios not setting correct Content-Type on HTTP PUT

Open TheGeekPharaoh opened this issue 2 years ago • 0 comments

Bug Report Checklist

  • [X] Have you provided a full/minimal spec to reproduce the issue?
  • [X] Have you validated the input using an OpenAPI validator (example)?
  • [ ] Have you tested with the latest master to confirm the issue still exists?
  • [X] Have you searched for related issues/PRs?
  • [X] What's the actual output vs expected output?
Description

The client code generated by the typescript-axios generator does not seem to honor the Content-Type of application/json that is listed in my OpenAPI spec document.

openapi-generator version

openapi-generator 6.2.0, typescript-axios generator

OpenAPI declaration file content or url

The relevant portion of my OpenAPI spec, showing the request body Content-Type being specified:

			"put": {
				"requestBody": {
					"content": {
						"application/json": {
							"schema": {
								"$ref": "#/components/schemas/CreateRecordRequest"
							}
						}
					},
					"required": true
				},

Generation Details

openapi-generator generate -i Developer/openapi.json -g typescript-axios -o ~/Developer/openapi-client

Steps to reproduce

I am calling the generated API client without any modifications. I do see generated code that looks like it applies the correct Content-Type header:

            localVarHeaderParameter['Content-Type'] = 'application/json';

            setSearchParams(localVarUrlObj, localVarQueryParameter);
            let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
            localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
            localVarRequestOptions.data = serializeDataIfNeeded(createQuestionRequest, localVarRequestOptions, configuration)

However, this is NOT reflected in the actual call to the server.

Related issues/PRs

Unknown

Suggest a fix

Unknown

TheGeekPharaoh avatar Oct 17 '22 20:10 TheGeekPharaoh