Skip to content

Commit

Permalink
feat: add openapi URL support
Browse files Browse the repository at this point in the history
It's helpful for openapi definitions to include
a server URL to send requests to (e.g. for aepcli
to use a single file to provide all required information).
  • Loading branch information
toumorokoshi committed Oct 14, 2024
1 parent c715d5d commit 4a82b7d
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 103 deletions.
1 change: 1 addition & 0 deletions example/bookstore/v1/bookstore.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# normally this would be suffixed with the domain (.com)
name: "bookstore.example.com"
url: "http://localhost:8081"
resources:
- kind: "Book"
plural: "books"
Expand Down
5 changes: 5 additions & 0 deletions example/bookstore/v1/bookstore_openapi.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"swagger": "2.0",
"servers": [
{
"url": "http://localhost:8081"
}
],
"info": {
"title": "bookstore.example.com",
"version": "version not set"
Expand Down
10 changes: 10 additions & 0 deletions example/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ func (BookstoreServer) GetBook(_ context.Context, r *bpb.GetBookRequest) (*bpb.B
return nil, status.Errorf(codes.NotFound, "book %q not found", r.Path)
}

func (BookstoreServer) ListBook(_ context.Context, r *bpb.ListBookRequest) (*bpb.ListBookResponse, error) {
var books []*bpb.Book
for _, book := range bookDatabase {
books = append(books, book)
}
return &bpb.ListBookResponse{
Results: books,
}, nil
}

func StartServer(targetPort int) {
bookDatabase = make(map[string]*bpb.Book)
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", targetPort))
Expand Down
Loading

0 comments on commit 4a82b7d

Please sign in to comment.