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

Read only support #882

Merged
merged 1 commit into from
Mar 1, 2019
Merged

Conversation

hypnoce
Copy link
Contributor

@hypnoce hypnoce commented Mar 1, 2019

Add read only support.

This helps simplifying asymmetry in request/response using the same proto message definition
For instance, a proto can define some HATEOAS links that are read-only that should not be present in the request body of PUT or POST but present in the response body of GET for instance.

What do you think ?

Thanks

@johanbrandhorst
Copy link
Collaborator

Looks like you need to rebase on master to start with.

@johanbrandhorst
Copy link
Collaborator

Note: these are normally simply documented as // Output Only in idiomatic protobuf: https://cloud.google.com/apis/design/design_patterns#output_fields. Since swagger supports this field, maybe we could detect this comment and translate the properties to use this too?

@hypnoce hypnoce force-pushed the read_only branch 2 times, most recently from c1de7cc to 5a7c48f Compare March 1, 2019 12:11
@hypnoce
Copy link
Contributor Author

hypnoce commented Mar 1, 2019

@johanbrandhorst PR updated with support for "Output only." comment on field. Added missing tests on updateSwaggerWithComment.

@johanbrandhorst
Copy link
Collaborator

The generate job is failing; did you run the generate job as described in CONTRIBUTING.md to regenerate the files?

@@ -1223,6 +1224,12 @@ func updateSwaggerDataFromComments(swaggerObject interface{}, comment string, is
// Figure out which properties to update.
summaryValue := infoObjectValue.FieldByName("Summary")
descriptionValue := infoObjectValue.FieldByName("Description")
readOnlyValue := infoObjectValue.FieldByName("ReadOnly")

if readOnlyValue.Kind() == reflect.Bool && readOnlyValue.CanSet() && strings.Contains(comment, "Output only.") {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 😎

* explicit swagger option on the field
* Implicit comment "Output only." on the field
@codecov-io
Copy link

Codecov Report

Merging #882 into master will increase coverage by 0.69%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #882      +/-   ##
==========================================
+ Coverage   52.99%   53.69%   +0.69%     
==========================================
  Files          39       39              
  Lines        3921     3926       +5     
==========================================
+ Hits         2078     2108      +30     
+ Misses       1647     1621      -26     
- Partials      196      197       +1
Impacted Files Coverage Δ
protoc-gen-swagger/genswagger/types.go 19.04% <ø> (ø) ⬆️
protoc-gen-swagger/genswagger/template.go 56.29% <100%> (+2.75%) ⬆️

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 0c2b3b1...251483a. Read the comment docs.

@hypnoce
Copy link
Contributor Author

hypnoce commented Mar 1, 2019

Do you think it's possible to release grpc-gateway at some point with the generated artifacts ?

@johanbrandhorst
Copy link
Collaborator

We automatically build binaries for all releases. We're planning on making another release soon!

Copy link
Collaborator

@johanbrandhorst johanbrandhorst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@johanbrandhorst johanbrandhorst merged commit 144843a into grpc-ecosystem:master Mar 1, 2019
adasari pushed a commit to adasari/grpc-gateway that referenced this pull request Apr 9, 2020
Can be set via:
* explicit swagger option on the field
* Implicit comment "Output only." on the field
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants