-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: render enum as string from schema ref form
* fix: render enum as string from schema ref form
- Loading branch information
Showing
6 changed files
with
61 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { FieldProps } from '@/components/collection-form' | ||
|
||
function definitionFromField(field: FieldProps) { | ||
const { name, existing, removed, ...definition } = field | ||
return [name, definition] as const | ||
} | ||
|
||
export { definitionFromField } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import type { FieldProps } from '@/components/collection-form' | ||
import { definitionFromField } from './definition-from-field' | ||
|
||
function schemaFromFields(fields: FieldProps[]) { | ||
const schema: Record<string, any> = {} | ||
for (const field of fields) { | ||
if (field.removed) { | ||
continue | ||
} | ||
|
||
const [name, definition] = definitionFromField(field) | ||
|
||
if (definition.type === 'string') { | ||
if (definition.enum) { | ||
if (definition.enum.length === 0) { | ||
// remove empty enum list | ||
definition.enum = undefined | ||
} else { | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
definition.enum = definition.enum.map((it) => it.text) | ||
} | ||
} | ||
} | ||
|
||
schema[name] = definition | ||
} | ||
|
||
return schema | ||
} | ||
|
||
export { schemaFromFields } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters