diff --git a/src/utils/typescript/storyblokProvidedPropertyTypes.ts b/src/utils/typescript/storyblokProvidedPropertyTypes.ts index e480bec..21f5b13 100644 --- a/src/utils/typescript/storyblokProvidedPropertyTypes.ts +++ b/src/utils/typescript/storyblokProvidedPropertyTypes.ts @@ -4,27 +4,65 @@ export const getAssetJSONSchema = (title: string): JSONSchema => ({ $id: "#/asset", title, type: "object", - required: ["id", "filename", "name"], + required: ["id", "fieldtype", "filename", "name", "title", "focus", "alt"], properties: { alt: { - type: "string", + type: ["string", "null"], }, copyright: { + type: ["string", "null"], + }, + fieldtype: { type: "string", + enum: ["asset"], }, id: { type: "number", }, filename: { - type: "string", + type: ["string", "null"], }, name: { type: "string", }, title: { - type: "string", + type: ["string", "null"], }, focus: { + type: ["string", "null"], + }, + meta_data: { + type: "object", + }, + source: { + type: ["string", "null"], + }, + is_external_url: { + type: "boolean", + }, + is_private: { + type: "boolean", + }, + src: { + type: "string", + }, + updated_at: { + type: "string", + }, + // Cloudinary integration keys + width: { + type: ["number", "null"], + }, + height: { + type: ["number", "null"], + }, + aspect_ratio: { + type: ["number", "null"], + }, + public_id: { + type: ["string", "null"], + }, + content_type: { type: "string", }, }, @@ -36,53 +74,108 @@ export const getMultiassetJSONSchema = (title: string): JSONSchema => ({ type: "array", items: { type: "object", - required: ["id", "filename", "name"], + required: ["id", "fieldtype", "filename", "name", "title", "focus", "alt"], properties: { alt: { - type: "string", + type: ["string", "null"], }, copyright: { + type: ["string", "null"], + }, + fieldtype: { type: "string", + enum: ["asset"], }, id: { type: "number", }, filename: { - type: "string", + type: ["string", "null"], }, name: { type: "string", }, title: { + type: ["string", "null"], + }, + focus: { + type: ["string", "null"], + }, + meta_data: { + type: "object", + }, + source: { + type: ["string", "null"], + }, + is_external_url: { + type: "boolean", + }, + is_private: { + type: "boolean", + }, + src: { + type: "string", + }, + updated_at: { + type: "string", + }, + // Cloudinary integration keys + width: { + type: ["number", "null"], + }, + height: { + type: ["number", "null"], + }, + aspect_ratio: { + type: ["number", "null"], + }, + public_id: { + type: ["string", "null"], + }, + content_type: { type: "string", }, }, }, }); +// TODO: find a reliable way to share props among different Link Types to increase maintainability +// Currently not possible because of JSONSchema4 complaining +const multilinkSharedRequiredProps = ["fieldtype", "id", "url", "cached_url", "linktype"]; + export const getMultilinkJSONSchema = (title: string): JSONSchema => ({ $id: "#/multilink", title, oneOf: [ { type: "object", + required: multilinkSharedRequiredProps, properties: { - id: { + // Shared props + fieldtype: { type: "string", + enum: ["multilink"], }, - cached_url: { + id: { type: "string" }, + url: { type: "string" }, + cached_url: { type: "string" }, + target: { type: "string", enum: ["_blank", "_self"] }, + // Custom props + anchor: { type: "string", }, - anchor: { + rel: { type: "string", }, - linktype: { + title: { type: "string", - enum: ["story"], }, - target: { + prep: { type: "string", - enum: ["_self", "_blank"], + }, + linktype: { + type: "string", + enum: ["story"], }, story: { type: "object", @@ -169,29 +262,44 @@ export const getMultilinkJSONSchema = (title: string): JSONSchema => ({ }, { type: "object", + required: multilinkSharedRequiredProps, properties: { - url: { + // Shared props + fieldtype: { type: "string", + enum: ["multilink"], }, - cached_url: { - type: "string", - }, - anchor: { + id: { type: "string" }, + url: { type: "string" }, + cached_url: { type: "string" }, + target: { type: "string", enum: ["_blank", "_self"] }, + // Custom props + linktype: { type: "string", + enum: ["url"], }, - linktype: { + rel: { type: "string", - enum: ["asset", "url"], }, - target: { + title: { type: "string", - enum: ["_self", "_blank"], }, }, }, { type: "object", + required: multilinkSharedRequiredProps, properties: { + // Shared props + fieldtype: { + type: "string", + enum: ["multilink"], + }, + id: { type: "string" }, + url: { type: "string" }, + cached_url: { type: "string" }, + target: { type: "string", enum: ["_blank", "_self"] }, + // Custom props email: { type: "string", }, @@ -199,9 +307,25 @@ export const getMultilinkJSONSchema = (title: string): JSONSchema => ({ type: "string", enum: ["email"], }, - target: { + }, + }, + { + type: "object", + required: multilinkSharedRequiredProps, + properties: { + // Shared props + fieldtype: { + type: "string", + enum: ["multilink"], + }, + id: { type: "string" }, + url: { type: "string" }, + cached_url: { type: "string" }, + target: { type: "string", enum: ["_blank", "_self"] }, + // Custom props + linktype: { type: "string", - enum: ["_self", "_blank"], + enum: ["asset"], }, }, },