in report/api_test_report.go [177:250]
func generateApiTestMarkdownReport(result ApiTestReport, opCovReport coverage.CoverageReport, swaggerPath string, testReportPath string, apiTestConfigFilePath string) error {
var config ApiTestConfig
if utils.Exists(apiTestConfigFilePath) {
contentBytes, err := os.ReadFile(apiTestConfigFilePath)
if err != nil {
logrus.Errorf("error when opening file(%s): %+v", apiTestConfigFilePath, err)
}
err = json.Unmarshal(contentBytes, &config)
if err != nil {
logrus.Errorf("error during Unmarshal() for file(%s): %+v", apiTestConfigFilePath, err)
}
} else {
logrus.Debugf("no config file found")
}
mdTitle := "## API TEST ERROR REPORT<br>\n|Rule|Message|\n|---|---|"
mdTable := make([]string, 0)
testedMap := make(map[string]bool)
for _, v := range result.CoveredSpecFiles {
v = strings.ReplaceAll(v, "\\", "/")
testedMap[v] = true
}
swaggerFiles, err := utils.ListFiles(swaggerPath, ".json", 1)
if err != nil {
return err
}
for _, v := range swaggerFiles {
v = strings.ReplaceAll(v, "\\", "/")
if _, exists := testedMap[v]; !exists {
if !isSuppressedInApiTest(config.SuppressionList, "SWAGGER_NOT_TEST", v, "") {
mdTable = append(mdTable, fmt.Sprintf("|[SWAGGER_NOT_TEST](about:blank)|**message**: No operations in swagger is test.<br>**location**: %s", v[strings.Index(v, "/specification/"):]))
}
}
}
for _, operationsItem := range result.UnCoveredOperationsList {
for _, id := range operationsItem.OperationIds {
if !isSuppressedInApiTest(config.SuppressionList, "OPERATION_NOT_TEST", operationsItem.Spec, id) {
mdTable = append(mdTable, fmt.Sprintf("|[OPERATION_NOT_TEST](about:blank)|**message**: **%s** opeartion is not test.<br>**opeartion**: %s<br>**location**: %s", id, id, operationsItem.Spec[strings.Index(operationsItem.Spec, "/specification/"):]))
}
}
}
for _, errItem := range result.Errors {
location := errItem.Spec[strings.Index(errItem.Spec, "/specification/"):]
normalizedPath := filepath.ToSlash(errItem.SchemaPathWithPosition)
if subIndex := strings.Index(normalizedPath, "/specification/"); subIndex != -1 {
location = normalizedPath[subIndex:]
}
if !isSuppressedInApiTest(config.SuppressionList, errItem.ErrorCode, errItem.Spec, errItem.OperationId) {
mdTable = append(mdTable, fmt.Sprintf("|[%s](%s)|**message**: %s.<br>**opeartion**: %s<br>**location**: %s", errItem.ErrorCode, errItem.ErrorLink, errItem.ErrorMessage, errItem.OperationId, location))
}
}
sort.Strings(mdTable)
mdContent := mdTitle + "\n" + strings.Join(mdTable, "\n")
mdContent += opCovReport.MarkdownContentCompact()
mdReportFilePath := path.Join(testReportPath, fmt.Sprintf("%s.md", ApiTestReportFileName))
if err := os.WriteFile(mdReportFilePath, []byte(mdContent), 0644); err != nil {
return fmt.Errorf("error when writing file(%s): %+v", mdReportFilePath, err)
}
logrus.Infof("markdown report saved to %s", mdReportFilePath)
return nil
}