Oak-Digital / types-4-strapi-2

Automate the creation of typescript interfaces for your strapi 4 projects
MIT License
24 stars 4 forks source link

TS key should be optional when the field in strapi is not a required field #12

Closed HenryC-3 closed 1 year ago

HenryC-3 commented 1 year ago

Description

Current t4s-2 generates required keys while required field option is not checked in strapi.

image

Expected output

{
  "kind": "collectionType",
  "collectionName": "articles",
  "info": {
    "singularName": "article",
    "pluralName": "articles",
    "displayName": "Article",
    "description": ""
  },
  "options": {
    "draftAndPublish": true
  },
  "pluginOptions": {},
  "attributes": {
    "title": {
      "type": "string"
    },
    "content": {
      "type": "richtext"
    },
    "author": {
      "type": "string"
    }
  }
}
HenryC-3 commented 1 year ago

And I notice that the interfaces name generated from user defined content type always starts with letter I, is this designed on purpose?

Alexnortung commented 1 year ago

And I notice that the interfaces name generated from user defined content type always starts with letter I, is this designed on purpose?

This is just a default and can be changed to your liking. It is also a goal of this project to be very configurable. You can change it with the --prefix option.


As for the original question: Strapi still sends the field, so it should not be undefined, but you are right, it should be nullable.

However there is another problem, if a content type is updated from not required to required, the interface would now say that it could not be nullable, however it can still be the case that the user hasn't updated the content and it can still be null. I think there should be a "paranoid" option as well.

Alexnortung commented 1 year ago

This should now work in version 0.3.1