Skip to content

Commit

Permalink
suppress error message for base discriminator prop match
Browse files Browse the repository at this point in the history
  • Loading branch information
teowa committed Sep 11, 2024
1 parent bc1d049 commit ffd1d0a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
13 changes: 8 additions & 5 deletions coverage/coverage.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,14 @@ func (m *Model) CredScan(root interface{}, secrets map[string]string) {
if isMatchProperty {
for k, v := range value {
if m.Properties == nil {
if !m.HasAdditionalProperties {
logrus.Errorf("unexpected key %s in %s", k, m.Identifier)
}
// some objects has no properties defined
// https://github.com/Azure/azure-rest-api-specs/blob/3519c80fe510a268f6e59a29ccac8a53fdec15b6/specification/monitor/resource-manager/Microsoft.Insights/stable/2023-03-11/dataCollectionRules_API.json#L724

logrus.Warnf("unexpected key %s in %s", k, m.Identifier)
continue
}
if _, ok := (*m.Properties)[k]; !ok {
if !m.HasAdditionalProperties {
if !m.HasAdditionalProperties && m.Discriminator == nil {
logrus.Errorf("unexpected key %s in %s", k, m.Identifier)
continue
}
Expand Down Expand Up @@ -194,10 +195,12 @@ func (m *Model) MarkCovered(root interface{}) {
if m.Properties == nil {
// some objects has no properties defined
// https://github.com/Azure/azure-rest-api-specs/blob/3519c80fe510a268f6e59a29ccac8a53fdec15b6/specification/monitor/resource-manager/Microsoft.Insights/stable/2023-03-11/dataCollectionRules_API.json#L724
logrus.Warnf("unexpected key %s in %s", k, m.Identifier)

continue
}
if _, ok := (*m.Properties)[k]; !ok {
if !m.HasAdditionalProperties {
if !m.HasAdditionalProperties && m.Discriminator == nil {
logrus.Errorf("unexpected key %s in %s", k, m.Identifier)
continue
}
Expand Down
22 changes: 22 additions & 0 deletions coverage/coverage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,28 @@ func TestCoverage_ResourceGroup(t *testing.T) {
}
}

func TestCoverage_AzureTerraform(t *testing.T) {
tc := testCase{
name: "AzureTerraform",
resourceType: "Microsoft.AzureTerraform@2023-07-01-preview",
method: "POST",
apiPath: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.AzureTerraform/exportTerraform",
expectedCoveredCount: 3,
expectedTotalCount: 25,
rawRequest: []string{
`{
"resourceGroupName" : "rg1",
"type" : "ExportResourceGroup"
}`,
},
}

_, err := testCoverage(t, tc)
if err != nil {
t.Fatalf("process coverage: %+v", err)
}
}

func TestCoverage_HealthcareDicom(t *testing.T) {
tc := testCase{
name: "HealthcareApisDicom",
Expand Down

0 comments on commit ffd1d0a

Please sign in to comment.