Skip to content

Commit

Permalink
fill example attribute of swagger schema if provided for messages
Browse files Browse the repository at this point in the history
use json.RawMessage for property & object examples

with json.RawMessage, users can supply complete json for swagger objects (i.e.
for a proto Message). If it's correct json, it will be added to the output.json
and rendered correctly by consuming applications (i.e. code generators or
swagger-ui)

Example, in proto:
option (grpc.gateway.protoc_gen_swagger.options.openapiv2_schema) = {
  example: {
    value:
    '{"someKey" : "someValue", "anotherKey" : 5}';
  };
};

Rendered JSON:
"example": {
  "someKey": "someValue",
  "anotherKey": 5
}

If we used string instead of json.RawMessage, the serializer would escape the
quotes and it would be serialized as a string. This is not desirable, because
the output should be in fact JSON key/value pairs.

Also:

* a_bit_of_everything.proto: add 'example' example

Signed-off-by: Stephan Renatus <srenatus@chef.io>
  • Loading branch information
srenatus committed Jan 9, 2019
1 parent ae4bb97 commit 3baf423
Show file tree
Hide file tree
Showing 5 changed files with 214 additions and 198 deletions.
Loading

0 comments on commit 3baf423

Please sign in to comment.