Skip to content

Commit

Permalink
Generate valid path segments when path contains 10 or more subschemas.
Browse files Browse the repository at this point in the history
  • Loading branch information
fuku710 committed Oct 19, 2023
1 parent 9146b0f commit c6618c3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/util/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export { compose as composePaths };
*/
export const toDataPathSegments = (schemaPath: string): string[] => {
const s = schemaPath
.replace(/(anyOf|allOf|oneOf)\/[\d]\//g, '')
.replace(/(anyOf|allOf|oneOf)\/[\d]+\//g, '')
.replace(/(then|else)\//g, '');
const segments = s.split('/');

Expand Down
15 changes: 12 additions & 3 deletions packages/core/test/util/path.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ test('toDataPath ', (t) => {
t.is(toDataPath('#/properties/foo/properties/bar'), 'foo.bar');
});
test('toDataPath replace anyOf', (t) => {
t.is(toDataPath('/anyOf/1/properties/foo/anyOf/1/properties/bar'), 'foo.bar');
t.is(
toDataPath('/anyOf/11/properties/foo/anyOf/11/properties/bar'),
'foo.bar'
);
});
test('toDataPath replace anyOf in combination with conditional schema compositions', (t) => {
t.is(toDataPath('/anyOf/1/then/properties/foo'), 'foo');
Expand All @@ -59,7 +62,10 @@ test('toDataPath replace multiple nested properties with anyOf in combination wi
);
});
test('toDataPath replace allOf', (t) => {
t.is(toDataPath('/allOf/1/properties/foo/allOf/1/properties/bar'), 'foo.bar');
t.is(
toDataPath('/allOf/11/properties/foo/allOf/11/properties/bar'),
'foo.bar'
);
});
test('toDataPath replace allOf in combination with conditional schema compositions', (t) => {
t.is(toDataPath('/allOf/1/then/properties/foo'), 'foo');
Expand All @@ -74,7 +80,10 @@ test('toDataPath replace multiple nested properties with allOf in combination wi
);
});
test('toDataPath replace oneOf', (t) => {
t.is(toDataPath('/oneOf/1/properties/foo/oneOf/1/properties/bar'), 'foo.bar');
t.is(
toDataPath('/oneOf/11/properties/foo/oneOf/11/properties/bar'),
'foo.bar'
);
});
test('toDataPath replace oneOf in combination with conditional schema compositions', (t) => {
t.is(toDataPath('/oneOf/1/then/properties/foo'), 'foo');
Expand Down

0 comments on commit c6618c3

Please sign in to comment.