Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request Payload with empty string values ignores all values and send empty object payload #1129

Closed
rners01 opened this issue Mar 28, 2024 · 5 comments

Comments

@rners01
Copy link

rners01 commented Mar 28, 2024

Hi,
I'd encountered the issue with empty payload request using kiota generated API client.
Client ignores payload with empty string or undefined values, eg. property: "" or property: undefined.
Before the request was made I console.log my payload and those values were present.

Im thinking potentially the problem could be with the serializer..

My setup:

export function createApiClient(requestAdapter: RequestAdapter) {
    registerDefaultSerializer(JsonSerializationWriterFactory);
    registerDefaultDeserializer(JsonParseNodeFactory);
    if (requestAdapter.baseUrl === undefined || requestAdapter.baseUrl === "") {
        requestAdapter.baseUrl = "https://myrestapi.com";
    }
    const pathParameters: Record<string, unknown> = {
        "baseurl": requestAdapter.baseUrl,
    };
    return apiClientProxifier<ApiClient>(requestAdapter, pathParameters, ApiClientNavigationMetadata, undefined);
}

// and then...

createApiClient(
    new FetchRequestAdapter(
      new BaseBearerTokenAuthenticationProvider({
        getAuthorizationToken() {
          const token = sessionStorage.getItem(TOKEN_KEY)

          return Promise.resolve(token)
        },
        getAllowedHostsValidator: () => new AllowedHostsValidator(new Set([apiUrl])),
      }),
      undefined,
      new JsonSerializationWriterFactory(),
      KiotaClientFactory.create(window.fetch.bind(window)),
      undefined,
    ),
  )

I'm using:

    "@microsoft/kiota-abstractions": "1.0.0-preview.45",
    "@microsoft/kiota-http-fetchlibrary": "1.0.0-preview.44",
    "@microsoft/kiota-serialization-json": "1.0.0-preview.45",
@andrueastman
Copy link
Member

Possibly related to #1120 cc @koros

@koros
Copy link
Contributor

koros commented Apr 3, 2024

Hi @rners01,

Thanks for raising the issue. I would like to seek more clarification; at the moment the serialization step intentionally skips all undefined fields see: #1079,
e.g

const Item = {
    id: "123"
    name: "Foo",
    serverId: undefined
}

In the example above since the serverId is undefined, its omitted, after serialization the payload becomes:

{
    "id": "123",
    "name": "Foo"
}

Please confirm whether this is what you are seeing on your end and whether it addresses your issue

@rners01
Copy link
Author

rners01 commented Apr 23, 2024

@koros Not really, it skips "" empty string values in my case too

@baywet baywet reopened this Apr 23, 2024
@github-project-automation github-project-automation bot moved this from Done ✔️ to In Progress 🚧 in Kiota Apr 23, 2024
@baywet
Copy link
Member

baywet commented Apr 23, 2024

@rners01 thanks for the additional information.
Any chance you could try with the latest version of the kiota dependencies published today? @koros implemented fixes for that specific scenario already.

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

No branches or pull requests

4 participants