Skip to content

Commit

Permalink
Revert "added limited support for conditional property values" (#141)
Browse files Browse the repository at this point in the history
Reverts #135, I did not see the
alternative PR sorry!
  • Loading branch information
acao authored Sep 6, 2024
1 parent 917333e commit 5806807
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 69 deletions.
5 changes: 0 additions & 5 deletions .changeset/nine-timers-develop.md

This file was deleted.

14 changes: 1 addition & 13 deletions src/features/__tests__/__fixtures__/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -181,17 +181,5 @@ export const testSchemaConditionalProperties = {
},
},
},
{
if: {
properties: {
type: { const: "Test_3" },
},
},
then: {
properties: {
props: { type: "string", enum: ["ace", "abu", "bay"] },
},
},
},
],
} as JSONSchema7;
18 changes: 0 additions & 18 deletions src/features/__tests__/json-completion.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
35 changes: 2 additions & 33 deletions src/features/completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 5806807

Please sign in to comment.