Skip to content

Commit

Permalink
fix: add additional cms format, add table format
Browse files Browse the repository at this point in the history
  • Loading branch information
julrich committed Sep 30, 2024
1 parent 7f904a3 commit 26eb394
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 44 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@kickstartds/jsonschema-utils",
"comment": "add additional cms format, add table format",
"type": "patch"
}
],
"packageName": "@kickstartds/jsonschema-utils"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@kickstartds/jsonschema2storyblok",
"comment": "add additional cms format, add table format",
"type": "patch"
}
],
"packageName": "@kickstartds/jsonschema2storyblok"
}
8 changes: 7 additions & 1 deletion tools/jsonschema-utils/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ export function getSchemaRegistry({ support2019 = false }: { support2019?: boole
'html',
'uuid',
'date-time',
'icon'
'icon',
'table'
];
ignoredFormats.forEach((ignoredFormat) => ajv.addFormat(ignoredFormat, { validate: () => true }));

Expand Down Expand Up @@ -78,6 +79,11 @@ export function getSchemaRegistry({ support2019 = false }: { support2019?: boole
schemaType: 'boolean',
validate: () => true
});
ajv.addKeyword({
keyword: 'x-cms-hidden',
schemaType: 'boolean',
validate: () => true
});

return ajv;
}
Expand Down
65 changes: 22 additions & 43 deletions tools/jsonschema2storyblok/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,31 @@ function basicTypeMapping(property: JSONSchema.Interface): GenericType {
return 'number';
}

if (property.type === 'string' && property.format && property.format === 'table') {
return 'table';
}

return mapping[property.type as TypeName];
}

function componentsEqual(componentOne: IStoryblokBlock, componentTwo: IStoryblokBlock): boolean {
return componentOne.name === componentTwo.name;
}

function createBlokSchema(fields: IStoryblokSchemaElement[]): Record<string, IStoryblokSchemaElement> {
return fields.reduce<Record<string, IStoryblokSchemaElement>>((schema, field) => {
schema[field.key] = field;
console.log('field', field.key);
if (field.objectFields) {
for (const objectField of field.objectFields) {
schema[objectField.key] = objectField;
}
delete field.objectFields;
}
return schema;
}, {});
}

function processObject({
name,
description,
Expand Down Expand Up @@ -228,17 +246,7 @@ function processObject({
created_at: new Date().toISOString(),
updated_at: new Date().toISOString(),
id: blokId++,
schema:
fields.reduce<Record<string, IStoryblokSchemaElement>>((schema, field) => {
schema[field.key] = field;
if (field.objectFields) {
for (const objectField of field.objectFields) {
schema[objectField.key] = objectField;
}
delete field.objectFields;
}
return schema;
}, {}) || [],
schema: createBlokSchema(fields),
is_nestable: true,
real_name: toPascalCase(blokName),
color: colors[blokName] || '#05566a',
Expand Down Expand Up @@ -298,16 +306,7 @@ function processObject({
updated_at: new Date().toISOString(),
is_root: (classification && classification === 'template') || false,
id: blokId++,
schema: fields.reduce<Record<string, IStoryblokSchemaElement>>((schema, field) => {
schema[field.key] = field;
if (field.objectFields) {
for (const objectField of field.objectFields) {
schema[objectField.key] = objectField;
}
delete field.objectFields;
}
return schema;
}, {}),
schema: createBlokSchema(fields),
is_nestable: true,
real_name: toPascalCase(name)
}
Expand Down Expand Up @@ -374,17 +373,7 @@ function processRef({
created_at: new Date().toISOString(),
updated_at: new Date().toISOString(),
id: blokId++,
schema:
fields.reduce<Record<string, IStoryblokSchemaElement>>((schema, field) => {
schema[field.key] = field;
if (field.objectFields) {
for (const objectField of field.objectFields) {
schema[objectField.key] = objectField;
}
delete field.objectFields;
}
return schema;
}, {}) || [],
schema: createBlokSchema(fields),
is_nestable: true,
real_name: toPascalCase(blokName),
color: colors[blokName] || '#05566a',
Expand Down Expand Up @@ -433,17 +422,7 @@ function processRefArray({
created_at: new Date().toISOString(),
updated_at: new Date().toISOString(),
id: blokId++,
schema:
field.objectFields.reduce<Record<string, IStoryblokSchemaElement>>((schema, field) => {
schema[field.key] = field;
if (field.objectFields) {
for (const objectField of field.objectFields) {
schema[objectField.key] = objectField;
}
delete field.objectFields;
}
return schema;
}, {}) || [],
schema: createBlokSchema(field.objectFields),
is_nestable: true,
real_name: toPascalCase(name),
color: colors[field.key] || '#05566a',
Expand Down

0 comments on commit 26eb394

Please sign in to comment.