Skip to content

Commit 5806807

Browse files
authored
Revert "added limited support for conditional property values" (#141)
Reverts #135, I did not see the alternative PR sorry!
1 parent 917333e commit 5806807

File tree

4 files changed

+3
-69
lines changed

4 files changed

+3
-69
lines changed

.changeset/nine-timers-develop.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/features/__tests__/__fixtures__/schemas.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ export const testSchemaConditionalProperties = {
140140
properties: {
141141
type: {
142142
type: "string",
143-
enum: ["Test_1", "Test_2", "Test_3"],
143+
enum: ["Test_1", "Test_2"],
144144
},
145145
props: {
146146
type: "object",
@@ -181,17 +181,5 @@ export const testSchemaConditionalProperties = {
181181
},
182182
},
183183
},
184-
{
185-
if: {
186-
properties: {
187-
type: { const: "Test_3" },
188-
},
189-
},
190-
then: {
191-
properties: {
192-
props: { type: "string", enum: ["ace", "abu", "bay"] },
193-
},
194-
},
195-
},
196184
],
197185
} as JSONSchema7;

src/features/__tests__/json-completion.spec.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -409,24 +409,6 @@ describe.each([
409409
],
410410
schema: testSchemaConditionalProperties,
411411
},
412-
{
413-
name: "autocomplete for a schema with conditional property values",
414-
mode: MODES.JSON,
415-
docs: ['{ "type": "Test_3", "props": "a|"'],
416-
expectedResults: [
417-
{
418-
type: "string",
419-
label: "ace",
420-
apply: '"ace"',
421-
},
422-
{
423-
type: "string",
424-
label: "abu",
425-
apply: '"abu"',
426-
},
427-
],
428-
schema: testSchemaConditionalProperties,
429-
},
430412
// JSON5
431413
{
432414
name: "return bare property key when no quotes are used",

src/features/completion.ts

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -837,50 +837,19 @@ export class JSONCompletion {
837837
if (
838838
!subSchema ||
839839
subSchema.name === "UnknownPropertyError" ||
840-
// TODO: Looking into why this is needed
841840
subSchema.enum ||
842841
subSchema.type === "undefined" ||
843842
subSchema.type === "null"
844843
) {
845-
debug.log(
846-
"xxx",
847-
"no schema for pointer. Try parent pointer..",
848-
pointer,
849-
subSchema
850-
);
851844
pointer = pointer.replace(/\/[^/]*$/, "/");
852-
pointer = "/" ? "" : pointer; // root pointer should be empty ("/" is a JSON pointer for an empty string key)
853-
subSchema = draft.getSchema({ pointer, data: data ?? undefined });
854-
debug.log(
855-
"xxx",
856-
"subSchema for parent pointer",
857-
subSchema,
858-
pointer,
859-
data
860-
);
861-
// resolve all direct child schemas
862-
// TODO: This is a bit hacky, but it works for now
863-
if (subSchema?.properties) {
864-
Object.entries(subSchema.properties).forEach(([key, value]) => {
865-
if (subSchema?.properties && typeof value === "object") {
866-
subSchema.properties[key] = {
867-
...value,
868-
...draft.getSchema({
869-
pointer: pointer + "/" + key,
870-
data: data ?? undefined,
871-
}),
872-
};
873-
}
874-
});
875-
debug.log("xxx", "direct children resolved", subSchema);
876-
}
845+
subSchema = draft.getSchema({ pointer });
877846
}
878847

879848
debug.log("xxx", "pointer..", JSON.stringify(pointer));
880849

881850
// For some reason, it returns undefined schema for the root pointer
882851
// We use the root schema in that case as the relevant (sub)schema
883-
if (!subSchema && (!pointer || pointer === "/")) {
852+
if (!pointer || pointer === "/") {
884853
subSchema = this.expandSchemaProperty(schema, schema) ?? schema;
885854
}
886855
// const subSchema = new Draft07(this.schema).getSchema(pointer);

0 commit comments

Comments
 (0)