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

protoc-gen-swagger: support JSON Schema Validation properties and add openapiv2_field option #687

Merged
merged 1 commit into from Aug 6, 2018

Conversation

Projects
None yet
6 participants
@co3k
Contributor

co3k commented Jun 28, 2018

This change supports JSON Schema Validation properties.
It allows you to specify some validation rules in .proto file like this:

message GeoCoordinate {
  option (grpc.gateway.protoc_gen_swagger.options.openapiv2_schema) = {
    json_schema: {
      required: ["latitude", "longitude"]
    }
  };

  string latitude = 1;
  string longitude = 2;
}

And also this supports openapiv2_field field option.
It allows you to specifiy additional JSON schema setting like this:

string latitude = 1 [(grpc.gateway.protoc_gen_swagger.options.openapiv2_field) = {pattern: "^[\-]?[0-9]{0,2}\.[0-9]+$"}];
string longitude = 2 [(grpc.gateway.protoc_gen_swagger.options.openapiv2_field) = {pattern: "^[\-]?[0-9]{0,3}\.[0-9]+$"}];

The both of grpc.gateway.protoc_gen_swagger.options.openapiv2_schema and grpc.gateway.protoc_gen_swagger.options.openapiv2_field now supports the following validation properties.

  • multiple_of
  • maximum
  • exclusive_maximum
  • minimum
  • exclusive_minimum
  • max_length
  • min_length
  • pattern
  • max_items
  • min_items
  • unique_items
  • max_properties
  • min_properties
  • required

Please see also JSON Schema Validation spec to understand about these properties.

@googlebot googlebot added the cla: yes label Jun 28, 2018

@co3k co3k changed the title from Add support to configure JSON Schema in openapiv2_field_json_schema field option and JSONSchema message type supports JSON Schema Validation properties to protoc-gen-swagger: Add ability to JSON Schema Validation properties and openapiv2_field_json_schema field option Jul 24, 2018

@co3k co3k changed the title from protoc-gen-swagger: Add ability to JSON Schema Validation properties and openapiv2_field_json_schema field option to protoc-gen-swagger: support JSON Schema Validation properties and add openapiv2_field_json_schema field option Jul 24, 2018

@codecov-io

This comment has been minimized.

Show comment
Hide comment
@codecov-io

codecov-io Jul 24, 2018

Codecov Report

Merging #687 into master will decrease coverage by 0.13%.
The diff coverage is 39.06%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #687      +/-   ##
==========================================
- Coverage    56.3%   56.16%   -0.14%     
==========================================
  Files          30       30              
  Lines        3062     3112      +50     
==========================================
+ Hits         1724     1748      +24     
- Misses       1167     1193      +26     
  Partials      171      171
