(path: JSONHeroPath | string)
| 38 | } |
| 39 | |
| 40 | function schemaPathFromPath(path: JSONHeroPath | string): JSONHeroPath { |
| 41 | const heroPath = typeof path === "string" ? new JSONHeroPath(path) : path; |
| 42 | |
| 43 | if (heroPath.isRoot) { |
| 44 | return heroPath; |
| 45 | } |
| 46 | |
| 47 | return heroPath.components.slice(1).reduce((acc, component) => { |
| 48 | if (component.isArray) { |
| 49 | return acc.child("items"); |
| 50 | } else { |
| 51 | return acc.child("properties").child(component.toString()); |
| 52 | } |
| 53 | }, new JSONHeroPath("$")); |
| 54 | } |