strapi-community / strapi-plugin-transformer

A plugin for Strapi Headless CMS that provides the ability to transform the API request or response.
https://market.strapi.io/plugins/strapi-plugin-transformer
MIT License
140 stars 22 forks source link

[BUG] repeatable component with nested component that contains a relation is not transformed #99

Open yarkovaleksei opened 10 months ago

yarkovaleksei commented 10 months ago
transformer: {
  enabled: true,
  config: {
    responseTransforms: {
      removeAttributesKey: true,
      removeDataKey: true,
    },
    requestTransforms : {
      wrapBodyWithDataKey: true,
    },
  },
}

image

image

Relation type "oneToOne".

Response example:

{
  "size": [ // Component "size"
    {
      "id": 1,
      "length": 90,
      "width": 60,
      "height": 5,
      "price": 15000,
      "stand": { // Nested component "size.stand"
        "id": 1,
        "additionalProducts": { // Relation field (oneToOne)
          "data": { // not deleted
            "id": 3,
            "attributes": { // not deleted
              "title": "Тумба 70x20x20",
              "description": "Описание тумбы 70x20x20",
              "price": 2000,
              "createdAt": "2024-01-06T11:30:46.980Z",
              "updatedAt": "2024-01-06T11:30:49.477Z",
              "publishedAt": "2024-01-06T11:30:49.384Z",
              "locale": "ru"
            }
          }
        }
      }
    }
  ]
}
ComfortablyCoding commented 10 months ago

I cannot reproduce this issue on the latest strapi version with the provided information. The data is transformed correctly with the data and attributes keys removed.

Can you provide the full schema files for all related content types/components? This should make it easier to reproduce.

yarkovaleksei commented 10 months ago
// src/api/memorial/content-types/memorial/schema.json
{
  "kind": "collectionType",
  "collectionName": "memorials",
  "info": {
    "singularName": "memorial",
    "pluralName": "memorials",
    "displayName": "Memorials",
    "description": ""
  },
  "options": {
    "draftAndPublish": true
  },
  "pluginOptions": {},
  "attributes": {
    "title": {
      "type": "string",
      "required": true
    },
    "size": {
      "type": "component",
      "repeatable": true,
      "component": "record.razmer-s-fiksirovannoj-czenoj-3-d", // component with nested component
      "required": true
    }
  }
}
// src/api/additional-product/content-types/additional-product/schema.json
{
  "kind": "collectionType",
  "collectionName": "additional_products",
  "info": {
    "singularName": "additional-product",
    "pluralName": "additional-products",
    "displayName": "Additional products",
    "description": ""
  },
  "options": {
    "draftAndPublish": true
  },
  "pluginOptions": {},
  "attributes": {
    "title": {
      "type": "string",
      "required": true
    }
  }
}
// src/components/record/razmer-s-fiksirovannoj-czenoj-3-d.json
{
  "collectionName": "components_record_razmer_s_fiksirovannoj_czenoj_3_ds",
  "info": {
    "displayName": "Memorial size",
    "description": ""
  },
  "options": {},
  "attributes": {
    "length": {
      "type": "integer",
      "required": true,
      "min": 0
    },
    "width": {
      "type": "integer",
      "required": true,
      "min": 0
    },
    "height": {
      "type": "integer",
      "required": true,
      "min": 0
    },
    "price": {
      "type": "decimal",
      "required": true,
      "min": 0
    },
    "additionalProducts": {
      "type": "component",
      "repeatable": false,
      "component": "memorial.obyazatelnye-dop-tovary", // problem nested component
      "required": true
    }
  }
}
// src/components/memorial/obyazatelnye-dop-tovary.json
{
  "collectionName": "components_memorial_obyazatelnye_dop_tovary",
  "info": {
    "displayName": "Required additional products"
  },
  "options": {},
  "attributes": {
    "stand": {
      "type": "relation",
      "relation": "oneToOne",
      "target": "api::additional-product.additional-product" // Objects from this collection not transformed
    }
  }
}
ComfortablyCoding commented 9 months ago

Thanks for the schema! I was able to reproduce this issue and will look into fixing it.