Skip to content

Commit 23904f5

Browse files
committed
using aep-lib-go
now that proto generation has been properly upstreamed, we can leverage LROs from the aep-lib-go instead. This vastly reduces the code in aepc.
1 parent 37a23aa commit 23904f5

14 files changed

Lines changed: 116 additions & 3794 deletions

File tree

cmd/root.go

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,12 @@ import (
2222

2323
"github.com/ghodss/yaml"
2424

25-
"github.com/aep-dev/aepc/loader"
26-
"github.com/aep-dev/aepc/parser"
27-
"github.com/aep-dev/aepc/schema"
25+
"encoding/json"
26+
27+
"github.com/aep-dev/aep-lib-go/pkg/api"
28+
"github.com/aep-dev/aep-lib-go/pkg/proto"
2829
"github.com/aep-dev/aepc/validator"
29-
"github.com/aep-dev/aepc/writer/proto"
3030
"github.com/spf13/cobra"
31-
"google.golang.org/protobuf/encoding/protojson"
3231
)
3332

3433
func NewCommand() *cobra.Command {
@@ -53,26 +52,22 @@ func NewCommand() *cobra.Command {
5352

5453
func ProcessInput(inputFile, outputFilePrefix string) error {
5554
outputDir := filepath.Dir(outputFilePrefix)
56-
s := &schema.Service{}
55+
var a api.API
5756
input, err := ReadFile(inputFile)
5857
fmt.Printf("input: %s\n", string(input))
5958
if err != nil {
6059
return fmt.Errorf("unable to read file: %w", err)
6160
}
6261
ext := filepath.Ext(inputFile)
63-
err = unmarshal(ext, input, s)
62+
err = unmarshal(ext, input, &a)
6463
if err != nil {
6564
return fmt.Errorf("unable to unmarshal file: %w", err)
6665
}
67-
errors := validator.ValidateService(s)
66+
errors := validator.ValidateAPI(&a)
6867
if len(errors) > 0 {
6968
return fmt.Errorf("error validating service: %v", errors)
7069
}
71-
api, err := parser.ToAPI(s)
72-
if err != nil {
73-
return fmt.Errorf("error building api: %w", err)
74-
}
75-
proto, err := proto.WriteServiceToProto(api, outputDir)
70+
proto, err := proto.APIToProtoString(&a, outputDir)
7671
if err != nil {
7772
return fmt.Errorf("error writing service proto: %w", err)
7873
}
@@ -82,7 +77,7 @@ func ProcessInput(inputFile, outputFilePrefix string) error {
8277
return fmt.Errorf("error writing file: %w", err)
8378
}
8479
fmt.Printf("output proto file: %s\n", protoFile)
85-
openapi, err := api.ConvertToOpenAPIBytes()
80+
openapi, err := a.ConvertToOpenAPIBytes()
8681
if err != nil {
8782
return fmt.Errorf("error building openapi: %w", err)
8883
}
@@ -105,22 +100,18 @@ func ProcessInput(inputFile, outputFilePrefix string) error {
105100
return nil
106101
}
107102

108-
func unmarshal(ext string, b []byte, s *schema.Service) error {
103+
func unmarshal(ext string, b []byte, a *api.API) error {
109104
switch ext {
110-
case ".proto":
111-
if err := loader.ReadServiceFromProto(b, s); err != nil {
112-
return fmt.Errorf("unable to decode proto %q: %w", string(b), err)
113-
}
114105
case ".yaml":
115106
asJson, err := yaml.YAMLToJSON(b)
116107
if err != nil {
117108
return fmt.Errorf("unable to decode yaml to JSON %q: %w", string(b), err)
118109
}
119-
if err := protojson.Unmarshal(asJson, s); err != nil {
110+
if err := json.Unmarshal(asJson, a); err != nil {
120111
log.Fatal(fmt.Errorf("unable to decode proto %q: %w", string(b), err))
121112
}
122113
case ".json":
123-
if err := protojson.Unmarshal(b, s); err != nil {
114+
if err := json.Unmarshal(b, a); err != nil {
124115
return fmt.Errorf("unable to decode json %q: %w", string(b), err)
125116
}
126117
default:

example/bookstore/v1/bookstore.yaml

Lines changed: 64 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ resources:
88
# example of a simple resource
99
- kind: "publisher"
1010
plural: "publishers"
11-
properties:
12-
description:
13-
type: STRING
14-
number: 1
11+
schema:
12+
type: "object"
13+
properties:
14+
description:
15+
type: string
16+
x-aep-field-number: 1
1517
methods:
1618
create: {}
1719
read: {}
@@ -28,34 +30,33 @@ resources:
2830
# kind.
2931
parents:
3032
- "publisher"
31-
properties:
32-
isbn:
33-
array_type:
34-
type: STRING
35-
number: 1
36-
required: true
37-
price:
38-
type: FLOAT
39-
number: 2
40-
required: true
41-
published:
42-
type: BOOLEAN
43-
number: 3
44-
required: true
45-
edition:
46-
type: INT32
47-
number: 4
48-
required: false
49-
author:
50-
array_type:
51-
object_type:
33+
schema:
34+
type: "object"
35+
required: ["author", "isbn", "price", "published"]
36+
properties:
37+
isbn:
38+
items:
39+
type: string
40+
x-aep-field-number: 1
41+
price:
42+
type: float
43+
x-aep-field-number: 2
44+
published:
45+
type: boolean
46+
x-aep-field-number: 3
47+
edition:
48+
type: integer
49+
x-aep-field-number: 4
50+
author:
51+
x-aep-field-number: 5
52+
items:
5253
properties:
5354
firstName:
54-
type: STRING
55-
number: 1
55+
type: string
56+
x-aep-field-number: 1
5657
lastName:
57-
type: STRING
58-
number: 2
58+
type: string
59+
x-aep-field-number: 2
5960
methods:
6061
create: {}
6162
read: {}
@@ -68,13 +69,14 @@ resources:
6869
- name: "archive"
6970
method_type: POST
7071
request:
71-
object_type:
72-
properties: {}
72+
type: "object"
73+
properties: {}
7374
response:
74-
object_type:
75-
properties:
76-
success:
77-
type: BOOLEAN
75+
type: "object"
76+
properties:
77+
success:
78+
type: boolean
79+
x-aep-field-number: 1
7880
# other example resources that might be interesting to add:
7981
# authors, which could be a reference for book
8082
# authors could have a reference to publishers too
@@ -86,22 +88,43 @@ resources:
8688
# kind.
8789
parents:
8890
- "book"
89-
properties:
90-
displayname:
91-
type: STRING
92-
number: 1
93-
required: true
91+
schema:
92+
required: ["displayname"]
93+
type: "object"
94+
properties:
95+
displayname:
96+
x-aep-field-number: 1
97+
type: string
9498
methods:
9599
create: {}
96100
read: {}
97101
list: {}
98102
delete: {}
99103
- kind: "isbn"
100104
plural: "isbns"
101-
properties: {}
105+
schema:
106+
type: "object"
102107
methods:
103108
read: {}
104109
list: {}
105110
create: {}
106111
# blocked on https://github.com/aep-dev/api-linter/issues/97
107112
# non_client_settable_id: true
113+
- kind: "operation"
114+
plural: "operations"
115+
schema:
116+
x-aep-proto-message-name: "aep.api.Operation",
117+
type: "object"
118+
properties:
119+
path:
120+
type: string
121+
x-aep-field-number: 1
122+
metadata:
123+
type: string
124+
x-aep-field-number: 2
125+
done:
126+
type: boolean
127+
x-aep-field-number: 3
128+
response:
129+
type: object
130+
x-aep-field-number: 5

go.mod

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@ go 1.23.0
55
toolchain go1.23.6
66

77
require (
8+
buf.build/gen/go/aep/api/protocolbuffers/go v1.36.6-20250324194021-2fc44491c629.1
9+
cloud.google.com/go/longrunning v0.6.6
10+
github.com/aep-dev/aep-lib-go v0.0.0-20250422043410-eb3b92e38647
11+
github.com/aep-dev/terraform-provider-aep v0.0.0-20241112052633-f48d45460768
12+
github.com/google/cel-go v0.22.1
813
github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0
914
github.com/hashicorp/terraform-plugin-sdk/v2 v2.35.0
10-
github.com/jhump/protoreflect v1.17.0
15+
github.com/mattn/go-sqlite3 v1.14.24
1116
github.com/rs/cors v1.11.1
1217
github.com/spf13/cobra v1.7.0
1318
google.golang.org/genproto/googleapis/api v0.0.0-20250303144028-a0af3efb3deb
@@ -16,32 +21,20 @@ require (
1621
)
1722

1823
require (
19-
buf.build/gen/go/aep/api/protocolbuffers/go v1.36.6-20250324194021-2fc44491c629.1 // indirect
2024
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.6-20240221180331-f05a6f4403ce.1 // indirect
2125
cel.dev/expr v0.19.1 // indirect
22-
cloud.google.com/go v0.118.3 // indirect
23-
cloud.google.com/go/auth v0.15.0 // indirect
24-
cloud.google.com/go/auth/oauth2adapt v0.2.7 // indirect
25-
cloud.google.com/go/compute/metadata v0.6.0 // indirect
26-
cloud.google.com/go/longrunning v0.6.6 // indirect
2726
github.com/DataDog/datadog-go v2.2.0+incompatible // indirect
2827
github.com/ProtonMail/go-crypto v1.1.0-alpha.2 // indirect
2928
github.com/PuerkitoBio/purell v1.1.0 // indirect
3029
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
31-
github.com/aep-dev/aep-lib-go v0.0.0-20250223051210-bfe8118a440e // indirect
32-
github.com/aep-dev/terraform-provider-aep v0.0.0-20241112052633-f48d45460768 // indirect
3330
github.com/agext/levenshtein v1.2.2 // indirect
3431
github.com/antlr4-go/antlr/v4 v4.13.0 // indirect
3532
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
3633
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a // indirect
3734
github.com/bufbuild/protocompile v0.14.1 // indirect
3835
github.com/cloudflare/circl v1.3.7 // indirect
39-
github.com/cockscomb/cel2sql v0.0.0-20211204123659-c803dfd5c44c // indirect
4036
github.com/dikhan/http_goclient v0.0.0-20181010015730-b9de9b5ee7b6 // indirect
4137
github.com/fatih/color v1.16.0 // indirect
42-
github.com/felixge/httpsnoop v1.0.4 // indirect
43-
github.com/go-logr/logr v1.4.2 // indirect
44-
github.com/go-logr/stdr v1.2.2 // indirect
4538
github.com/go-openapi/analysis v0.0.0-20171215055114-2bbaa248df98 // indirect
4639
github.com/go-openapi/errors v0.0.0-20170426151106-03cfca65330d // indirect
4740
github.com/go-openapi/jsonpointer v0.17.0 // indirect
@@ -51,10 +44,6 @@ require (
5144
github.com/go-openapi/strfmt v0.0.0-20171222154016-4dd3d302e100 // indirect
5245
github.com/go-openapi/swag v0.17.0 // indirect
5346
github.com/golang/protobuf v1.5.4 // indirect
54-
github.com/google/cel-go v0.22.1 // indirect
55-
github.com/google/s2a-go v0.1.9 // indirect
56-
github.com/googleapis/enterprise-certificate-proxy v0.3.5 // indirect
57-
github.com/googleapis/gax-go/v2 v2.14.1 // indirect
5847
github.com/hashicorp/errwrap v1.0.0 // indirect
5948
github.com/hashicorp/go-checkpoint v0.5.0 // indirect
6049
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
@@ -77,11 +66,11 @@ require (
7766
github.com/hashicorp/yamux v0.1.1 // indirect
7867
github.com/iancoleman/strcase v0.3.0 // indirect
7968
github.com/inconshreveable/mousetrap v1.1.0 // indirect
69+
github.com/jhump/protoreflect v1.17.0 // indirect
8070
github.com/kr/text v0.2.0 // indirect
8171
github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329 // indirect
8272
github.com/mattn/go-colorable v0.1.13 // indirect
8373
github.com/mattn/go-isatty v0.0.20 // indirect
84-
github.com/mattn/go-sqlite3 v1.14.24 // indirect
8574
github.com/mitchellh/copystructure v1.2.0 // indirect
8675
github.com/mitchellh/go-homedir v1.1.0 // indirect
8776
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
@@ -93,35 +82,26 @@ require (
9382
github.com/rogpeppe/go-internal v1.13.1 // indirect
9483
github.com/spf13/pflag v1.0.5 // indirect
9584
github.com/stoewer/go-strcase v1.2.0 // indirect
85+
github.com/stretchr/testify v1.10.0 // indirect
9686
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
9787
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
9888
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
9989
github.com/zclconf/go-cty v1.15.0 // indirect
100-
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
101-
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.59.0 // indirect
102-
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.59.0 // indirect
103-
go.opentelemetry.io/otel v1.34.0 // indirect
104-
go.opentelemetry.io/otel/metric v1.34.0 // indirect
105-
go.opentelemetry.io/otel/trace v1.34.0 // indirect
10690
golang.org/x/crypto v0.36.0 // indirect
10791
golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc // indirect
10892
golang.org/x/mod v0.21.0 // indirect
10993
golang.org/x/net v0.37.0 // indirect
110-
golang.org/x/oauth2 v0.27.0 // indirect
11194
golang.org/x/sync v0.12.0 // indirect
112-
golang.org/x/time v0.10.0 // indirect
11395
golang.org/x/tools v0.26.0 // indirect
114-
google.golang.org/api v0.224.0 // indirect
11596
google.golang.org/appengine v1.6.8 // indirect
116-
google.golang.org/genproto v0.0.0-20250303144028-a0af3efb3deb // indirect
11797
google.golang.org/genproto/googleapis/rpc v0.0.0-20250303144028-a0af3efb3deb // indirect
11898
gopkg.in/mgo.v2 v2.0.0-20160818020120-3f83fa500528 // indirect
11999
gopkg.in/yaml.v2 v2.4.0 // indirect
120100
)
121101

122102
require (
123103
github.com/ghodss/yaml v1.0.0
124-
github.com/google/go-cmp v0.7.0
104+
github.com/google/go-cmp v0.7.0 // indirect
125105
golang.org/x/sys v0.31.0 // indirect
126-
golang.org/x/text v0.23.0
106+
golang.org/x/text v0.23.0 // indirect
127107
)

0 commit comments

Comments
 (0)