Skip to content

Commit

Permalink
Show autogenerated error message that matches title
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettmflynn committed Oct 10, 2023
1 parent 6300a8c commit a299a0c
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/renderer/src/stories/JSONSchemaForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,9 +349,9 @@ export class JSONSchemaForm extends LitElement {
return true;
};

#get = (path, object = this.resolved) => {
#get = (path, object = this.resolved, omitted = []) => {
// path = path.slice(this.base.length); // Correct for base path
return path.reduce((acc, curr) => (acc = acc[curr]), object);
return path.reduce((acc, curr) => (acc = acc[curr] ?? acc?.[omitted.find(str => acc[str])]?.[curr]), object);
};

#checkRequiredAfterChange = async (localPath) => {
Expand All @@ -375,7 +375,8 @@ export class JSONSchemaForm extends LitElement {
if (indexOf !== -1) path = path.slice(indexOf + 1);
}

const resolved = this.#get(path, schema);

const resolved = this.#get(path, schema, ["properties"]);
if (resolved["$ref"]) return this.getSchema(resolved["$ref"].split("/").slice(1)); // NOTE: This assumes reference to the root of the schema

return resolved;
Expand Down Expand Up @@ -619,7 +620,9 @@ export class JSONSchemaForm extends LitElement {
} else {
// For non-links, throw a basic requirement error if the property is required
if (!errors.length && isRequired && !parent[name]) {
errors.push({ message: `${name} is a required property.`, type: "error", missing: true }); // Throw at least a basic error if the property is required
const schema = this.getSchema(localPath)
console.log(schema)
errors.push({ message: `${schema.title ?? header(name)} is a required property.`, type: "error", missing: true }); // Throw at least a basic error if the property is required
}
}

Expand Down

0 comments on commit a299a0c

Please sign in to comment.