From 6767e07344d35af3ce6c03df71e5fc580f05e104 Mon Sep 17 00:00:00 2001 From: Heng Lu Date: Mon, 2 Sep 2024 12:40:20 +0800 Subject: [PATCH] remove duplicated error items --- CHANGELOG.md | 1 + report/api_test_report.go | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c8b59cf..6ce20be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ ENHANCEMENTS: BUG FIXES: - Fix a bug that undocumented swagger properties caused inaccurate coverage report +- Remove duplicated items in the error report. ## v0.14.0 FEATURES: diff --git a/report/api_test_report.go b/report/api_test_report.go index bc178ff..0491fc4 100644 --- a/report/api_test_report.go +++ b/report/api_test_report.go @@ -77,6 +77,19 @@ func OavValidateTraffic(traceDir string, swaggerPath string, outputDir string) ( return nil, fmt.Errorf("oav report is empty") } + // remove duplicated error items + errorMap := make(map[string]ErrorItem) + for _, errItem := range payload.Errors { + errorMap[fmt.Sprintf("%s-%s-%s-%s", errItem.ErrorCode, errItem.ErrorMessage, errItem.OperationId, errItem.SchemaPathWithPosition)] = errItem + } + + errors := make([]ErrorItem, 0) + for _, v := range errorMap { + errors = append(errors, v) + } + + payload.Errors = errors + return payload, nil }