Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic Buf Example #1

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
*.class
*.log
.vscode
.metals
.history
.bloop
metals.sbt
target/
.bsp

#Probably not the best idea but to keep this repo clean and let people run stuff themselves
/src/main/scala/com/example/petstore/generated
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
An example. I believe these text is not correct.# Scala Pb Buf Examples.
Luka-J9 marked this conversation as resolved.
Show resolved Hide resolved

More documentation to come...

## What is Buf
Great tool for protobuf dependency management - a better explanation to come

## Prerequisites

This guide assumes you have Scala/SBT.

## Getting Started

Follow the instructions of the [Buf install guide](https://buf.build/docs/installation)

Run the following command to see your code get generated:
“`
buf generate
“`


## My Scala Plugin doesn't exist; what do?

Plugins that are live:

[Base Scala Pb Compiler](https://buf.build/community/scalapb-scala)
[ZIO GRPC](https://buf.build/community/scalapb-zio-grpc)

The following are buf plugins that can be easily added, but require demand so the Buf team will support them. If you want to see them, PLEASE leave a thumbs up. If your company would use that plugin heavily drop a comment!
[FS2 GRPC](https://github.com/bufbuild/plugins/issues/305)
[Akka GRPC pre/post license change](https://github.com/bufbuild/plugins/issues/306)

[Scalapb Validate](https://github.com/bufbuild/plugins/issues/304) plugin would require some help from the Buf team as their plugin test bench doesn't (at the time of writing) support chained plugins.
11 changes: 11 additions & 0 deletions buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: v1
plugins:
- plugin: buf.build/community/scalapb-scala:v0.11.13
out: src/main/scala
opt:
- flat_package
Luka-J9 marked this conversation as resolved.
Show resolved Hide resolved
- grpc
- plugin: buf.build/community/scalapb-zio-grpc:v0.5.3
out: src/main/scala
opt:
- flat_package
3 changes: 3 additions & 0 deletions buf.work.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
version: v1
directories:
- src/main/protobuf
7 changes: 7 additions & 0 deletions buf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: v1
breaking:
use:
- FILE
lint:
use:
- DEFAULT
13 changes: 13 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

scalaVersion := "2.13.8"

name := "scalapb-buf-examples"
organization := "scalapb"
version := "1.0"

libraryDependencies ++=
Seq(
"com.thesamet.scalapb" %% "scalapb-runtime" % scalapb.compiler.Version.scalapbVersion,
"com.thesamet.scalapb" %% "scalapb-runtime-grpc" % scalapb.compiler.Version.scalapbVersion,
"com.thesamet.scalapb.zio-grpc" %% "zio-grpc-core" % "0.5.3"
)
1 change: 1 addition & 0 deletions project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=1.8.2
2 changes: 2 additions & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
addSbtPlugin("com.thesamet" % "sbt-protoc" % "1.0.0")
libraryDependencies += "com.thesamet.scalapb" %% "compilerplugin" % "0.11.11"
7 changes: 7 additions & 0 deletions src/main/protobuf/buf.yaml
Luka-J9 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: v1
breaking:
use:
- FILE
lint:
use:
- DEFAULT
47 changes: 47 additions & 0 deletions src/main/protobuf/petstore/petstore.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
syntax = "proto3";
package petstore;

option java_package = "com.example.petstore.generated";

message Pet {
int32 id = 1;
string name = 2;
}

message User {
int32 id = 1;
string username = 2;
string email = 3;
string phone = 4;
}

message PetByIdRequest {
int32 id = 1;
}

message UserByNameRequest {
string username = 1;
}

message PetResponse {
Pet pet = 1;
}

message UserResponse {
User user = 1;
}

message EmptyReq{
string msg = 1;
}
message EmptyRes{
string msg = 1;
}

service PetStoreService {
rpc PetById (PetByIdRequest) returns (PetResponse);
rpc UserByName (UserByNameRequest) returns (UserResponse);
rpc ListUsers (EmptyReq) returns (stream User);
rpc StoreUsers (stream User)returns (EmptyRes);
rpc BulkUsers (stream User) returns (stream User);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.example.petstore.impl

class ZioPetstoreImpl {
//TODO: Draw the owl
}