commercetools / commercetools-sdk-typescript

The e-commerce SDK from commercetools for JavaScript written in TypeScript.
https://commercetools.github.io/commercetools-sdk-typescript/
MIT License
45 stars 25 forks source link

Incorrect type definition for ProductSelectionPagedQueryResponse #186

Closed andrei-ivanov closed 2 years ago

andrei-ivanov commented 2 years ago

Using @commercetools/platform-sdk@2.3.0, I'm fetching the productSelections for a product: const response = await requestBuilder().products().withKey({key: productKey}).productSelections().get().execute();

AFAIS, response has a type of ClientResponse<ProductSelectionPagedQueryResponse> response.body is a ProductSelectionPagedQueryResponse response.body.results is a ProductSelection[]

The problem I see is that the values contained in the array don't seem to match the properties defined in ProductSelection:

response.body.results = [{
    "productSelection": {
        "typeId": "product-selection",
        "id": "2e89d89b-bdfb-4339-8e53-7638966a97c2"
    },
    "createdAt": "2022-02-02T09:15:35.001Z"
}]

Since response.body.results[0] should be a ProductSelection, there should be a response.body.results[0].id property and all the others properties defined in ProductSelection. Instead it seems some properties were placed in that response.body.results[0].productSelection wrapper.

I think the same issue is reproducible for the Java SDK 7.6.0 too:

List<ProductSelection> productSelections = projectApiRoot.products().withKey(productKey).productSelections().get().executeBlocking().getBody().getResults();
INFO  --- [                     main] com.loylogic.experimental.commercetools.ProductSelectionsService : listing selections for product iphone-13
DEBUG --- [ForkJoinPool.commonPool-worker-1]                       commercetools.products.request.queries : io.vrap.rmf.base.client.ApiHttpRequest@7fe3477b[method=GET,uri="https://api.europe-west1.gcp.commercetools.com/loylogic-poc/products/key=iphone-13/product-selections",headers=[{key=Accept-Encoding, value=gzip}, {key=Authorization, value=**removed from output**}, {key=User-Agent, value=commercetools-sdk-java-v2/7.6.0  Java/17.0.2+8-LTS (Windows 10; amd64)}],textInterpretedBody=empty body]
TRACE --- [ForkJoinPool.commonPool-worker-1]                       commercetools.products.request.queries : GET https://api.europe-west1.gcp.commercetools.com/loylogic-poc/products/key=iphone-13/product-selections <no body>
INFO  --- [    httpclient-dispatch-2]                              commercetools.products.response : GET https://api.europe-west1.gcp.commercetools.com/loylogic-poc/products/key=iphone-13/product-selections 200
DEBUG --- [    httpclient-dispatch-2]                              commercetools.products.response : io.vrap.rmf.base.client.ApiHttpResponse@5eff0dc7[statusCode=200,headers=[{key=date, value=Wed, 02 Feb 2022 10:39:20 GMT}, {key=server, value=istio-envoy}, {key=x-envoy-upstream-service-time, value=75}, {key=content-encoding, value=gzip}, {key=access-control-allow-headers, value=Accept, Authorization, Content-Type, Origin, User-Agent, X-Correlation-ID}, {key=x-correlation-id, value=projects-ba85f082-58ce-40c4-ba75-6f927b03ac81}, {key=access-control-allow-methods, value=GET, POST, DELETE, OPTIONS}, {key=via, value=1.1 google}, {key=access-control-expose-headers, value=X-Correlation-ID}, {key=access-control-allow-origin, value=*}, {key=access-control-max-age, value=299}, {key=content-type, value=application/json; charset=utf-8}, {key=server-timing, value=projects;dur=7}, {key=alt-svc, value=clear}],textInterpretedBody={"limit":20,"offset":0,"count":1,"results":[{"productSelection":{"typeId":"product-selection","id":"2e89d89b-bdfb-4339-8e53-7638966a97c2"},"createdAt":"2022-02-02T09:15:35.001Z"}]}]
TRACE --- [    httpclient-dispatch-2]                              commercetools.products.response : 200
{
  "limit" : 20,
  "offset" : 0,
  "count" : 1,
  "results" : [ {
    "productSelection" : {
      "typeId" : "product-selection",
      "id" : "2e89d89b-bdfb-4339-8e53-7638966a97c2"
    },
    "createdAt" : "2022-02-02T09:15:35.001Z"
  } ]
}
INFO  --- [                     main] com.loylogic.experimental.commercetools.ProductSelectionsService : results: 1
INFO  --- [                     main] com.loylogic.experimental.commercetools.ProductSelectionsService : ProductSelectionImpl[createdAt=2022-02-02T09:15:35.001Z,createdBy=<null>,id=<null>,key=<null>,lastModifiedAt=<null>,lastModifiedBy=<null>,name=<null>,productCount=<null>,type=<null>,version=<null>]
jenschude commented 2 years ago

Fixed with version 2.4.1

Thanks for the report! 👍

andrei-ivanov commented 2 years ago

It seems to work fine now, thanks :)