Skip to content

Commit

Permalink
post review and rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitrii Tikhomirov authored and Dmitrii Tikhomirov committed Nov 3, 2024
1 parent fc1c64a commit 8e6fc38
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
13 changes: 7 additions & 6 deletions packages/kn-plugin-workflow/pkg/specs/openapi_minifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"fmt"
"io"
"os"
"path"
"path/filepath"
"strings"

Expand Down Expand Up @@ -67,7 +68,7 @@ func (m *OpenApiMinifier) Minify() (map[string]string, error) {

m.findSubflowsFiles(m.params)

if err := m.processFunctions(); err != nil {
if err := m.fetchSpecFromFunctions(); err != nil {
return nil, err
}

Expand All @@ -83,17 +84,17 @@ func (m *OpenApiMinifier) Minify() (map[string]string, error) {
return minifySpecsFiles, nil
}

func (m *OpenApiMinifier) processFunctions() error {
func (m *OpenApiMinifier) fetchSpecFromFunctions() error {
for _, workflowFile := range m.workflows {
err := m.processFunction(workflowFile)
err := m.fetchSpecFromFunction(workflowFile)
if err != nil {
return err
}
}
return nil
}

func (m *OpenApiMinifier) processFunction(workflowFile string) error {
func (m *OpenApiMinifier) fetchSpecFromFunction(workflowFile string) error {
workflow, err := m.GetWorkflow(workflowFile)
if err != nil {
return err
Expand All @@ -107,15 +108,15 @@ func (m *OpenApiMinifier) processFunction(workflowFile string) error {

for _, function := range workflow.Functions {
if strings.HasPrefix(function.Operation, relativePath) {
trimmedPrefix := strings.TrimPrefix(function.Operation, relativePath+string(os.PathSeparator))
trimmedPrefix := strings.TrimPrefix(function.Operation, relativePath+"/")
if !strings.Contains(trimmedPrefix, "#") {
return fmt.Errorf("Invalid operation format in function: %s", function.Operation)
}
parts := strings.SplitN(trimmedPrefix, "#", 2)
if len(parts) != 2 {
return fmt.Errorf("❌ ERROR: Invalid operation format: %s", function.Operation)
}
apiFileName := parts[0]
apiFileName := path.Base(parts[0])
operation := parts[1]

if _, ok := m.operations[apiFileName]; !ok {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func checkResult(t *testing.T, test minifyTest, minifiedFiles map[string]string)
minified := minifiedFiles[file]
data, err := os.ReadFile(minified)
if err != nil {
t.Fatalf("Error reading minified file: %v", err)
t.Fatalf("Error reading minified file %s: %v", minified, err)
}
doc, err := openapi3.NewLoader().LoadFromData(data)
for _, value := range doc.Paths.Map() {
Expand All @@ -234,15 +234,15 @@ func checkResult(t *testing.T, test minifyTest, minifiedFiles map[string]string)
func parseFunctions(t *testing.T, functions map[string]sets.Set[string], workflow *v1alpha08.Flow, test minifyTest) {
for _, function := range workflow.Functions {
if strings.HasPrefix(function.Operation, test.specsDir) {
trimmedPrefix := strings.TrimPrefix(function.Operation, test.specsDir+string(os.PathSeparator))
trimmedPrefix := strings.TrimPrefix(function.Operation, test.specsDir+"/")
if !strings.Contains(trimmedPrefix, "#") {
t.Fatalf("Invalid operation format in function: %s", function.Operation)
}
parts := strings.SplitN(trimmedPrefix, "#", 2)
if len(parts) != 2 {
t.Fatalf("Invalid operation format: %s", function.Operation)
}
apiFileName := parts[0]
apiFileName := path.Base(parts[0])
operation := parts[1]

if _, ok := functions[apiFileName]; !ok {
Expand Down

0 comments on commit 8e6fc38

Please sign in to comment.