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

Deprecate example field #1637

Merged
merged 2 commits into from
Sep 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ All submissions, including submissions by project members, require review.
Great! It should be as simple as this (run from the root of the directory):

```bash
docker run -v $(pwd):/src/grpc-gateway --rm docker.pkg.github.com/grpc-ecosystem/grpc-gateway/build-env:1.14 \
docker run -v $(pwd):/src/grpc-gateway --rm docker.pkg.github.com/grpc-ecosystem/grpc-gateway/build-env:1.15 \
/bin/bash -c 'cd /src/grpc-gateway && \
make realclean && \
make examples && \
Expand Down
478 changes: 239 additions & 239 deletions examples/internal/proto/examplepb/a_bit_of_everything.pb.go

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions examples/internal/proto/examplepb/a_bit_of_everything.proto
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,13 @@ message ABitOfEverything {
url: "https://github.com/grpc-ecosystem/grpc-gateway";
description: "Find out more about ABitOfEverything";
}
example: { value: '{ "uuid": "0cf361e1-4b44-483d-a159-54dabdf7e814" }' }
example_string: "{\"uuid\": \"0cf361e1-4b44-483d-a159-54dabdf7e814\"}"
};

// Nested is nested type.
message Nested {
option (grpc.gateway.protoc_gen_swagger.options.openapiv2_schema) = {
example: { value: '{ "ok": "TRUE" }' }
example_string: "{\"ok\": \"TRUE\"}"
};
// name is nested field.
string name = 1;
Expand Down Expand Up @@ -276,7 +276,7 @@ message ABitOfEverything {
// ABitOfEverythingRepeated is used to validate repeated path parameter functionality
message ABitOfEverythingRepeated {
option (grpc.gateway.protoc_gen_swagger.options.openapiv2_schema) = {
example: { value: '{ "path_repeated_bool_value": [true, true, false, true], "path_repeated_int32_value": [1, 2, 3] }' }
example_string: "{\"path_repeated_bool_value\": [true, true, false, true], \"path_repeated_int32_value\": [1, 2, 3]}"
};

// repeated values. they are comma-separated in path
Expand Down
1 change: 0 additions & 1 deletion protoc-gen-swagger/genswagger/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ go_test(
"//protoc-gen-grpc-gateway/httprule:go_default_library",
"//protoc-gen-swagger/options:go_default_library",
"@com_github_golang_protobuf//proto:go_default_library",
"@io_bazel_rules_go//proto/wkt:any_go_proto",
"@io_bazel_rules_go//proto/wkt:compiler_plugin_go_proto",
"@io_bazel_rules_go//proto/wkt:descriptor_go_proto",
"@io_bazel_rules_go//proto/wkt:struct_go_proto",
Expand Down
3 changes: 3 additions & 0 deletions protoc-gen-swagger/genswagger/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -1877,6 +1877,9 @@ func swaggerSchemaFromProtoSchema(s *swagger_options.Schema, reg *descriptor.Reg
if s != nil && s.Example != nil {
ret.Example = json.RawMessage(s.Example.Value)
}
if s != nil && s.ExampleString != "" {
ret.Example = json.RawMessage(s.ExampleString)
}

return ret
}
Expand Down
10 changes: 2 additions & 8 deletions protoc-gen-swagger/genswagger/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/golang/protobuf/proto"
protodescriptor "github.com/golang/protobuf/protoc-gen-go/descriptor"
plugin "github.com/golang/protobuf/protoc-gen-go/plugin"
"github.com/golang/protobuf/ptypes/any"
structpb "github.com/golang/protobuf/ptypes/struct"
"github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/descriptor"
"github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/httprule"
Expand Down Expand Up @@ -2515,10 +2514,7 @@ func TestRenderMessagesAsDefinition(t *testing.T) {
},
schema: map[string]swagger_options.Schema{
"Message": swagger_options.Schema{
Example: &any.Any{
TypeUrl: "this_isnt_used",
Value: []byte(`{"foo":"bar"}`),
},
ExampleString: `{"foo":"bar"}`,
},
},
defs: map[string]swaggerSchemaObject{
Expand All @@ -2535,9 +2531,7 @@ func TestRenderMessagesAsDefinition(t *testing.T) {
},
schema: map[string]swagger_options.Schema{
"Message": swagger_options.Schema{
Example: &any.Any{
Value: []byte(`XXXX anything goes XXXX`),
},
ExampleString: `XXXX anything goes XXXX`,
},
},
defs: map[string]swaggerSchemaObject{
Expand Down
257 changes: 135 additions & 122 deletions protoc-gen-swagger/options/openapiv2.pb.go

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion protoc-gen-swagger/options/openapiv2.proto
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,13 @@ message Schema {
// Additional external documentation for this schema.
ExternalDocumentation external_docs = 5;
// A free-form property to include an example of an instance for this schema.
google.protobuf.Any example = 6;
// Deprecated, please use example_string instead.
google.protobuf.Any example = 6 [
deprecated = true
];
// A free-form property to include a JSON example of this field. This is copied
// verbatim to the output swagger.json. Quotes must be escaped.
string example_string = 7;
}

// `JSONSchema` represents properties from JSON Schema taken, and as used, in
Expand Down