Skip to content

Commit

Permalink
Add metadata to conformance report (#680)
Browse files Browse the repository at this point in the history
* Add metadata to conformance report

* Add doc_uri in metadata
  • Loading branch information
shrutiparabgoogle authored Aug 9, 2022
1 parent 213371d commit 8b58a46
Show file tree
Hide file tree
Showing 33 changed files with 212 additions and 99 deletions.
97 changes: 69 additions & 28 deletions cmd/registry/cmd/compute/conformance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"bytes"
"compress/gzip"
"context"
"fmt"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -78,8 +79,11 @@ func TestConformance(t *testing.T) {
Severity: rpc.Rule_ERROR,
RuleReports: []*rpc.RuleReport{
{
RuleId: "norefsiblings",
Spec: "projects/conformance-test/locations/global/apis/petstore/versions/1.0.0/specs/openapi.yaml",
RuleId: "norefsiblings",
Spec: "projects/conformance-test/locations/global/apis/petstore/versions/1.0.0/specs/openapi.yaml",
DisplayName: "No $ref siblings",
Description: "An object exposing a $ref property cannot be further extended with additional properties.",
DocUri: "https://meta.stoplight.io/docs/spectral/4dec24461f3af-open-api-rules#no-ref-siblings",
},
},
},
Expand Down Expand Up @@ -115,8 +119,10 @@ func TestConformance(t *testing.T) {
Severity: rpc.Rule_SEVERITY_UNSPECIFIED,
RuleReports: []*rpc.RuleReport{
{
RuleId: "norefsiblings",
Spec: "projects/conformance-test/locations/global/apis/petstore/versions/1.0.0/specs/openapi.yaml",
RuleId: "norefsiblings",
Spec: "projects/conformance-test/locations/global/apis/petstore/versions/1.0.0/specs/openapi.yaml",
DisplayName: "No $ref siblings",
Description: "An object exposing a $ref property cannot be further extended with additional properties.",
},
},
},
Expand Down Expand Up @@ -158,12 +164,16 @@ func TestConformance(t *testing.T) {
Severity: rpc.Rule_ERROR,
RuleReports: []*rpc.RuleReport{
{
RuleId: "operationtags",
Spec: "projects/conformance-test/locations/global/apis/petstore/versions/1.0.0/specs/openapi.yaml",
RuleId: "operationtags",
Spec: "projects/conformance-test/locations/global/apis/petstore/versions/1.0.0/specs/openapi.yaml",
DisplayName: "Operation tags",
Description: "Operation should have non-empty tags array.",
},
{
RuleId: "operationtagdefined",
Spec: "projects/conformance-test/locations/global/apis/petstore/versions/1.0.0/specs/openapi.yaml",
RuleId: "operationtagdefined",
Spec: "projects/conformance-test/locations/global/apis/petstore/versions/1.0.0/specs/openapi.yaml",
DisplayName: "Operation tag defined",
Description: "Operation tags should be defined in global tags.",
},
},
},
Expand All @@ -172,12 +182,16 @@ func TestConformance(t *testing.T) {
Severity: rpc.Rule_INFO,
RuleReports: []*rpc.RuleReport{
{
RuleId: "openapitags",
Spec: "projects/conformance-test/locations/global/apis/petstore/versions/1.0.0/specs/openapi.yaml",
RuleId: "openapitags",
Spec: "projects/conformance-test/locations/global/apis/petstore/versions/1.0.0/specs/openapi.yaml",
DisplayName: "OpenAPI tags",
Description: "OpenAPI object should have non-empty tags array.",
},
{
RuleId: "openapitagsalphabetical",
Spec: "projects/conformance-test/locations/global/apis/petstore/versions/1.0.0/specs/openapi.yaml",
RuleId: "openapitagsalphabetical",
Spec: "projects/conformance-test/locations/global/apis/petstore/versions/1.0.0/specs/openapi.yaml",
DisplayName: "OpenAPI tags alphabetical",
Description: "OpenAPI object should have alphabetical tags. This will be sorted by the name property.",
},
},
},
Expand Down Expand Up @@ -213,8 +227,10 @@ func TestConformance(t *testing.T) {
Severity: rpc.Rule_ERROR,
RuleReports: []*rpc.RuleReport{
{
RuleId: "operationtags",
Spec: "projects/conformance-test/locations/global/apis/petstore/versions/1.0.0/specs/openapi.yaml",
RuleId: "operationtags",
Spec: "projects/conformance-test/locations/global/apis/petstore/versions/1.0.0/specs/openapi.yaml",
DisplayName: "Operation tags",
Description: "Operation should have non-empty tags array.",
},
},
},
Expand All @@ -223,8 +239,10 @@ func TestConformance(t *testing.T) {
Severity: rpc.Rule_INFO,
RuleReports: []*rpc.RuleReport{
{
RuleId: "openapitags",
Spec: "projects/conformance-test/locations/global/apis/petstore/versions/1.0.0/specs/openapi.yaml",
RuleId: "openapitags",
Spec: "projects/conformance-test/locations/global/apis/petstore/versions/1.0.0/specs/openapi.yaml",
DisplayName: "OpenAPI tags",
Description: "OpenAPI object should have non-empty tags array.",
},
},
},
Expand All @@ -244,8 +262,10 @@ func TestConformance(t *testing.T) {
Severity: rpc.Rule_ERROR,
RuleReports: []*rpc.RuleReport{
{
RuleId: "norefsiblings",
Spec: "projects/conformance-test/locations/global/apis/petstore/versions/1.0.0/specs/openapi.yaml",
RuleId: "norefsiblings",
Spec: "projects/conformance-test/locations/global/apis/petstore/versions/1.0.0/specs/openapi.yaml",
DisplayName: "No $ref siblings",
Description: "An object exposing a $ref property cannot be further extended with additional properties.",
},
},
},
Expand Down Expand Up @@ -283,30 +303,38 @@ func TestConformance(t *testing.T) {
Severity: rpc.Rule_ERROR,
RuleReports: []*rpc.RuleReport{
{
RuleId: "operationdescription",
Spec: "projects/conformance-test/locations/global/apis/petstore/versions/1.0.0/specs/openapi.yaml",
RuleId: "operationdescription",
Spec: "projects/conformance-test/locations/global/apis/petstore/versions/1.0.0/specs/openapi.yaml",
DisplayName: "Operation description",
Description: "Operation should have non-empty description.",
},
{
RuleId: "infodescription",
Spec: "projects/conformance-test/locations/global/apis/petstore/versions/1.0.0/specs/openapi.yaml",
RuleId: "infodescription",
Spec: "projects/conformance-test/locations/global/apis/petstore/versions/1.0.0/specs/openapi.yaml",
DisplayName: "Info description",
Description: "OpenAPI object info description must be present and non-empty string.",
},
},
},
{
Severity: rpc.Rule_WARNING,
RuleReports: []*rpc.RuleReport{
{
RuleId: "descriptiontags",
Spec: "projects/conformance-test/locations/global/apis/petstore/versions/1.0.0/specs/openapi.yaml",
RuleId: "descriptiontags",
Spec: "projects/conformance-test/locations/global/apis/petstore/versions/1.0.0/specs/openapi.yaml",
DisplayName: "Description tags",
Description: "Ensures that description fields in the OpenAPI spec contain no tags (such as HTML tags).",
},
},
},
{
Severity: rpc.Rule_INFO,
RuleReports: []*rpc.RuleReport{
{
RuleId: "tagdescription",
Spec: "projects/conformance-test/locations/global/apis/petstore/versions/1.0.0/specs/openapi.yaml",
RuleId: "tagdescription",
Spec: "projects/conformance-test/locations/global/apis/petstore/versions/1.0.0/specs/openapi.yaml",
DisplayName: "Tag description",
Description: "Tags alone are not very descriptive. Give folks a bit more information to work with.",
},
},
},
Expand All @@ -326,8 +354,10 @@ func TestConformance(t *testing.T) {
Severity: rpc.Rule_ERROR,
RuleReports: []*rpc.RuleReport{
{
RuleId: "norefsiblings",
Spec: "projects/conformance-test/locations/global/apis/petstore/versions/1.0.0/specs/openapi.yaml",
RuleId: "norefsiblings",
Spec: "projects/conformance-test/locations/global/apis/petstore/versions/1.0.0/specs/openapi.yaml",
DisplayName: "No $ref siblings",
Description: "An object exposing a $ref property cannot be further extended with additional properties.",
},
},
},
Expand Down Expand Up @@ -451,6 +481,17 @@ func TestConformance(t *testing.T) {
t.Fatalf("Failed getting artifact contents %s: %s", test.getPattern, err)
}

// Add revision ID in wantProto
for _, g := range test.wantProto.GuidelineReportGroups {
for _, gr := range g.GetGuidelineReports() {
for _, r := range gr.RuleReportGroups {
for _, report := range r.RuleReports {
report.Spec = fmt.Sprintf("%s@%s", report.Spec, spec.RevisionId)
}
}
}
}

gotProto := &rpc.ConformanceReport{}
if err := proto.Unmarshal(contents.GetData(), gotProto); err != nil {
t.Fatalf("Failed to unmarshal artifact: %s", err)
Expand Down
1 change: 1 addition & 0 deletions cmd/registry/cmd/compute/testdata/styleguide-default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ guidelines:
description: This guideline governs properties for ref fields on specs.
rules:
- id: norefsiblings
display_name: No $ref siblings
description: An object exposing a $ref property cannot be further extended with additional properties.
linter: sample
linter_rulename: no-$ref-siblings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ guidelines:
description: This guideline governs properties for ref fields on specs.
rules:
- id: norefsiblings
display_name: No $ref siblings
description: An object exposing a $ref property cannot be further extended with additional properties.
linter: sample
linter_rulename: no-$ref-siblings
Expand All @@ -31,21 +32,25 @@ guidelines:
description: This guideline specifies rules for different tags.
rules:
- id: tagdescription
display_name: Tag description
description: Tags alone are not very descriptive. Give folks a bit more information to work with.
linter: sample
linter_rulename: tag-description
severity: INFO
- id: operationdescription
display_name: Operation description
description: Operation should have non-empty description.
linter: sample
linter_rulename: operation-description
severity: ERROR
- id: infodescription
display_name: Info description
description: OpenAPI object info description must be present and non-empty string.
linter: sample
linter_rulename: info-description
severity: ERROR
- id: descriptiontags
display_name: Description tags
description: Ensures that description fields in the OpenAPI spec contain no tags (such as HTML tags).
linter: openapi-sample
linter_rulename: description-contains-no-tags
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,25 @@ guidelines:
description: This guideline specifies rules for different tags.
rules:
- id: openapitags
display_name: OpenAPI tags
description: OpenAPI object should have non-empty tags array.
linter: sample
linter_rulename: openapi-tags
severity: INFO
- id: openapitagsalphabetical
display_name: OpenAPI tags alphabetical
description: OpenAPI object should have alphabetical tags. This will be sorted by the name property.
linter: sample
linter_rulename: openapi-tags-alphabetical
severity: INFO
- id: operationtags
display_name: Operation tags
description: Operation should have non-empty tags array.
linter: sample
linter_rulename: operation-tags
severity: ERROR
- id: operationtagdefined
display_name: Operation tag defined
description: Operation tags should be defined in global tags.
linter: sample
linter_rulename: operation-tag-defined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ guidelines:
description: This guideline governs properties for ref fields on specs.
rules:
- id: norefsiblings
display_name: No $ref siblings
description: An object exposing a $ref property cannot be further extended with additional properties.
linter: sample
linter_rulename: no-$ref-siblings
Expand All @@ -31,11 +32,13 @@ guidelines:
description: This guideline specifies rules for different tags.
rules:
- id: openapitags
display_name: OpenAPI tags
description: OpenAPI object should have non-empty tags array.
linter: sample
linter_rulename: openapi-tags
severity: INFO
- id: operationtags
display_name: Operation tags
description: Operation should have non-empty tags array.
linter: sample
linter_rulename: operation-tags
Expand Down
2 changes: 2 additions & 0 deletions cmd/registry/cmd/compute/testdata/styleguide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ guidelines:
description: This guideline governs properties for ref fields on specs.
rules:
- id: norefsiblings
display_name: No $ref siblings
description: An object exposing a $ref property cannot be further extended with additional properties.
linter: sample
linter_rulename: no-$ref-siblings
severity: ERROR
doc_uri: https://meta.stoplight.io/docs/spectral/4dec24461f3af-open-api-rules#no-ref-siblings
state: ACTIVE
linters:
- name: sample
Expand Down
13 changes: 8 additions & 5 deletions cmd/registry/conformance/conformance-task.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,14 @@ func (task *ComputeConformanceTask) computeConformanceReport(
}

ruleReport := &rpc.RuleReport{
RuleId: guidelineRule.GetId(),
Spec: task.Spec.GetName(),
File: filepath.Base(lintFile.GetFilePath()),
Suggestion: problem.Suggestion,
Location: problem.Location,
RuleId: guidelineRule.GetId(),
Spec: fmt.Sprintf("%s@%s", task.Spec.GetName(), task.Spec.GetRevisionId()),
File: filepath.Base(lintFile.GetFilePath()),
Suggestion: problem.Suggestion,
Location: problem.Location,
DisplayName: guidelineRule.GetDisplayName(),
Description: guidelineRule.GetDescription(),
DocUri: guidelineRule.GetDocUri(),
}
// Add the rule report to the appropriate guideline report.
guidelineGroup := conformanceReport.GuidelineReportGroups[guideline.GetState()]
Expand Down
Loading

0 comments on commit 8b58a46

Please sign in to comment.