Skip to content

Commit 30d17fe

Browse files
authored
feat(151): add long-running-operation example (#66)
Adding an example of a long-running-operation (archiveBook), to illustrate how LROs would work from a user interface standpoint. This change currently implements the google.aip.Operation service to return the operation resource - in the future this will be replaced by an operation service that will be generated by aep-lib-go/aepc. This change also upstreams the proto generation functionality, as well as the resource model for aepc, up to aep-lib-go. This simplifies end-to-end testing of changes to the resource model, as well as it's maintenance.
1 parent ae90418 commit 30d17fe

26 files changed

Lines changed: 1023 additions & 4326 deletions

buf.gen.yaml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
1-
version: v1
1+
version: v2
2+
managed:
3+
enabled: true
4+
override:
5+
# temporary workaround until https://github.com/aep-dev/aep-components/pull/22
6+
# is merged and released
7+
- module: buf.build/aep/api
8+
file_option: go_package_prefix
9+
value: buf.build/gen/go/aep/api/protocolbuffers/go
210
plugins:
3-
- plugin: buf.build/protocolbuffers/go:v1.31.0
11+
- remote: buf.build/protocolbuffers/go:v1.31.0
412
out: .
513
opt: paths=source_relative
6-
- plugin: buf.build/grpc-ecosystem/gateway:v2.18.0
14+
- remote: buf.build/grpc-ecosystem/gateway:v2.18.0
715
out: .
816
opt: paths=source_relative
9-
- plugin: buf.build/grpc-ecosystem/openapiv2:v2.18.0
17+
- remote: buf.build/grpc-ecosystem/openapiv2:v2.18.0
1018
out: .
11-
- plugin: buf.build/grpc/go:v1.3.0
19+
- remote: buf.build/grpc/go:v1.3.0
1220
out: .
1321
opt:
1422
- paths=source_relative

buf.lock

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# Generated by buf. DO NOT EDIT.
22
version: v2
33
deps:
4+
- name: buf.build/aep/api
5+
commit: 2fc44491c62940f1b59218fb450701b5
6+
digest: b5:268b5152935e5a9b48c2606944b33cdbb141152e914a364a3bbce0790f657c8adfb4635664063e89cbaa557aa9294e37c3874613d921e2343a7a709a7924f5c3
7+
- name: buf.build/bufbuild/protovalidate
8+
commit: f05a6f4403ce4327bae4f50f281c3ed0
9+
digest: b5:f1d76430ee97c89cd2044e9ae1c510887b701ee7bca60564ebf82e3919e53cacefc830a0eb803277c2d98c5f313b4167e8914afc9f214332717a50b5e170e6f4
410
- name: buf.build/googleapis/googleapis
511
commit: 28151c0d0a1641bf938a7672c500e01d
612
digest: b5:93b70089baa4fc05a92d3e52db91a4b7812db3b57b9664f6cb301733938cb630e377a938e8a56779388171c749c1d42a2e9a6c6230f2ff45f127a8102a6a27d0

buf.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ plugins:
99
- plugin: buf-plugin-aep
1010
deps:
1111
- buf.build/googleapis/googleapis:28151c0d0a1641bf938a7672c500e01d
12+
- buf.build/aep/api:2fc44491c62940f1b59218fb450701b5

cmd/root.go

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,10 @@ 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+
"github.com/aep-dev/aep-lib-go/pkg/api"
26+
"github.com/aep-dev/aep-lib-go/pkg/proto"
2827
"github.com/aep-dev/aepc/validator"
29-
"github.com/aep-dev/aepc/writer/proto"
3028
"github.com/spf13/cobra"
31-
"google.golang.org/protobuf/encoding/protojson"
3229
)
3330

3431
func NewCommand() *cobra.Command {
@@ -53,26 +50,21 @@ func NewCommand() *cobra.Command {
5350

5451
func ProcessInput(inputFile, outputFilePrefix string) error {
5552
outputDir := filepath.Dir(outputFilePrefix)
56-
s := &schema.Service{}
5753
input, err := ReadFile(inputFile)
5854
fmt.Printf("input: %s\n", string(input))
5955
if err != nil {
6056
return fmt.Errorf("unable to read file: %w", err)
6157
}
6258
ext := filepath.Ext(inputFile)
63-
err = unmarshal(ext, input, s)
59+
a, err := deserializeAPI(ext, input)
6460
if err != nil {
6561
return fmt.Errorf("unable to unmarshal file: %w", err)
6662
}
67-
errors := validator.ValidateService(s)
63+
errors := validator.ValidateAPI(a)
6864
if len(errors) > 0 {
6965
return fmt.Errorf("error validating service: %v", errors)
7066
}
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)
67+
proto, err := proto.APIToProtoString(a, outputDir)
7668
if err != nil {
7769
return fmt.Errorf("error writing service proto: %w", err)
7870
}
@@ -82,7 +74,7 @@ func ProcessInput(inputFile, outputFilePrefix string) error {
8274
return fmt.Errorf("error writing file: %w", err)
8375
}
8476
fmt.Printf("output proto file: %s\n", protoFile)
85-
openapi, err := api.ConvertToOpenAPIBytes()
77+
openapi, err := a.ConvertToOpenAPIBytes()
8678
if err != nil {
8779
return fmt.Errorf("error building openapi: %w", err)
8880
}
@@ -105,28 +97,27 @@ func ProcessInput(inputFile, outputFilePrefix string) error {
10597
return nil
10698
}
10799

108-
func unmarshal(ext string, b []byte, s *schema.Service) error {
100+
func deserializeAPI(ext string, b []byte) (*api.API, error) {
109101
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-
}
114102
case ".yaml":
115103
asJson, err := yaml.YAMLToJSON(b)
116104
if err != nil {
117-
return fmt.Errorf("unable to decode yaml to JSON %q: %w", string(b), err)
105+
return nil, fmt.Errorf("unable to decode yaml to JSON %q: %w", string(b), err)
118106
}
119-
if err := protojson.Unmarshal(asJson, s); err != nil {
120-
log.Fatal(fmt.Errorf("unable to decode proto %q: %w", string(b), err))
107+
api, err := api.LoadAPIFromJson(asJson)
108+
if err != nil {
109+
log.Fatal(fmt.Errorf("unable to unmarshal json %q: %w", string(b), err))
121110
}
111+
return api, nil
122112
case ".json":
123-
if err := protojson.Unmarshal(b, s); err != nil {
124-
return fmt.Errorf("unable to decode json %q: %w", string(b), err)
113+
api, err := api.LoadAPIFromJson(b)
114+
if err != nil {
115+
log.Fatal(fmt.Errorf("unable to unmarshal json %q: %w", string(b), err))
125116
}
117+
return api, nil
126118
default:
127-
return fmt.Errorf("extension %v is unsupported", ext)
119+
return nil, fmt.Errorf("extension %v is unsupported", ext)
128120
}
129-
return nil
130121
}
131122

132123
func ReadFile(fileName string) ([]byte, error) {

0 commit comments

Comments
 (0)