mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-09-20 20:19:19 +00:00
Add additionall error message on swagger v2 to v3 convert (#4254)
Co-authored-by: Anbraten <6918444+anbraten@users.noreply.github.com>
This commit is contained in:
@@ -24,6 +24,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
|
||||||
@@ -57,6 +58,7 @@ func main() {
|
|||||||
|
|
||||||
// convert to OpenApi3
|
// convert to OpenApi3
|
||||||
if err := toOpenApi3(filePath, filePath); err != nil {
|
if err := toOpenApi3(filePath, filePath); err != nil {
|
||||||
|
fmt.Printf("converting '%s' from openapi v2 to v3 failed\n", filePath)
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -77,18 +79,18 @@ func removeHost(jsonIn string) (string, error) {
|
|||||||
func toOpenApi3(input, output string) error {
|
func toOpenApi3(input, output string) error {
|
||||||
data2, err := os.ReadFile(input)
|
data2, err := os.ReadFile(input)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return fmt.Errorf("read input: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var doc2 openapi2.T
|
var doc2 openapi2.T
|
||||||
err = json.Unmarshal(data2, &doc2)
|
err = json.Unmarshal(data2, &doc2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return fmt.Errorf("unmarshal input: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
doc3, err := openapi2conv.ToV3(&doc2)
|
doc3, err := openapi2conv.ToV3(&doc2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return fmt.Errorf("convert openapi v2 to v3: %w", err)
|
||||||
}
|
}
|
||||||
err = doc3.Validate(context.Background())
|
err = doc3.Validate(context.Background())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -97,8 +99,12 @@ func toOpenApi3(input, output string) error {
|
|||||||
|
|
||||||
data, err := json.Marshal(doc3)
|
data, err := json.Marshal(doc3)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return fmt.Errorf("Marshal converted: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return os.WriteFile(output, data, 0o644)
|
if err = os.WriteFile(output, data, 0o644); err != nil {
|
||||||
|
return fmt.Errorf("write output: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user