/
main.go
51 lines (41 loc) · 1009 Bytes
/
main.go
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
// Copyright 2022 The Go Language Server Authors
// SPDX-License-Identifier: BSD-3-Clause
// Command openapi2protobuf generates Protocol Buffers v3 and gRPC services definitions from the OpenAPI/Swagger schema.
package main
import (
"context"
"fmt"
"log"
"os"
"go.lsp.dev/openapi2protobuf/compiler"
"go.lsp.dev/openapi2protobuf/internal/conv"
"go.lsp.dev/openapi2protobuf/openapi"
)
func init() {
conv.RegisterAcronyms(
[]string{
"NFT",
"DID",
"IDs",
},
)
}
func main() {
if err := run(os.Args[1:]); err != nil {
log.Fatal(err)
}
}
func run(args []string) error {
f := args[0]
pkgname := args[1]
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
schema, err := openapi.LoadFile(ctx, f)
if err != nil {
return fmt.Errorf("could not load %s OpenAPI file: %w", f, err)
}
if _, err = compiler.Compile(ctx, schema, compiler.WithPackageName(pkgname)); err != nil {
return fmt.Errorf("could not compile file descriptor: %w", err)
}
return nil
}