Skip to content

Commit 5537424

Browse files
authored
feat(input_schema): Update sub-schema related types (#534)
Update input-schema types regarding the sub-schema features (new editor value, `properties`, `required`, `additionalProperties`)
1 parent f6198d1 commit 5537424

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

packages/input_schema/src/input_schema.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export function parseAjvError(
6868
// If error is with keyword type, it means that type of input is incorrect
6969
// this can mean that provided value is null
7070
if (error.keyword === 'type') {
71-
fieldKey = error.instancePath.split('/').pop()!;
71+
fieldKey = cleanPropertyName(error.instancePath);
7272
// Check if value is null and field is nullable, if yes, then skip this error
7373
if (properties[fieldKey] && properties[fieldKey].nullable && input[fieldKey] === null) {
7474
return null;
@@ -167,7 +167,7 @@ function validateField(validator: Ajv, fieldSchema: Record<string, unknown>, fie
167167
if ((fieldSchema as StringFieldDefinition).enum) {
168168
const definition = matchingDefinitions.filter((item) => !!item.properties.enum).pop();
169169
if (!definition) throw new Error('Input schema validation failed to find "enum property" definition');
170-
validateAgainstSchemaOrThrow(validator, fieldSchema, enhanceDefinition(definition), `schema.properties.${fieldKey}.enum`);
170+
validateAgainstSchemaOrThrow(validator, fieldSchema, enhanceDefinition(definition), `schema.properties.${fieldKey}`);
171171
return;
172172
}
173173
// If the definition contains "resourceType" property then it's resource type.

packages/input_schema/src/types.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,19 @@ export type IntegerFieldDefinition = CommonFieldDefinition<number> & {
3939

4040
export type ObjectFieldDefinition = CommonFieldDefinition<object> & {
4141
type: 'object'
42-
editor: 'json' | 'proxy' | 'hidden';
42+
editor: 'json' | 'proxy' | 'schemaBased' | 'hidden';
4343
patternKey?: string;
4444
patternValue?: string;
4545
maxProperties?: number;
4646
minProperties?: number;
47+
properties?: Record<string, unknown>;
48+
required?: string[];
49+
additionalProperties?: boolean;
4750
}
4851

4952
export type ArrayFieldDefinition = CommonFieldDefinition<unknown[]> & {
5053
type: 'array'
51-
editor: 'json' | 'requestListSources' | 'pseudoUrls' | 'globs' | 'keyValue' | 'stringList' | 'select' | 'hidden';
54+
editor: 'json' | 'requestListSources' | 'pseudoUrls' | 'globs' | 'keyValue' | 'stringList' | 'select' | 'schemaBased' | 'hidden';
5255
placeholderKey?: string;
5356
placeholderValue?: string;
5457
patternKey?: string;

test/input_schema.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ describe('input_schema.json', () => {
246246
};
247247

248248
expect(() => validateInputSchema(validator, schema)).toThrow(
249-
'Input schema is not valid (Field schema.properties.myField.enum.enum must NOT have fewer than 1 items)',
249+
'Input schema is not valid (Field schema.properties.myField.enum must NOT have fewer than 1 items)',
250250
);
251251
});
252252

@@ -267,7 +267,7 @@ describe('input_schema.json', () => {
267267
};
268268

269269
expect(() => validateInputSchema(validator, schema)).toThrow(
270-
'Input schema is not valid (Field schema.properties.myField.enum.enumTitles must NOT have fewer than 1 items)',
270+
'Input schema is not valid (Field schema.properties.myField.enumTitles must NOT have fewer than 1 items)',
271271
);
272272
});
273273

0 commit comments

Comments
 (0)