mancku / strapi-plugin-schemas-to-ts

Strapi Plugin Schemas to TS is a plugin for Strapi v4 that automatically converts your Strapi schemas into Typescript interfaces.
MIT License
65 stars 20 forks source link

Name conflict with component field #18

Closed matepaiva closed 1 year ago

matepaiva commented 1 year ago

Dependencies

{
  "dependencies": {
    "@strapi/strapi": "4.11.5",
    "strapi-plugin-schemas-to-ts": "^1.1.4",
  },
}

Description

My system have a collection type called "Material" and also a component called "Material". One possible fix is to add a suffix to the components field, so it would be "MaterialComponent".

This:

// Interface automatically generated by schemas-to-ts

import { Material_Plain } from "../../../api/material/content-types/material/material";

export interface Material {
  value: number;
  material?: { data: Material };
}
export interface Material_Plain { // ERROR NAME CONFLICT
  value: number;
  material?: Material_Plain;
}

export interface Material_NoRelations {
  value: number;
  material?: number;
}

Would become this:

// Interface automatically generated by schemas-to-ts

import { Material_Plain } from "../../../api/material/content-types/material/material";

export interface Material {
  value: number;
  material?: { data: Material };
}
export interface Material_Plain_Component {
  value: number;
  material?: Material_Plain;
}

export interface Material_NoRelations {
  value: number;
  material?: number;
}
matepaiva commented 1 year ago

Also this caused a problem with the project collection type, which uses the material component. But, instead of adding the material component import, it imported the material collection type.

So this:

export interface Project_Plain {
  id: number;
  materials: Material_Plain[];
}

should be this:

export interface Project_Plain {
  id: number;
  materials: Material_Plain_Component[]; // also changing the import, of course
}
mancku commented 1 year ago

@matepaiva I just pushed the version 1.1.7 to npm with this fix, also adding in https://github.com/mancku/strapi-plugin-schemas-to-ts/commit/bb858179e17317e00f5f826a2ae72226e3b6d29b the posibility to configure the plugin to always add the 'Component' suffix