How to override Strapi's core entity-validator?

System Information
  • 3.4.1:
  • MacOS:
  • Mongodb:
  • v12.18.3:
  • 6.14.7:
  • 1.22.10:


Currently I am trying to override the uid field in Strapi content-manager so it accepts are more advanced regex pattern. As far I understood by default it only accepts slugs like i-am-a-slug because graphQL has issues with i-am-a-slug/and-a-nested-one.

As far as the content-builder I got everything working. It checks if the uid is unique and shows a green checkmark if it passes the regex pattern match.

However when I try to create the collection it fails with a ValidationError. The uid field with name slug does not match the regex pattern. After a deep dive in the code I found the responsible place for it.


My question

How can I override strapi’s core entity-validator for uid?

Looking forward for your help.

You can’t overwrite the strapi’s core code with the extensions or something similar as we do with extensions on plugins/admin. The only solution is to fork the strapi core and modify it.

1 Like

That’s to bad. So I actually have to create a fork and host that on npm as a private package to install via yarn?

Unfortunately, yes, if you want to modify the core, this is how you should do it. It’s the same approach for any npm package, if you want to modify its core you should fork it. You should also manage manually all the updates inside the core, to not overwrite your modifications when merging new releases.

1 Like

Do you maybe know a better way of changing the regex of the UID field type? So it can accept /home/testpage for example

You can create a collection type called URLs, there you will have Homepage, Contacts, Categories, Tags, etc.
For the Page you should keep the default slug field. (ex: my-test-page)

Then you add your Page into the relation with an item from URLs, for example, let’s assume we created a new page with slug my-test-page and created a relation with Homepage from URLS.

An example response for the Page, after adding the relation with Homepage

    "id": "1",
    "page_title": "My test page",
    "page_body": "some text here",

Now you get the page_slug and the urls.url_slug and concatenate them:

let URL = `/${data.page_slug}/${data.urls.url_slug}`; // result: /homepage/my-test-page
1 Like

Hi Sunny,

Thanks for your quick response.
How would this work for nested urls? :slight_smile: