Skip to content

Commit b7799de

Browse files
committed
2 new files added
1 parent 90492ff commit b7799de

3 files changed

Lines changed: 59 additions & 1 deletion

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import {SUPPORTED_KEYWORDS} from './supportedJsonSchemaTypeKeywords';
2+
import type {JsonSchemaType} from './supportedJsonSchemaTypeKeywords';
3+
export function cleanupSchemaByType(schema: Record<string, any>, type: JsonSchemaType | '$ref') {
4+
let allowed: string[];
5+
6+
if (type === '$ref') {
7+
allowed = ['$ref', 'title', 'description', 'default', 'examples'];
8+
} else {
9+
allowed = SUPPORTED_KEYWORDS[type];
10+
}
11+
12+
Object.keys(schema).forEach(key => {
13+
if (!allowed.includes(key) && key !== 'type') {
14+
delete schema[key];
15+
}
16+
});
17+
}

meta_configurator/src/schema/graph-representation/typeUtils.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import type {JsonSchemaObjectType, SchemaPropertyTypes} from '@/schema/jsonSchemaType';
22
import {pathToJsonPointer} from '@/utility/pathUtils';
33
import {SchemaNodeData} from '@/schema/graph-representation/schemaGraphTypes';
4-
import type {Path} from '@/utility/path';
4+
import type {Path} from '@/utility/path'
5+
import { cleanupSchemaByType } from '../cleanupSchemaByType';
56

67
export type AttributeTypeChoice = {label: string; schema: JsonSchemaObjectType};
78

@@ -111,6 +112,7 @@ export function applyNewType(
111112
) {
112113
if (typeSchema.type !== undefined) {
113114
currentSchema.type = typeSchema.type;
115+
cleanupSchemaByType(currentSchema, typeSchema.type);
114116
if (typeSchema.type === 'array') {
115117
if (
116118
currentSchema.items === undefined ||
@@ -131,6 +133,7 @@ export function applyNewType(
131133

132134
if (typeSchema.$ref) {
133135
currentSchema.$ref = typeSchema.$ref;
136+
cleanupSchemaByType(currentSchema, '$ref');
134137
} else {
135138
delete currentSchema.$ref;
136139
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
export type JsonSchemaType =
2+
| 'string'
3+
| 'number'
4+
| 'integer'
5+
| 'object'
6+
| 'array'
7+
| 'boolean'
8+
| 'null';
9+
10+
const COMMON = ['title', 'description', 'default', 'examples', 'enum', 'const'];
11+
12+
const GENERIC = ['allOf', 'anyOf', 'oneOf', 'not'];
13+
14+
export const SUPPORTED_KEYWORDS: Record<JsonSchemaType, string[]> = {
15+
string: [...COMMON, ...GENERIC, 'minLength', 'maxLength', 'pattern', 'format'],
16+
number: [
17+
...COMMON,
18+
...GENERIC,
19+
'minimum',
20+
'maximum',
21+
'exclusiveMinimum',
22+
'exclusiveMaximum',
23+
'multipleOf',
24+
],
25+
integer: [
26+
...COMMON,
27+
...GENERIC,
28+
'minimum',
29+
'maximum',
30+
'exclusiveMinimum',
31+
'exclusiveMaximum',
32+
'multipleOf',
33+
],
34+
object: [...COMMON, ...GENERIC, 'properties', 'required', 'additionalProperties'],
35+
array: [...COMMON, ...GENERIC, 'items', 'minItems', 'maxItems', 'uniqueItems'],
36+
boolean: [...COMMON, ...GENERIC],
37+
null: [...COMMON, ...GENERIC],
38+
};

0 commit comments

Comments
 (0)