Impacted Files Coverage Δ
protoc-gen-swagger/genswagger/types.go 19.04% <ø> (ø) ⬆️
protoc-gen-swagger/genswagger/template.go 38.75% <39.06%> (+0.57%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7951e5b...757aaa0. Read the comment docs.

codecov-io commented Jul 24, 2018

Codecov Report

Merging #687 into master will decrease coverage by 0.13%.
The diff coverage is 39.06%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #687      +/-   ##
==========================================
- Coverage    56.3%   56.16%   -0.14%     
==========================================
  Files          30       30              
  Lines        3062     3112      +50     
==========================================
+ Hits         1724     1748      +24     
- Misses       1167     1193      +26     
  Partials      171      171
Impacted Files Coverage Δ
protoc-gen-swagger/genswagger/types.go 19.04% <ø> (ø) ⬆️
protoc-gen-swagger/genswagger/template.go 38.75% <39.06%> (+0.57%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7951e5b...757aaa0. Read the comment docs.

@co3k

This comment has been minimized.

Show comment
Hide comment
@co3k

co3k Jul 29, 2018

Contributor

Hi, I really need these changes for my works but there aren't any reactions for a month.
What should I do to get any feedbacks about this pull request?

Contributor

co3k commented Jul 29, 2018

Hi, I really need these changes for my works but there aren't any reactions for a month.
What should I do to get any feedbacks about this pull request?

@johanbrandhorst

This comment has been minimized.

Show comment
Hide comment
@johanbrandhorst

johanbrandhorst Jul 29, 2018

Collaborator

This is really interesting, but to make things easier for us maintainers, could you please include a description of the changes? Include any external links as well.

Collaborator

johanbrandhorst commented Jul 29, 2018

This is really interesting, but to make things easier for us maintainers, could you please include a description of the changes? Include any external links as well.

@co3k

This comment has been minimized.

Show comment
Hide comment
@co3k

co3k Jul 29, 2018

Contributor

@johanbrandhorst Thanks for your advice! I've added descriptions to this pull request. If it's OK, I will also change the commit message to follow it.

Contributor

co3k commented Jul 29, 2018

@johanbrandhorst Thanks for your advice! I've added descriptions to this pull request. If it's OK, I will also change the commit message to follow it.

@johanbrandhorst

This comment has been minimized.

Show comment
Hide comment
@johanbrandhorst

johanbrandhorst Jul 29, 2018

Collaborator

@co3k that's great thanks! I think this looks good but I would like the input of @ivucica as well before we merge.

Collaborator

johanbrandhorst commented Jul 29, 2018

@co3k that's great thanks! I think this looks good but I would like the input of @ivucica as well before we merge.

@johanbrandhorst johanbrandhorst requested a review from ivucica Jul 29, 2018

@ivucica

Can't think of a better way to go about it. I would just rename the new option, but otherwise this seems to be it.

Show outdated Hide outdated protoc-gen-swagger/options/annotations.proto Outdated

@co3k co3k changed the title from protoc-gen-swagger: support JSON Schema Validation properties and add openapiv2_field_json_schema field option to protoc-gen-swagger: support JSON Schema Validation properties and add openapiv2_field option Jul 31, 2018

@co3k

This comment has been minimized.

Show comment
Hide comment
@co3k

co3k Jul 31, 2018

Contributor

I wonder why the Go: 1.10.x GATEWAY_PLUGIN_FLAGS= Travis CI build gets failed after my rebasing. I've tried make realclean examples but this problem isn't solved.

Contributor

co3k commented Jul 31, 2018

I wonder why the Go: 1.10.x GATEWAY_PLUGIN_FLAGS= Travis CI build gets failed after my rebasing. I've tried make realclean examples but this problem isn't solved.

@johanbrandhorst

This comment has been minimized.

Show comment
Hide comment
@johanbrandhorst

johanbrandhorst Jul 31, 2018

Collaborator

@co3k There's definitely something weird up with our CI pipeline at the moment, I'm trying to work out with the other maintainers what we need to do, sorry for the inconvenience. We'll get this change in as soon as possible!

Collaborator

johanbrandhorst commented Jul 31, 2018

@co3k There's definitely something weird up with our CI pipeline at the moment, I'm trying to work out with the other maintainers what we need to do, sorry for the inconvenience. We'll get this change in as soon as possible!

protoc-gen-swagger: support JSON Schema Validation properties and add…
… openapiv2_field option

This change supports [JSON Schema Validation](https://tools.ietf.org/html/draft-fge-json-schema-validation-00) properties.
It allows you to specify some validation rules in `openapiv2_schema` option and `openapiv2_field` option of your .proto files.
@co3k

This comment has been minimized.

Show comment
Hide comment
@co3k

co3k Aug 6, 2018

Contributor

Oh, I'm sorry...I've forgotten to do go get -u github.com/golang/protobuf/protoc-gen-go before my local building.

Finally, Travis CI builds have been passed.

Contributor

co3k commented Aug 6, 2018

Oh, I'm sorry...I've forgotten to do go get -u github.com/golang/protobuf/protoc-gen-go before my local building.

Finally, Travis CI builds have been passed.

@johanbrandhorst

This comment has been minimized.

Show comment
Hide comment
@johanbrandhorst

johanbrandhorst Aug 6, 2018

Collaborator

go get -u github.com/golang/protobuf/protoc-gen-go

You absolutely should not be expected to do this. Install it from the vendor folder: go install ./vendor/github.com/golang/protobuf/protoc-gen-go

Collaborator

johanbrandhorst commented Aug 6, 2018

go get -u github.com/golang/protobuf/protoc-gen-go

You absolutely should not be expected to do this. Install it from the vendor folder: go install ./vendor/github.com/golang/protobuf/protoc-gen-go

@johanbrandhorst johanbrandhorst merged commit 221ef34 into grpc-ecosystem:master Aug 6, 2018

2 checks passed

cla/google All necessary CLAs are signed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@johanbrandhorst

This comment has been minimized.

Show comment
Hide comment
@johanbrandhorst

johanbrandhorst Aug 6, 2018

Collaborator

Thanks for your contribution!

Collaborator

johanbrandhorst commented Aug 6, 2018

Thanks for your contribution!

@achew22

This comment has been minimized.

Show comment
Hide comment
@achew22

achew22 Aug 6, 2018

Collaborator

@johanbrandhorst would it be possible to have the Makefile build protoc-gen-go from the vendor directory and use it instead?

Collaborator

achew22 commented Aug 6, 2018

@johanbrandhorst would it be possible to have the Makefile build protoc-gen-go from the vendor directory and use it instead?

@johanbrandhorst

This comment has been minimized.

Show comment
Hide comment
@johanbrandhorst

johanbrandhorst Aug 6, 2018

Collaborator

@achew22 This was part of the change I made already:

go install ./vendor/$(GO_PLUGIN_PKG)

Collaborator

johanbrandhorst commented Aug 6, 2018

@achew22 This was part of the change I made already:

go install ./vendor/$(GO_PLUGIN_PKG)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment