Skip to content

Commit

Permalink
feature(stackbit): improve integration
Browse files Browse the repository at this point in the history
  • Loading branch information
julrich committed Jul 10, 2024
1 parent a18248b commit 525aba5
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@kickstartds/jsonschema-utils",
"comment": "handle nested allOfs",
"type": "patch"
}
],
"packageName": "@kickstartds/jsonschema-utils"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@kickstartds/jsonschema2stackbit",
"comment": "extract more tab groups",
"type": "patch"
}
],
"packageName": "@kickstartds/jsonschema2stackbit"
}
4 changes: 3 additions & 1 deletion tools/jsonschema-utils/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,9 @@ export function reduceSchemaAllOf(

const reducedSchema = allOfs.reduce((finalSchema: JSONSchema.Interface, allOf: JSONSchema.Interface) => {
const mergeSchemaAllOf = (allOf: JSONSchema.Interface): JSONSchema.Interface => {
if (allOf.$ref !== undefined) {
if (allOf.allOf) {
return deepMerge(reduceSchemaAllOf(allOf, ajv, replaceExamples), finalSchema, replaceExamples);
} else if (allOf.$ref !== undefined) {
const reffedSchema = structuredClone(
ajv.getSchema(
allOf.$ref.includes('#/definitions/') && !allOf.$ref.includes('http')
Expand Down
36 changes: 34 additions & 2 deletions tools/jsonschema2stackbit/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ export function convert({
schema.fields.length > 0 &&
Array.isArray(parent)
) {
for (const field of schema.fields.reverse()) {
parent.unshift({
for (const field of schema.fields) {
parent.splice(parent.indexOf(schema), 0, {
...field,
name: `${value.name}__${field.name}`,
group: field.group && field.group === 'content' ? undefined : field.group || value.name
Expand Down Expand Up @@ -171,6 +171,38 @@ function reduceFields(fields: Field[], subSchema: JSONSchema.Interface): [Field[
label: schemaField['x-cms-group-title'] || toPascalCase(groupName),
icon: schemaField['x-cms-group-icon'] || 'circle-question'
};

if (
field.group.startsWith('INLINE__') &&
field.type === 'object' &&
field.fields &&
field.fields.length > 0
) {
for (const subField of field.fields) {
if (!subField.group) continue;
const groupName = subField.group.startsWith('INLINE__')
? subField.group.replace('INLINE__', '')
: subField.group;

if (subField.group !== 'content') {
const schemaSubField = schemaField.properties && schemaField.properties[subField.name];

fieldGroups[subField.group] ||= {
name: groupName,
label:
(schemaSubField &&
isCmsAnnotatedSchema(schemaSubField) &&
schemaSubField['x-cms-group-title']) ||
toPascalCase(groupName),
icon:
(schemaSubField &&
isCmsAnnotatedSchema(schemaSubField) &&
schemaSubField['x-cms-group-icon']) ||
'circle-question'
};
}
}
}
}
}
fields.push(field);
Expand Down

0 comments on commit 525aba5

Please sign in to comment.