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

Empty Object in Request Payload #3596

Closed
illunix opened this issue Oct 29, 2023 · 19 comments · Fixed by #3597
Closed

Empty Object in Request Payload #3596

illunix opened this issue Oct 29, 2023 · 19 comments · Fixed by #3597
Assignees
Labels
type:bug A broken experience TypeScript Pull requests that update Javascript code WIP
Milestone

Comments

@illunix
Copy link

illunix commented Oct 29, 2023

I am encountering a peculiar issue in the latest release and pre-release versions of the TypeScript Client Generator, where my object appears empty in the request payload. Before sending the request, I log the object to the console using console.log to ensure it's populated correctly. This process worked as expected in version v1.4.0. However, post-upgrade, the object in the request payload is showing as empty, despite the console log indicating otherwise. I am seeking assistance or insights to resolve this issue.

@github-project-automation github-project-automation bot moved this to Todo in Kiota Oct 29, 2023
@illunix illunix changed the title Empty Object in Request Payload in Latest and Pre-release Versions Empty Object in Request Payload Oct 29, 2023
@baywet baywet self-assigned this Oct 30, 2023
@baywet baywet added question TypeScript Pull requests that update Javascript code labels Oct 30, 2023
@baywet baywet added this to the Backlog milestone Oct 30, 2023
@baywet
Copy link
Member

baywet commented Oct 30, 2023

Hi @illunix,
Thanks for using kiota and for reporting this.
For "latest pre-release" do you mean v1.8.0-preview.202310260001 or v1.7.0?
What are the versions of the kiota packages installed in your project?

@illunix
Copy link
Author

illunix commented Oct 30, 2023

@baywet

   "@microsoft/kiota-abstractions": "^1.0.0-preview.28",
   "@microsoft/kiota-authentication-azure": "^1.0.0-preview.24",
   "@microsoft/kiota-http-fetchlibrary": "^1.0.0-preview.27",
   "@microsoft/kiota-serialization-form": "^1.0.0-preview.15",
   "@microsoft/kiota-serialization-json": "^1.0.0-preview.27",
   "@microsoft/kiota-serialization-multipart": "^1.0.0-preview.8",
   "@microsoft/kiota-serialization-text": "^1.0.0-preview.23",

@baywet
Copy link
Member

baywet commented Oct 30, 2023

For "latest pre-release" do you mean v1.8.0-preview.202310260001 or v1.7.0?

@illunix
Copy link
Author

illunix commented Oct 30, 2023

Pre release that I used v1.8.0-preview.202310260001 and
Release v1.7.0

For both versions I used same packages

@baywet

@baywet
Copy link
Member

baywet commented Oct 30, 2023

When you generate, do you enable the backing store? (-b or --backing-store)
Could you share a snippet of the code making the request?
Could you share the section of the API description for the request?

@illunix
Copy link
Author

illunix commented Oct 30, 2023

The offer object is empty in request body but in console log it's okey @baywet
Weird thing is that, priceId and baseSuccessUrl is successfully mapped

const cmd: GetCheckoutUrlCommand = {
      priceId: this.planId,
      offer: this.offer,
      baseSuccessUrl: `${window.location.origin}/offer-published`
    }

console.log(cmd)

this._testProjApi.checkout.url
      .post(cmd)
      .then(q => window.location.href = q?.url ?? '')
      .catch(() => this.isLoading.update(() => false));
"/checkout/url": {
      "post": {
        "tags": [
          "Checkout"
        ],
        "operationId": "Get checkout url",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TestProj.Core.Commands.Commerce.GetCheckoutUrlCommand"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TestProj.Core.DTOs.Commerce.CheckoutUrlDto"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request"
          },
          "422": {
            "description": "Client Error",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Microsoft.AspNetCore.Http.HttpValidationProblemDetails"
                }
              }
            }
          }
        }
      }
    },
"TestProj.Core.Commands.Commerce.GetCheckoutUrlCommand": {
        "type": "object",
        "properties": {
          "priceId": {
            "type": "string",
            "nullable": true
          },
          "offer": {
            "$ref": "#/components/schemas/TestProj.Core.DTOs.Commerce.OfferDto"
          },
          "baseSuccessUrl": {
            "type": "string",
            "nullable": true
          }
        },
        "additionalProperties": false
      },

