Skip to content

Commit c7ffa69

Browse files
incremental validation framework
1 parent 9acb496 commit c7ffa69

File tree

2 files changed

+39
-11
lines changed

2 files changed

+39
-11
lines changed

tools/spectral/ipa/metrics/main.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ func main() {
1717
tagsPath := "split_specs/tags"
1818
sharedComponentPath := "split_specs/shared_components.yaml" // Input: shared schema file
1919
mergedSpecPath := "output/merged_spec.yaml" // Temporary file to hold the merged spec
20-
spectralRulesetPath := "../ipa-spectral.yaml" // Spectral ruleset file
20+
deletedMergedSpecPath := "output/merged_spec_deleted.yaml" // Temporary file to hold the merged spec
21+
22+
spectralRulesetPath := "../ipa-spectral.yaml" // Spectral ruleset file
2123

2224
// Create output directory if it doesn't exist
2325
if err := os.MkdirAll("output", 0755); err != nil {
@@ -40,21 +42,22 @@ func main() {
4042
}
4143
}
4244

45+
//Collect all the spec files which have deleted paths
46+
var deletedTagsFiles []string
4347
for tag := range deletedTags {
4448
tagDir := filepath.Join(tagsPath, tag)
4549
tagFilePath := filepath.Join(tagDir, "spec-deleted.yaml")
50+
deletedTagsFiles = append(deletedTagsFiles, tagFilePath)
51+
}
4652

47-
//check if there is a deleted component file, and if there is merge with it
48-
//otherwise, merge with the shared components file
49-
if err := utils.RebuildFullSpec(tagFilePath, sharedComponentPath, mergedSpecPath); err != nil {
50-
log.Fatalf("Failed to merge specs: %v", err)
51-
}
52-
fmt.Printf("Merged spec written to: %s\n", mergedSpecPath)
53+
if err := utils.RebuildFullDeletedPathsSpec(deletedTagsFiles, sharedComponentPath, deletedMergedSpecPath); err != nil {
54+
log.Fatalf("Failed to merge specs: %v", err)
55+
}
56+
fmt.Printf("Merged spec written to: %s\n", deletedMergedSpecPath)
5357

54-
//Lint the merged spec with Spectral
55-
if err := utils.LintSpecWithSpectral(mergedSpecPath, spectralRulesetPath); err != nil {
56-
log.Fatalf("Failed to lint spec with Spectral: %v", err)
57-
}
58+
//Lint the merged spec with Spectral
59+
if err := utils.LintSpecWithSpectral(deletedMergedSpecPath, spectralRulesetPath); err != nil {
60+
log.Fatalf("Failed to lint spec with Spectral: %v", err)
5861
}
5962

6063
}

tools/spectral/ipa/metrics/utils/rebuild_full_spec.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,31 @@ func loadSpecYAMLFile(filePath string) (*OpenAPISpec, error) {
2222
return &spec, nil
2323
}
2424

25+
func RebuildFullDeletedPathsSpec(tagFiles []string, sharedSchemasFile string, outputFile string) error {
26+
loader := openapi3.NewLoader()
27+
28+
componentsSpec, err := loadSpec(loader, sharedSchemasFile)
29+
if err != nil {
30+
return fmt.Errorf("failed to load shared schemas: %v", err)
31+
}
32+
33+
var deletedPathsSpec OpenAPISpec
34+
// Merge tag-specific paths
35+
for _, tagFile := range tagFiles {
36+
tagSpec, err := loadSpecYAMLFile(tagFile)
37+
if err != nil {
38+
return fmt.Errorf("failed to load tag file %s: %v", tagFile, err)
39+
}
40+
for path, pathItem := range tagSpec.Paths {
41+
deletedPathsSpec.Paths[path] = pathItem
42+
}
43+
}
44+
45+
deletedPathsSpec.Components = componentsSpec.Spec.Components
46+
47+
return saveYAML(outputFile, deletedPathsSpec)
48+
}
49+
2550
func RebuildFullSpec(tagFile string, sharedSchemasFile string, outputFile string) error {
2651
loader := openapi3.NewLoader()
2752

0 commit comments

Comments
 (0)