Skip to content

Commit

Permalink
adobe#371 first attempt at using property name as default title
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdeely committed Jan 29, 2023
1 parent 137b332 commit cd1ce34
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/schemaProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,13 @@ const handler = ({
return undefined;
};
meta[symbols.titles] = (target) => {
let selfName = meta[symbols.pointer]().split('/').pop();
if (selfName === '' || selfName === 'properties') selfName = undefined;

if (parent) {
// if we can determine the parent titles
// then we append our own
return [...parent[symbols.titles], target.title];
return [...parent[symbols.titles], target.title || selfName];
}
// otherwise, it's just our own
if (typeof target.title === 'string') {
Expand Down
8 changes: 8 additions & 0 deletions test/schemaProxy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ describe('Testing Schema Proxy', () => {
assert.deepStrictEqual(proxied.properties.zip[titles], ['Example Proxy', undefined, 'An object']);
});

it('Schema Proxy creates a JSON schema with title References using property name as default value', () => {
const proxied = loader()('proxy.schema.json', example);

assert.deepStrictEqual(proxied[titles], ['Example Proxy']);
assert.deepStrictEqual(proxied.properties.foo[titles], ['Example Proxy', undefined, 'foo']);
assert.deepStrictEqual(proxied.properties.bar[titles], ['Example Proxy', undefined, 'bar']);
});

it('Schema proxy resolves JSON Pointers', () => {
const myloader = loader();
const proxied1 = myloader('proxy.schema.json', example);
Expand Down

0 comments on commit cd1ce34

Please sign in to comment.