Skip to content

Overriding formDataBodySerializer via config #2742

@Marsunpaisti

Description

@Marsunpaisti

Description

Context why I have a problem in the first place:
I have a .NET backend that expects objects in form data to be in flattened dot notation such that the following applies:

{
  "primitiveKey": "fizzbuzz",
  "objectKey" : {
      "nestedKey1": "nestedValue1",
      "nestedKey2": "nestedValue2"
  }
}

// How it's currently added to form data:
primitiveKey = "fizzbuzz"
objectKey = "{\"nestedKey1\": \"nestedValue1\", \"nestedKey2\": \"nestedValue2\" }"

// How .NET expects it to be
primitiveKey = "fizzbuzz"
objectKey.nestedKey1 = "nestedValue1"
objectKey.nestedKey2 = "nestedValue2"

I need to override the default behavior of the form data body serializer but I can't find any way to accomplish this in the documentation. I can see that the client has a bodySerializer config, but I'm using the Tanstack Query plugin and it seems to directly pass a reference to the default generated body serializer in the generated mutations like below, so the bodySerializer of the client is not applied here:

/**
 * Upload documents
 */
export const uploadDocuments = <ThrowOnError extends boolean = false>(
	options: Options<UploadDocumentsData, ThrowOnError>
) => {
	return (options.client ?? client).post<UploadDocumentsResponses, unknown, ThrowOnError>({
		...formDataBodySerializer,
		responseTransformer: uploadDocumentsResponseTransformer,
		url: '/projects/{projectId}/documents',
		...options,
		headers: {
			'Content-Type': null,
			...options.headers
		}
	})
}

Is there any way to either configure it to override a specific serializer or to have it generate the flat form data format?

For now I did a dirty hack by just making script that replaces the import in the generated code with a serializer of my own, but it does feel like a hacky patch for something that seems like it would / should be configurable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions