From 58068076d60ed45470264ea6b0927d14c93ddc08 Mon Sep 17 00:00:00 2001 From: Rikki Schulte Date: Fri, 6 Sep 2024 03:58:50 +0200 Subject: [PATCH] Revert "added limited support for conditional property values" (#141) Reverts jsonnext/codemirror-json-schema#135, I did not see the alternative PR sorry! --- .changeset/nine-timers-develop.md | 5 --- .../__tests__/__fixtures__/schemas.ts | 14 +------- .../__tests__/json-completion.spec.ts | 18 ---------- src/features/completion.ts | 35 ++----------------- 4 files changed, 3 insertions(+), 69 deletions(-) delete mode 100644 .changeset/nine-timers-develop.md diff --git a/.changeset/nine-timers-develop.md b/.changeset/nine-timers-develop.md deleted file mode 100644 index 32518d4..0000000 --- a/.changeset/nine-timers-develop.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"codemirror-json-schema": patch ---- - -added limited support for conditional property values diff --git a/src/features/__tests__/__fixtures__/schemas.ts b/src/features/__tests__/__fixtures__/schemas.ts index f0f416c..e6ba10b 100644 --- a/src/features/__tests__/__fixtures__/schemas.ts +++ b/src/features/__tests__/__fixtures__/schemas.ts @@ -140,7 +140,7 @@ export const testSchemaConditionalProperties = { properties: { type: { type: "string", - enum: ["Test_1", "Test_2", "Test_3"], + enum: ["Test_1", "Test_2"], }, props: { type: "object", @@ -181,17 +181,5 @@ export const testSchemaConditionalProperties = { }, }, }, - { - if: { - properties: { - type: { const: "Test_3" }, - }, - }, - then: { - properties: { - props: { type: "string", enum: ["ace", "abu", "bay"] }, - }, - }, - }, ], } as JSONSchema7; diff --git a/src/features/__tests__/json-completion.spec.ts b/src/features/__tests__/json-completion.spec.ts index 8c4aacf..6be53bd 100644 --- a/src/features/__tests__/json-completion.spec.ts +++ b/src/features/__tests__/json-completion.spec.ts @@ -409,24 +409,6 @@ describe.each([ ], schema: testSchemaConditionalProperties, }, - { - name: "autocomplete for a schema with conditional property values", - mode: MODES.JSON, - docs: ['{ "type": "Test_3", "props": "a|"'], - expectedResults: [ - { - type: "string", - label: "ace", - apply: '"ace"', - }, - { - type: "string", - label: "abu", - apply: '"abu"', - }, - ], - schema: testSchemaConditionalProperties, - }, // JSON5 { name: "return bare property key when no quotes are used", diff --git a/src/features/completion.ts b/src/features/completion.ts index f73efd3..9c5f2d1 100644 --- a/src/features/completion.ts +++ b/src/features/completion.ts @@ -837,50 +837,19 @@ export class JSONCompletion { if ( !subSchema || subSchema.name === "UnknownPropertyError" || - // TODO: Looking into why this is needed subSchema.enum || subSchema.type === "undefined" || subSchema.type === "null" ) { - debug.log( - "xxx", - "no schema for pointer. Try parent pointer..", - pointer, - subSchema - ); pointer = pointer.replace(/\/[^/]*$/, "/"); - pointer = "/" ? "" : pointer; // root pointer should be empty ("/" is a JSON pointer for an empty string key) - subSchema = draft.getSchema({ pointer, data: data ?? undefined }); - debug.log( - "xxx", - "subSchema for parent pointer", - subSchema, - pointer, - data - ); - // resolve all direct child schemas - // TODO: This is a bit hacky, but it works for now - if (subSchema?.properties) { - Object.entries(subSchema.properties).forEach(([key, value]) => { - if (subSchema?.properties && typeof value === "object") { - subSchema.properties[key] = { - ...value, - ...draft.getSchema({ - pointer: pointer + "/" + key, - data: data ?? undefined, - }), - }; - } - }); - debug.log("xxx", "direct children resolved", subSchema); - } + subSchema = draft.getSchema({ pointer }); } debug.log("xxx", "pointer..", JSON.stringify(pointer)); // For some reason, it returns undefined schema for the root pointer // We use the root schema in that case as the relevant (sub)schema - if (!subSchema && (!pointer || pointer === "/")) { + if (!pointer || pointer === "/") { subSchema = this.expandSchemaProperty(schema, schema) ?? schema; } // const subSchema = new Draft07(this.schema).getSchema(pointer);