📙 For any Help, Contact me on Discord (@raideno).
Extend Validators

Extend Entity Validators

Built-In entities are updated through default medusa endpoints. This is why we need to extend those endpoints validators in order to accept new fields and validate them.

1- Extend Validators

IMPORTANT Note: depending on your usecase / fields you added the validators might change, if you need help for creating your validators contact us.

In the same file where you created your entity (previous step):

src/models/product.ts
import { Column, Entity } from "typeorm";
 
import { Product as MedusaProduct } from "@medusajs/medusa";
 
import {
  UltimateEntity,
  UltimateEntityField,
  UltimateEntityFieldTypes,
} from "medusa-plugin-ultimate/dist/index";
 
@Entity()
@UltimateEntity({
  isBuiltInEntity: true,
  hidden: true,
})
export class Product extends MedusaProduct {
  @UltimateEntityField({
    type: UltimateEntityFieldTypes.MARKDOWN,
  })
  @Column({ type: "varchar", nullable: true })
  rich_description?: string | null;
}
 
import { IsString, IsOptional } from "class-validator";
import { registerOverriddenValidators } from "@medusajs/medusa";
import { AdminPostProductsReq as MedusaAdminPostProductsReq } from "@medusajs/medusa/dist/api/routes/admin/products/create-product";
import { AdminPostProductsProductReq as MedusaAdminPostProductsProductReq } from "@medusajs/medusa/dist/api/routes/admin/products/update-product";
 
class AdminPostProductsReq extends MedusaAdminPostProductsReq {
  @IsOptional()
  @IsString()
  rich_description?: string | null;
}
 
class AdminPostProductsProductReq extends MedusaAdminPostProductsProductReq {
  @IsOptional()
  @IsString()
  rich_description?: string | null;
}
 
registerOverriddenValidators(AdminPostProductsReq);
registerOverriddenValidators(AdminPostProductsProductReq);