Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add additional error message on swagger v2 to v3 convert #4254

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions cmd/server/woodpecker_docs_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ package main
import (
"context"
"encoding/json"
"fmt"
"os"
"path"

Expand Down Expand Up @@ -57,6 +58,7 @@ func main() {

// convert to OpenApi3
if err := toOpenApi3(filePath, filePath); err != nil {
fmt.Printf("converting '%s' from openapi v2 to v3 failed\n", filePath)
panic(err)
}
}
Expand All @@ -77,18 +79,18 @@ func removeHost(jsonIn string) (string, error) {
func toOpenApi3(input, output string) error {
data2, err := os.ReadFile(input)
if err != nil {
return err
return fmt.Errorf("read input: %w", err)
}

var doc2 openapi2.T
err = json.Unmarshal(data2, &doc2)
if err != nil {
return err
return fmt.Errorf("unmarshal input: %w", err)
}

doc3, err := openapi2conv.ToV3(&doc2)
if err != nil {
return err
return fmt.Errorf("convert openapi v2 to v3: %w", err)
}
err = doc3.Validate(context.Background())
if err != nil {
Expand All @@ -97,8 +99,12 @@ func toOpenApi3(input, output string) error {

data, err := json.Marshal(doc3)
if err != nil {
return err
return fmt.Errorf("Marshal converted: %w", err)
}

if err = os.WriteFile(output, data, 0o644); err != nil {
return fmt.Errorf("write output: %w", err)
}

return os.WriteFile(output, data, 0o644)
return nil
}