-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
71 lines (62 loc) · 1.73 KB
/
Copy pathmain.go
File metadata and controls
71 lines (62 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Package main demonstrates basic usage of the apibconv library.
package main
import (
"context"
"fmt"
"log"
"os"
"github.com/amer8/apibconv/pkg/converter"
"github.com/amer8/apibconv/pkg/format"
"github.com/amer8/apibconv/pkg/format/apiblueprint"
"github.com/amer8/apibconv/pkg/format/openapi"
)
func main() {
// Create a new converter instance
conv, err := converter.New(
converter.WithStrict(true),
converter.WithValidation(true, true),
)
if err != nil {
log.Fatalf("failed to create converter: %v", err)
}
// Register format parsers and writers
conv.RegisterParser(openapi.NewParser())
conv.RegisterWriter(openapi.NewWriter())
conv.RegisterParser(apiblueprint.NewParser())
conv.RegisterWriter(apiblueprint.NewWriter())
// Open input file from testdata
inputPath := "test/integration/testdata/openapi_v3_0.yaml"
fmt.Printf("Opening input from %s...\n", inputPath)
inputFile, err := os.Open(inputPath)
if err != nil {
log.Fatalf("failed to open input file: %v", err)
}
defer func() {
if err := inputFile.Close(); err != nil {
log.Printf("failed to close input file: %v", err)
}
}()
// Create output file
outputFile, err := os.Create("petstore.apib")
if err != nil {
log.Printf("failed to create output file: %v", err)
return
}
defer func() {
if cerr := outputFile.Close(); cerr != nil {
log.Printf("Error closing output file: %v", cerr)
}
}()
ctx := context.Background()
// Convert OpenAPI to API Blueprint
fmt.Println("Converting OpenAPI to API Blueprint...")
err = conv.Convert(ctx, inputFile, outputFile,
format.FormatOpenAPI,
format.FormatAPIBlueprint,
)
if err != nil {
log.Printf("conversion failed: %v", err)
return
}
fmt.Println("Conversion successful: petstore.apib created")
}