Skip to content

Commit

Permalink
Merge pull request #122 from storyblok/PRO-658
Browse files Browse the repository at this point in the history
[PRO-658] - Update `Asset`, `Multiasset` and `Multilink` types
  • Loading branch information
alvarosabu authored Oct 4, 2024
2 parents ad5a50b + 7562c03 commit 43327b7
Showing 1 changed file with 149 additions and 25 deletions.
174 changes: 149 additions & 25 deletions src/utils/typescript/storyblokProvidedPropertyTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
},
Expand All @@ -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",
Expand Down Expand Up @@ -169,39 +262,70 @@ 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",
},
linktype: {
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"],
},
},
},
Expand Down

0 comments on commit 43327b7

Please sign in to comment.