Why does user permissions plugin not transform the response?

Hi,
I’ve recognized that the user-permissions plugin does not transform the response data which is leading to the very confusing state that the api responses have a different format depending on if I retrieve the data from the user object or another object that relates to the user object.

Is there a specific reason why this is happening? It just creates inconsistency in the data models and confuses the heck out of me.

For example:

2 entities, user and school.
If I fetch a user and populate the school field I get this response:

{ 
  id: 1
  name: "Peter"
  school: {
     id: 1
     name: "Test"
  }
}

But when I fetch a school and populate the user field then I get this response:

{ 
  id: 2
  attributes: {
    name: "Test",
    user: {
      data: {
        id: 1
        attributes: {
          name: "Peter"
        }
      }
    }
  }
}

The annoying thing is that now in my frontend (using Typescript) I have to create different types depending on from where I fetch the data and have to adjust the data so that it always fits to my frontend.

Following.

It is because route (user) you are requesting is from plugin where you dont get data->attributes, and if its “native” route then you have data->attributes structure

Note: I have same situation with my plugin and its annoying that responses dont have same structure.

Yes I am aware of that but I’m asking what is the reasoning behind this decision and is this open to change? Because I’m seriously considering patching this locally so I get consistent responses which is a nightmare to maintain locally.

They did not think of doing it when releasing v4 and they can’t change it since that would be a breaking change. I recomand the Transformer | Strapi Market plugin since that should make everyting 1 format.

1 Like

Any chance of incremental adoption, example to have option in config:

  1. to allow data->attributes,
  2. later to allow without data->attributes
  3. to have default data->attributes

they could technically add an opt in feature to do that but that chance will be realty small. since that will not really change much but it will increase the complexity and the amount of code to maintain

Still I recommend the transform plugin Transformer | Strapi Market
since this will handle it for all endpoints

My idea was to change for plugin api part, not to change native api. That way it would be unified.

I just tried the Transformer plugin but now the data and meta information on the first level is missing in all the user routes :confused:

So I still have different output depending on the route.

Best way to patch this is by adding a middleware dynamically on the route where in you tranform the data manualy.

if you want a better explenation I would recomand joining the discord since it depends on your needs how you would do this.

I tried transform plugin but then the dilema of working on data response moved to custom controllers (or services, I dont remember) in backend. So finally removed transformer and implemented the transform myself in the frontend.