Skip to content

Commit 51b5248

Browse files
committed
feat: JSONSchema 관련 라이브러리 및 함수 추가
1 parent 9c51636 commit 51b5248

File tree

4 files changed

+319
-0
lines changed

4 files changed

+319
-0
lines changed

package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,25 @@
2727
"@mdx-js/rollup": "^3.1.0",
2828
"@mui/icons-material": "^7.1.0",
2929
"@mui/material": "^7.1.0",
30+
"@rjsf/core": "6.0.0-beta.10",
31+
"@rjsf/mui": "6.0.0-beta.10",
32+
"@rjsf/utils": "6.0.0-beta.10",
33+
"@rjsf/validator-ajv8": "6.0.0-beta.10",
3034
"@suspensive/react": "^3.2.0",
3135
"@tanstack/react-query": "^5.76.1",
3236
"@uiw/react-md-editor": "^4.0.7",
37+
"ajv-draft-04": "^1.0.0",
3338
"astring": "^1.9.0",
3439
"axios": "^1.9.0",
3540
"crypto-js": "^4.2.0",
3641
"globals": "^15.15.0",
42+
"json-schema": "^0.4.0",
3743
"mui-mdx-components": "^0.5.0",
3844
"notistack": "^3.0.2",
3945
"react": "^19.1.0",
4046
"react-dom": "^19.1.0",
4147
"react-router-dom": "^7.6.0",
48+
"remark-gfm": "^4.0.1",
4249
"remeda": "^2.21.5"
4350
},
4451
"devDependencies": {
@@ -49,6 +56,7 @@
4956
"@rollup/plugin-replace": "^6.0.2",
5057
"@tanstack/react-query-devtools": "^5.76.1",
5158
"@types/crypto-js": "^4.2.2",
59+
"@types/json-schema": "^7.0.15",
5260
"@types/mdx": "^2.0.13",
5361
"@types/node": "^22.15.18",
5462
"@types/react": "^19.1.4",

packages/common/src/utils/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ import {
1010
getFormValue as _getFormValue,
1111
isFormValid as _isFormValid,
1212
} from "./form";
13+
import {
14+
filterReadOnlyPropertiesInJsonSchema as _filterReadOnlyPropertiesInJsonSchema,
15+
filterWritablePropertiesInJsonSchema as _filterWritablePropertiesInJsonSchema,
16+
} from './json_schema';
1317

1418
namespace Utils {
1519
export const buildNestedSiteMap = _buildNestedSiteMap;
@@ -19,6 +23,8 @@ namespace Utils {
1923
export const isFormValid = _isFormValid;
2024
export const getFormValue = _getFormValue;
2125
export const isFilledString = (obj: unknown): obj is string => R.isString(obj) && !R.isEmpty(obj);
26+
export const filterWritablePropertiesInJsonSchema = _filterWritablePropertiesInJsonSchema;
27+
export const filterReadOnlyPropertiesInJsonSchema = _filterReadOnlyPropertiesInJsonSchema;
2228
}
2329

2430
export default Utils;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { JSONSchema7 } from 'json-schema';
2+
3+
export const filterWritablePropertiesInJsonSchema = (schema: JSONSchema7) => {
4+
const writableSchema: JSONSchema7 = { ...schema };
5+
if (writableSchema.properties) {
6+
writableSchema.properties = Object.entries(writableSchema.properties)
7+
.filter(([_, propDef]) => !(propDef as JSONSchema7).readOnly)
8+
.reduce(
9+
(acc, [propKey, propDef]) => ({...acc, [propKey]: filterWritablePropertiesInJsonSchema(propDef as JSONSchema7)}),
10+
{} as JSONSchema7["properties"],
11+
);
12+
}
13+
14+
return writableSchema;
15+
}
16+
17+
export const filterReadOnlyPropertiesInJsonSchema = (schema: JSONSchema7) => {
18+
const readOnlySchema: JSONSchema7 = { ...schema };
19+
if (readOnlySchema.properties) {
20+
readOnlySchema.properties = Object.entries(readOnlySchema.properties)
21+
.filter(([_, propDef]) => (propDef as JSONSchema7).readOnly)
22+
.reduce(
23+
(acc, [propKey, propDef]) => ({...acc, [propKey]: filterReadOnlyPropertiesInJsonSchema(propDef as JSONSchema7)}),
24+
{} as JSONSchema7["properties"],
25+
);
26+
readOnlySchema.required = readOnlySchema.required?.filter((key) => key in (readOnlySchema?.properties || {}));
27+
}
28+
29+
return readOnlySchema;
30+
}

0 commit comments

Comments
 (0)