@baywet
Copy link
Member

baywet commented Oct 30, 2023

When you generate, do you enable the backing store? (-b or --backing-store)

Can you share how the offer is created?

@illunix
Copy link
Author

illunix commented Oct 30, 2023

What this parameter do? I don't use that @baywet

@baywet
Copy link
Member

baywet commented Oct 30, 2023

It allows you to do dirty tracking for scenarios where you:

  1. get an object from the API
  2. update a property on the object
  3. send the object back to the API (patch/put)

In that scenario, the backing store only sends the changed property, not the whole object representation. Since this is something we've recently revamped in the last preview, I was wondering whether it could be the source of the issue.

Can you share a code snippet of how the offer is created?

@illunix
Copy link
Author

illunix commented Oct 30, 2023

You mean the generated code? Or what you mean by where offer is created

@illunix
Copy link
Author

illunix commented Oct 30, 2023

Also when I add -b parameter I get errors about Property 'backingStore' is missing in type on every interface

@illunix
Copy link
Author

illunix commented Oct 30, 2023

export function serializeGetCheckoutUrlCommand(writer: SerializationWriter, getCheckoutUrlCommand: GetCheckoutUrlCommand | undefined = {} as GetCheckoutUrlCommand) : void {
        writer.writeStringValue("baseSuccessUrl", getCheckoutUrlCommand.baseSuccessUrl);
        writer.writeObjectValue<OfferDto>("offer", getCheckoutUrlCommand.offer, );
        writer.writeStringValue("priceId", getCheckoutUrlCommand.priceId);
}

@baywet
Copy link
Member

baywet commented Oct 30, 2023

I meant the part of your code that built the offer property here

const cmd: GetCheckoutUrlCommand = {
      priceId: this.planId,
      offer: this.offer,
      baseSuccessUrl: `${window.location.origin}/offer-published`
    }

Also when I add -b parameter I get errors about Property 'backingStore' is missing in type on every interface

This is probably because the dependencies are misaligned, we're still working on that. But As you're not passing that argument, disregard it for now.

@illunix
Copy link
Author

illunix commented Oct 30, 2023

this.offer comes from input property that is OfferDto type, nothing special
@baywet

@baywet
Copy link
Member

baywet commented Oct 30, 2023

in this generated code

export function serializeGetCheckoutUrlCommand(writer: SerializationWriter, getCheckoutUrlCommand: GetCheckoutUrlCommand | undefined = {} as GetCheckoutUrlCommand) : void {
        writer.writeStringValue("baseSuccessUrl", getCheckoutUrlCommand.baseSuccessUrl);
        writer.writeObjectValue<OfferDto>("offer", getCheckoutUrlCommand.offer, );
        writer.writeStringValue("priceId", getCheckoutUrlCommand.priceId);
}

This line writer.writeObjectValue<OfferDto>("offer", getCheckoutUrlCommand.offer, ); is incorrect, and should be instead be something like writer.writeObjectValue<OfferDto>("offer", getCheckoutUrlCommand.offer, serializeOfferDto);

Looking at our own repositories, this looks like a bug that was inserted recently.

@baywet baywet added type:bug A broken experience and removed question Needs: Attention 👋 labels Oct 30, 2023
@baywet baywet modified the milestones: Backlog, Kiota v1.8 Oct 30, 2023
@baywet baywet moved this from Todo to In Progress in Kiota Oct 30, 2023
@baywet
Copy link
Member

baywet commented Oct 30, 2023

just submitted #3597 to address this issue.

@github-project-automation github-project-automation bot moved this from In Progress to Done in Kiota Oct 31, 2023
@rners01
Copy link

rners01 commented Mar 27, 2024

Hi, @baywet
I'd encountered the same issue with kiota generated API client.
It ignores payload with empty string or undefined values, eg. property: "" or property: undefined.
Before the request made I console.log my payload and those values are present.


    "@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",

@baywet
Copy link
Member

baywet commented Mar 27, 2024

@rners01 Can you submit a new issue at https://github.com/microsoft/kiota-typescript for that please?

@rners01
Copy link

rners01 commented Mar 29, 2024

@baywet created - microsoft/kiota-typescript#1129

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug A broken experience TypeScript Pull requests that update Javascript code WIP
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants