Skip to content

Commit

Permalink
Add grpc proto spec files in 'io' package
Browse files Browse the repository at this point in the history
  • Loading branch information
yogeshnikam671 committed Jul 22, 2024
1 parent 6c8849d commit 92fa0ca
Show file tree
Hide file tree
Showing 3 changed files with 166 additions and 0 deletions.
54 changes: 54 additions & 0 deletions io/specmatic/examples/store/grpc/order_api/order.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
syntax = "proto3";

option java_multiple_files = true;
option java_package = "com.store.order.proto";
option go_package = "github.com/znsio/specmatic-order-bff-grpc-go/com/store/order/proto";
option java_outer_classname = "OrderProto";

package com.store;
import "buf/validate/validate.proto";

service OrderService {
rpc SearchOrders(OrderSearchRequest) returns (OrderListResponse);
rpc GetOrder(OrderId) returns (Order);
rpc AddOrder(NewOrder) returns (OrderId);
rpc UpdateOrder(Order) returns (OrderResponse);
rpc DeleteOrder(OrderId) returns (OrderResponse);
}

enum OrderStatus {
NULL_ORD_STATUS = 0;
FULFILLED = 1;
PENDING = 2;
CANCELLED = 3;
}

message Order {
int32 id = 1 [(buf.validate.field).required = true];
int32 productId = 2 [(buf.validate.field).required = true];
int32 count = 3 [(buf.validate.field).required = true];
OrderStatus status = 4 [(buf.validate.field).required = true];
}

message NewOrder {
int32 productId = 1 [(buf.validate.field).required = true];
int32 count = 2 [(buf.validate.field).required = true];
OrderStatus status = 3 [(buf.validate.field).required = true];
}

message OrderId {
int32 id = 1 [(buf.validate.field).required = true];
}

message OrderSearchRequest {
int32 productId = 1;
OrderStatus status = 2 [(buf.validate.field).enum.defined_only = true];
}

message OrderListResponse {
repeated Order orders = 1;
}

message OrderResponse {
string message = 1;
}
54 changes: 54 additions & 0 deletions io/specmatic/examples/store/grpc/order_api/product.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
syntax = "proto3";

option java_multiple_files = true;
option java_package = "com.store.product.proto";
option go_package = "github.com/znsio/specmatic-order-bff-grpc-go/com/store/product/proto";
option java_outer_classname = "ProductProto";

package com.store;
import "buf/validate/validate.proto";

service ProductService {
rpc SearchProducts(ProductSearchRequest) returns (ProductListResponse);
rpc GetProduct(ProductId) returns (Product);
rpc AddProduct(NewProduct) returns (ProductId);
rpc UpdateProduct(Product) returns (ProductResponse);
rpc DeleteProduct(ProductId) returns (ProductResponse);
}

enum ProductType {
NULL_PROD_TYPE = 0;
BOOK = 1;
FOOD = 2;
GADGET = 3;
OTHER = 4;
}

message Product {
int32 id = 1 [(buf.validate.field).required = true];
string name = 2 [(buf.validate.field).required = true];
ProductType type = 3 [(buf.validate.field).required = true];
int32 inventory = 4 [(buf.validate.field).required = true];
}

message NewProduct {
string name = 1 [(buf.validate.field).required = true];
ProductType type = 2 [(buf.validate.field).required = true];
int32 inventory = 3 [(buf.validate.field).required = false];
}

message ProductId {
int32 id = 1 [(buf.validate.field).required = true];
}

message ProductSearchRequest {
ProductType type = 1 [(buf.validate.field).enum.defined_only = true];
}

message ProductListResponse {
repeated Product products = 1;
}

message ProductResponse {
string message = 1;
}
58 changes: 58 additions & 0 deletions io/specmatic/examples/store/grpc/order_bff.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
syntax = "proto3";

option java_multiple_files = true;
option java_package = "com.store.order.bff.proto";
option go_package = "github.com/znsio/specmatic-order-bff-grpc-go/com/store/order/bff/proto";
option java_outer_classname = "BffProto";

package com.store.order.bff;
import "buf/validate/validate.proto";

service OrderService {
rpc findAvailableProducts(findAvailableProductsRequest) returns (ProductListResponse);
rpc createOrder(NewOrder) returns (OrderId);
rpc createProduct(NewProduct) returns (ProductId);
}

enum ProductType {
NULL_PROD_TYPE = 0;
BOOK = 1;
FOOD = 2;
GADGET = 3;
OTHER = 4;
}

message findAvailableProductsRequest {
ProductType type = 1 [(buf.validate.field).enum.defined_only = true];
int32 pageSize = 2 [(buf.validate.field).required = true];
}

message Product {
int32 id = 1 [(buf.validate.field).required = true];
string name = 2 [(buf.validate.field).required = true];
ProductType type = 3 [(buf.validate.field).required = true];
int32 inventory = 4 [(buf.validate.field).required = true];
}

message ProductListResponse {
repeated Product products = 1;
}

message NewOrder {
int32 productId = 1 [(buf.validate.field).required = true];
int32 count = 2 [(buf.validate.field).required = true, (buf.validate.field).int32.gte = 2, (buf.validate.field).int32.lte = 100];
}

message OrderId {
int32 id = 1 [(buf.validate.field).required = true];
}

message NewProduct {
string name = 1 [(buf.validate.field).required = true, (buf.validate.field).string.min_len = 5, (buf.validate.field).string.max_len = 10];
ProductType type = 2 [(buf.validate.field).required = true];
int32 inventory = 3 [(buf.validate.field).required = false];
}

message ProductId {
int32 id = 1 [(buf.validate.field).required = true];
}

0 comments on commit 92fa0ca

Please sign in to comment.