11import get from "lodash/get"
22
33export const validateRefHasNoSiblings = ( ) => system => {
4- return Promise . all ( [
5- system . validateSelectors . all$refArtifacts ( ) ,
6- ] ) . then ( ( [ nodes ] ) => {
4+ return system . validateSelectors . all$refArtifacts ( )
5+ . then ( ( nodes ) => {
76 const immSpecJson = system . specSelectors . specJson ( )
87 const specJson = immSpecJson . toJS ? immSpecJson . toJS ( ) : { }
98
@@ -28,16 +27,9 @@ export const validateRefHasNoSiblings = () => system => {
2827
2928// Add warnings for unused definitions
3029export const validateUnusedDefinitions = ( ) => ( system ) => {
31- return Promise . all ( [
32- system . validateSelectors . all$refs ( ) ,
33- system . validateSelectors . all$refArtifacts ( )
34- ] ) . then ( ( [ refs , refArtifacts ] ) => {
35- const references = (
36- ( refs . length ? refs : null )
37- || ( refArtifacts . length ? refArtifacts : null )
38- || [ ]
39- ) . map ( node => node . node )
40-
30+ return system . validateSelectors . all$refArtifacts ( )
31+ . then ( ( nodes ) => {
32+ const references = nodes . map ( node => node . node )
4133 const errors = [ ]
4234
4335 system . specSelectors . definitions ( )
@@ -55,3 +47,29 @@ export const validateUnusedDefinitions = () => (system) => {
5547 return errors
5648 } )
5749}
50+
51+ export const validateRefPathFormatting = ( ) => ( system ) => {
52+ return system . validateSelectors . all$refArtifacts ( )
53+ . then ( ( refArtifacts ) => {
54+
55+ const errors = [ ]
56+ refArtifacts . forEach ( ( node ) => {
57+ const value = node . node
58+ if ( typeof value === "string" ) {
59+ // eslint-disable-next-line no-unused-vars
60+ const [ refUrl , refPath ] = value . split ( "#" )
61+
62+ if ( ! refPath || refPath [ 0 ] !== "/" ) {
63+ errors . push ( {
64+ // $ref instead of $$ref
65+ path : [ ...node . path . slice ( 0 , - 1 ) , "$ref" ] ,
66+ message : "$ref paths must begin with `#/`" ,
67+ level : "error"
68+ } )
69+ }
70+ }
71+ } )
72+
73+ return errors
74+ } )
75+ }
0 commit comments