Skip to content

Commit

Permalink
fix: labels in object arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
julrich committed Oct 11, 2024
1 parent b73dc5f commit e67e073
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@kickstartds/jsonschema2stackbit",
"comment": "use correct labels in arrays of objects",
"type": "patch"
}
],
"packageName": "@kickstartds/jsonschema2stackbit"
}
4 changes: 4 additions & 0 deletions common/config/rush/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion tools/jsonschema2stackbit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"dependencies": {
"@kickstartds/jsonschema-utils": "workspace:*",
"ajv": "^8.12.0",
"object-traversal": "^1.0.1"
"object-traversal": "^1.0.1",
"pluralize": "^8.0.0"
},
"devDependencies": {
"@rushstack/eslint-config": "^3.2.0",
Expand All @@ -31,6 +32,7 @@
"@types/common-tags": "^1.8.4",
"@types/heft-jest": "1.0.3",
"@types/node": "^18.16.4",
"@types/pluralize": "^0.0.33",
"@types/ramda": "^0.28.20",
"@types/uuid": "~9.0.2",
"@typescript-eslint/parser": "~5.59.2",
Expand Down
8 changes: 5 additions & 3 deletions tools/jsonschema2stackbit/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
} from '@stackbit/types';
import { type JSONSchema, TypeName } from 'json-schema-typed/draft-07';
import { traverse } from 'object-traversal';
import { singular } from 'pluralize';

import { GenericType, ITypeMapping } from './@types/index.js';
export * from './@types/index.js';
Expand Down Expand Up @@ -230,15 +231,16 @@ function processObject({
const modelName =
classification && ['component', 'template', 'global'].includes(classification) && subSchema.$id
? getSchemaName(subSchema.$id).replaceAll('-', '_')
: name.replaceAll('-', '_');
: singular(name.replaceAll('-', '_'));
const modelLabel =
(classification && ['component', 'template', 'global'].includes(classification) && subSchema.title) ||
title ||
toPascalCase(modelName);

const model: FieldModel = {
name: name.replaceAll('-', '_'),
label: title || toPascalCase(name),
description,
label: parentSchema.title || toPascalCase(name),
description: parentSchema.description || description,
type: 'model',
models: [modelName]
};
Expand Down

0 comments on commit e67e073

Please sign in to comment.