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

protoc-gen-swagger: return error when encoding swagger file #878

Merged

Conversation

elliots
Copy link

@elliots elliots commented Feb 27, 2019

Json marshalling errors were being ignored, and it was generating a blank string swagger file.

This PR causes the error to be returned.

I ran into this (and it very well could be the only way this could happen) when using the json schema example option, which must be valid json.

For example:

message Request {
    option (grpc.gateway.protoc_gen_swagger.options.openapiv2_schema) = {
        example: { value: 'this is not json'}
    };

    bytes content = 90;
}

would silently fail.

Now, it fails like this:

failed to encode swagger for attachment/web/attachment.proto: json: error calling MarshalJSON for type json.RawMessage: invalid character 'h' in literal true (expecting 'r')

which isn't great, but is better.

I'm using this from inside https://github.com/utrack/clay/ but I think it would apply the same using it directly.

Previously, the error was being ignored
@codecov-io
Copy link

Codecov Report

Merging #878 into master will decrease coverage by 0.1%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #878      +/-   ##
==========================================
- Coverage   52.99%   52.88%   -0.11%     
==========================================
  Files          39       39              
  Lines        3910     3918       +8     
==========================================
  Hits         2072     2072              
- Misses       1642     1650       +8     
  Partials      196      196
Impacted Files Coverage Δ
protoc-gen-swagger/genswagger/generator.go 13.82% <0%> (-1.29%) ⬇️

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 70fc086...629afb0. Read the comment docs.

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.

Great work! Do you think you could add some tests here that trigger this behaviour as well?

Thanks!

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.

Ah this is fine as it is, don't want it to be forgotten.

@johanbrandhorst johanbrandhorst merged commit 9bb0d96 into grpc-ecosystem:master Mar 8, 2019
@johanbrandhorst
Copy link
Collaborator

Thanks for your contribution!

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