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

OpenAPIv2 YAML format does not include extensions #2795

Closed
hasit opened this issue Jul 15, 2022 · 9 comments · Fixed by #2797
Closed

OpenAPIv2 YAML format does not include extensions #2795

hasit opened this issue Jul 15, 2022 · 9 comments · Fixed by #2797

Comments

@hasit
Copy link

hasit commented Jul 15, 2022

🐛 Bug Report

I have a field bar in a message Foo for which I would like to generate swagger documentation.

message Foo {
  google.protobuf.Duration bar = 2 [(grpc.gateway.protoc_gen_openapiv2.options.openapiv2_field) = {
    description: "This is bar"
    extensions: {
      key: "x-go-default";
      value {
        string_value: "0.5s"
      }
    }
  }]; // @gotags: default:"0.5s"
}

Upon generation, I see the description field being generated correctly, but not the x-go-default field.

To Reproduce

I use the following buf.gen.yaml openapiv2 plugin options:

  - remote: buf.build/grpc-ecosystem/plugins/openapiv2:v2.10.3-1
    out: gen/openapiv2
    opt:
      - json_names_for_fields=false
      - merge_file_name=file
      - allow_merge=true
      - output_format=yaml
      - generate_unbound_methods=true

After changing output_format=yaml to output_format=json , the x-* fields started showing up.

Expected behavior

Expect output to contain x-go-default field populated with "0.5s" value.

Actual Behavior

Actual output contains all fields apart from the extensions provided.

Your Environment

Remote plugin via buf: buf.build/grpc-ecosystem/plugins/openapiv2:v2.10.3-1
Operating system: Pop!_OS 22.04 LTS x86_64

@hasit
Copy link
Author

hasit commented Jul 15, 2022

cc: @hedhyw

@johanbrandhorst
Copy link
Collaborator

Thanks for this detailed issue. If someone is interested in trying to fix this, I would suggest starting by adding a failing test. Look at the tests added in #2579 for inspiration.

As a workaround for this issue, there appear to be lots of different tools available for converting JSON to YAML as a post-processing step: https://www.google.com/search?client=firefox-b-d&q=json2yaml.

@hedhyw
Copy link
Contributor

hedhyw commented Jul 16, 2022

Fixed in PR #2797

@hasit Please check it on your project.

@hasit
Copy link
Author

hasit commented Jul 18, 2022

@johanbrandhorst Yes that is what we started doing as soon as we found the bug.

@hasit
Copy link
Author

hasit commented Jul 18, 2022

@hedhyw I am not sure how I could verify this change. I am using buf to run this plugin

  - remote: buf.build/grpc-ecosystem/plugins/openapiv2:v2.10.3-1
    out: gen/openapiv2
    opt:
      - json_names_for_fields=false
      - merge_file_name=file
      - allow_merge=true
      - output_format=json
      - generate_unbound_methods=true

@johanbrandhorst
Copy link
Collaborator

@hasit it won't be available on the BSR until we've made a release. If you want to test the change locally, you'll have to build a binary locally. Since the PR is on a fork, it's a little complicated to test before we've merged it. You could check out the PR locally and run go build ./protoc-gen-openapiv2 and then use the following buf.gen.yaml:

  - name: openapiv2
    path: ./<path to built protoc-gen-openapiv2>
    out: gen/openapiv2
    opt:
      - json_names_for_fields=false
      - merge_file_name=file
      - allow_merge=true
      - output_format=json
      - generate_unbound_methods=true

But we should get this merged soon, I'm looking at the PR, and then you can install directly using go install.

johanbrandhorst pushed a commit that referenced this issue Jul 18, 2022
* fix: Support extensions for YAML [#2795]

* Move extensionsToMap to generator

* bazel fix

* define map size
@johanbrandhorst
Copy link
Collaborator

We'll get this released soon, it's about time for another release, but if you want to test this in the meantime, you should now able to install protoc-gen-openapiv2 via:

go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2@master

@hasit
Copy link
Author

hasit commented Jul 18, 2022

@johanbrandhorst wonderful! Thanks to you and @hedhyw :)

@johanbrandhorst
Copy link
Collaborator

This has been released in https://github.com/grpc-ecosystem/grpc-gateway/releases/tag/v2.11.0

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

Successfully merging a pull request may close this issue.

3 participants