@@ -53,30 +53,30 @@ func Validate(document string) (ValidationResult, error) {
5353 return myResult , err
5454 }
5555
56- versionList := getVersionList (suppliedVersion )
56+ versionList , invalidVersions := getVersionList (suppliedVersion )
57+
58+ for _ , version := range invalidVersions {
59+ // Version not found. Thus, we cannot validate. Show an
60+ // error for the declared "api_compatibilty" and continue.
61+ myResult .Valid = false
62+ invalidVersionErrors := []ResultError {
63+ {
64+ "api_compatibility" ,
65+ "(root).api_compatibility" ,
66+ fmt .Sprintf ("Endpoint declares compatibility with schema version %s, which isn't supported" , version ),
67+ },
68+ }
69+ myResult .Schemas = append (myResult .Schemas , VersionValidationResult {
70+ version ,
71+ false ,
72+ invalidVersionErrors ,
73+ })
74+ myResult .Errors = append (myResult .Errors , invalidVersionErrors ... )
75+ }
5776
5877 for _ , version := range versionList {
59- schemaString , found := SpaceAPISchemas [version ]
60- if ! found {
61- // Version not found. Thus, we cannot validate. Show an
62- // error for the declared "api_compatibilty" and continue.
63- myResult .Valid = false
64- invalidVersionErrors := []ResultError {
65- {
66- "api_compatibility" ,
67- "(root).api_compatibility" ,
68- fmt .Sprintf ("Endpoint declares compatibility with schema version %s, which isn't supported" , version ),
69- },
70- }
71- myResult .Schemas = append (myResult .Schemas , VersionValidationResult {
72- version ,
73- false ,
74- invalidVersionErrors ,
75- })
76- myResult .Errors = append (myResult .Errors , invalidVersionErrors ... )
77- continue
78- }
79- var schema = gojsonschema .NewStringLoader (schemaString )
78+ schemaVersion := SpaceAPISchemas [version ]
79+ var schema = gojsonschema .NewStringLoader (schemaVersion )
8080 result , err := gojsonschema .Validate (schema , documentLoader )
8181 if err != nil {
8282 myResult .Valid = false
@@ -108,15 +108,27 @@ func Validate(document string) (ValidationResult, error) {
108108 return myResult , err
109109}
110110
111- func getVersionList (suppliedVersion spaceAPIVersion ) []string {
112- versionList := suppliedVersion .APICompatibility
113- oldVersion := strings .Replace (fmt .Sprintf ("%v" , suppliedVersion .API ), "0." , "" , 1 )
114- if oldVersion != "<nil>" {
115- versionList = append (versionList , oldVersion )
111+ func getVersionList (suppliedVersion spaceAPIVersion ) ([]string , []string ) {
112+ var versionList = []string {}
113+ var invalidVersions = []string {}
114+ for _ , v14version := range suppliedVersion .APICompatibility {
115+ if schema , found := SpaceApiVersioning [v14version ]; found && schema == V14 {
116+ versionList = append (versionList , v14version )
117+ } else {
118+ invalidVersions = append (invalidVersions , v14version )
119+ }
120+ }
121+ v12version := strings .Replace (fmt .Sprintf ("%v" , suppliedVersion .API ), "0." , "" , 1 )
122+ if v12version != "<nil>" {
123+ if schema , found := SpaceApiVersioning [v12version ]; found && schema == V12 {
124+ versionList = append (versionList , v12version )
125+ } else {
126+ invalidVersions = append (invalidVersions , v12version )
127+ }
116128 }
117129
118- if len (versionList ) == 0 {
119- versionList = []string {"14 " }
130+ if len (versionList ) == 0 && len ( invalidVersions ) == 0 {
131+ versionList = []string {"15 " }
120132 }
121- return versionList
133+ return versionList , invalidVersions
122134}
0 commit comments