diff --git a/api/api_creator.go b/api/api_creator.go index 3bf4048..d104a37 100644 --- a/api/api_creator.go +++ b/api/api_creator.go @@ -33,7 +33,13 @@ func newCreator(logger *logrus.Entry) *creator { } func (c creator) getHandler(enforceValidJSON bool, headers []config.Header, dir, fileName string, file wrapper.IFileOps) func(w http.ResponseWriter, r *http.Request) { - path := fmt.Sprintf("%s/%s/%s", constants.APIDir, dir, fileName) + var path string + if len(fileName) > 0 { + path = fmt.Sprintf("%s/%s/%s", constants.APIDir, dir, fileName) + } else { + path = "" + } + contextLogger := c.log.WithFields(logrus.Fields{ log.FuncField: "handler for mock API", "enforceValidJSON": enforceValidJSON, @@ -53,6 +59,10 @@ func getJSONHandler(path string, headers []config.Header, file wrapper.IFileOps, w.Header().Set(header.Key, header.Value) } + if len(path) == 0 { + return + } + bytes, err := json.GetJSON(path, file) if err != nil { logger.WithError(err).Error("error serving JSON from this endpoint") @@ -70,6 +80,10 @@ func getGeneralHandler(path string, headers []config.Header, file wrapper.IFileO w.Header().Set(header.Key, header.Value) } + if len(path) == 0 { + return + } + fileInfo, err := file.Open(path) defer fileInfo.Close() if err != nil { diff --git a/mockApis/exampleStudentsApi/studentsApi.toml b/mockApis/exampleStudentsApi/studentsApi.toml index 0c1d19f..414022c 100644 --- a/mockApis/exampleStudentsApi/studentsApi.toml +++ b/mockApis/exampleStudentsApi/studentsApi.toml @@ -17,7 +17,6 @@ keyFile = "" [endpoints.getStudents] path = "students" - file = "students.json" method = "GET" [endpoints.getNothing]