Skip to content

Commit

Permalink
fix: enums in stackbit connector
Browse files Browse the repository at this point in the history
  • Loading branch information
julrich committed Oct 10, 2024
1 parent 6e19a56 commit 6e6a378
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@kickstartds/jsonschema2stackbit",
"comment": "resolve wrong enums",
"type": "patch"
}
],
"packageName": "@kickstartds/jsonschema2stackbit"
}
8 changes: 6 additions & 2 deletions tools/jsonschema2stackbit/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
toPascalCase,
getSchemaReducer,
IProcessInterface,
safeEnumKey,
IReducerResult,
IProcessFnResult,
IConvertParams,
Expand Down Expand Up @@ -49,6 +48,10 @@ function isObjectModel(field: unknown): field is ObjectModel {
return typeof field === 'object' && field !== null && 'type' in field && field.type === 'object';
}

function safeEnumKey(string: string): string {
return string;
}

/**
* @param jsonSchemas - An individual schema or an array of schemas, provided
* either as Javascript objects or as JSON text.
Expand Down Expand Up @@ -511,6 +514,7 @@ function processEnum({
title,
description,
subSchema,
parentSchema,
options
}: IProcessInterface<Field>): IProcessFnResult<Field, ObjectModel, PageModel, DataModel> {
const field: FieldEnum = {
Expand All @@ -531,7 +535,7 @@ function processEnum({
field.options = options;
}

field.required = subSchema.required?.includes(name) || false;
field.required = parentSchema?.required?.includes(name) || false;

return { field };
}
Expand Down

0 comments on commit 6e6a378

Please sign in to comment.