Skip to content

Commit

Permalink
protoc-gen-swagger: Add ability to specify custom response objects
Browse files Browse the repository at this point in the history
Extends the openapiv2 protofile to allow control over response objects.

Fixes grpc-ecosystem#304
  • Loading branch information
johanbrandhorst committed Jun 7, 2018
1 parent 15cae3f commit bb657d1
Show file tree
Hide file tree
Showing 14 changed files with 1,032 additions and 454 deletions.
1 change: 1 addition & 0 deletions examples/clients/abe/examplepb_a_bit_of_everything.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"time"
)

// Intentionaly complicated message type to cover much features of Protobuf.
type ExamplepbABitOfEverything struct {

SingleNested ABitOfEverythingNested `json:"single_nested,omitempty"`
Expand Down
354 changes: 183 additions & 171 deletions examples/proto/examplepb/a_bit_of_everything.pb.go

Large diffs are not rendered by default.

52 changes: 51 additions & 1 deletion examples/proto/examplepb/a_bit_of_everything.proto
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,45 @@ option (grpc.gateway.protoc_gen_swagger.options.openapiv2_swagger) = {
value: {};
}
}
responses: {
key: "403";
value: {
description: "Returned when the user does not have permission to access the resource.";
}
}
responses: {
key: "404";
value: {
description: "Returned when the resource does not exist.";
schema: {
json_schema: {
type: STRING;
}
}
}
}
responses: {
key: "418";
value: {
description: "I'm a teapot.";
schema: {
json_schema: {
ref: ".grpc.gateway.examples.examplepb.NumericEnum";
}
}
}
}
};


// Intentionaly complicated message type to cover much features of Protobuf.
// NEXT ID: 30
message ABitOfEverything {
option (grpc.gateway.protoc_gen_swagger.options.openapiv2_schema) = {
json_schema: {
title: "A bit of everything"
description: "Intentionaly complicated message type to cover much features of Protobuf."
}
external_docs: {
url: "https://github.com/grpc-ecosystem/grpc-gateway";
description: "Find out more about ABitOfEverything";
Expand Down Expand Up @@ -155,7 +187,7 @@ message ABitOfEverything {

google.protobuf.Timestamp timestamp_value = 27;

// repeated enum value. it is comma-separated in query
// repeated enum value. it is comma-separated in query
repeated NumericEnum repeated_enum_value = 28;
}

Expand Down Expand Up @@ -271,6 +303,24 @@ service ABitOfEverythingService {
url: "https://github.com/grpc-ecosystem/grpc-gateway";
description: "Find out more Echo";
}
responses: {
key: "503";
value: {
description: "Returned when the resource is temporarily unavailable.";
}
}
responses: {
// Overwrites global definition.
key: "404";
value: {
description: "Returned when the resource does not exist.";
schema: {
json_schema: {
type: INTEGER;
}
}
}
}
};
}
rpc DeepPathEcho(ABitOfEverything) returns (ABitOfEverything) {
Expand Down
Loading

0 comments on commit bb657d1

Please sign in to comment.