-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Fix: path item objects become block scalars [#3557] #3566
Conversation
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
WalkthroughThis pull request introduces enhancements to the YAML generation process in the Changes
TipsChat with CodeRabbit Bot (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 1
Files selected for processing (1)
- protoc-gen-openapiv2/internal/genopenapi/generator.go (1 hunks)
Additional comments (Suppressed): 3
protoc-gen-openapiv2/internal/genopenapi/generator.go (3)
150-163: The error handling here is correct and the logic for appending to
pathObjectNode.Content
is improved compared to the old hunk. The new implementation correctly creates a YAML node fromPathItemObject
and appends it to the content ofpathObjectNode
.166-190: This workaround for the go-yaml bug seems reasonable, but it's important to keep track of the issue at v3: Invalid output (bad indentation) when an indentation indicator/hint is used in a scalar block go-yaml/yaml#643. Once it's resolved, the commented-out simpler implementation should be reinstated.
- // We can simplify this implementation once the go-yaml bug is resolved. See: https://github.com/go-yaml/yaml/issues/643. - // - // func (pio *openapiPathItemObject) toYAMLNode() (*yaml.Node, error) { - // var node yaml.Node - // if err := node.Encode(pio); err != nil { - // return nil, err - // } - // return &node, nil - // }
- 192-194: No issues found in these lines. The aliasing technique used here is a common way to handle JSON marshaling with embedded structs that also need to be marshaled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, thanks for this PR! Any chance you could add a test file that exhibits the old, bad behaviour, so we know this is now fixed? Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Files ignored due to filter (1)
- protoc-gen-openapiv2/internal/genopenapi/testdata/generator/path_item_object.swagger.yaml
Files selected for processing (1)
- protoc-gen-openapiv2/internal/genopenapi/generator_test.go (2 hunks)
Additional comments (Suppressed): 2
protoc-gen-openapiv2/internal/genopenapi/generator_test.go (2)
1-13: The import of the
os
package is new and necessary for file operations in the newly added test functionTestGenerateYAML
. The rest of the imports are unchanged.125-170: This new test function
TestGenerateYAML
is well written. It reads input from a file, performs code generation, and compares the generated content with an expected output file. This is a good way to ensure that the YAML generation is working as expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Files selected for processing (1)
- protoc-gen-openapiv2/internal/genopenapi/generator_test.go (2 hunks)
Additional comments (Suppressed): 2
protoc-gen-openapiv2/internal/genopenapi/generator_test.go (2)
1-13: The import of
"os"
is new in this hunk. Ensure that theos
package is used appropriately and securely, especially when dealing with file operations.125-171: This new test function
TestGenerateYAML
is well written and covers the case where a YAML file is generated from a.prototext
file and compared with an expected output. It's good to see that error handling is properly done for file reading and unmarshalling operations. The use of table-driven tests also enhances the maintainability and readability of the test cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Files selected for processing (1)
- protoc-gen-openapiv2/internal/genopenapi/generator_test.go (2 hunks)
Additional comments (Suppressed): 2
protoc-gen-openapiv2/internal/genopenapi/generator_test.go (2)
1-13: The import of the
os
package is new in this hunk. It's used for reading files in the newly added test functionTestGenerateYAML
. Thecmp
package is also imported, which is used for comparing the expected and actual output in the tests.125-171: This new test function
TestGenerateYAML
validates the generation of YAML files. It reads input from a file, generates code, and compares the output with an expected result. The test ensures that the generated YAML matches the expected output, thereby validating the fix for the original issue. This is a good addition to the test suite as it directly verifies the functionality being addressed by this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Files ignored due to filter (1)
- protoc-gen-openapiv2/internal/genopenapi/testdata/generator/path_item_object.swagger.yaml
Files selected for processing (1)
- protoc-gen-openapiv2/internal/genopenapi/testdata/generator/path_item_object.prototext (1 hunks)
Additional comments (Suppressed): 1
protoc-gen-openapiv2/internal/genopenapi/testdata/generator/path_item_object.prototext (1)
- 1-32: The protobuf definition seems to be correctly defined. The service
YourService
with the methodEcho
is well defined and the HTTP binding is correctly set up with a POST request to/api/echo
. The messageStringMessage
is also correctly defined with an optional string fieldvalue
. The go package option is correctly set to"github.com/yourorg/yourprotos/gen/go/your/service/v1"
.
It looks like you need to regenerate one of the bazel files, there are instructions in CONTRIBUTING.md, thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regenerate bazel files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Files selected for processing (1)
- protoc-gen-openapiv2/internal/genopenapi/BUILD.bazel (1 hunks)
Additional comments (Suppressed): 2
protoc-gen-openapiv2/internal/genopenapi/BUILD.bazel (2)
52-52: The use of
glob(["testdata/**"])
ensures that all files under thetestdata
directory are included during the build process. This is a good practice as it allows for automated testing with various input data.53-53: The
embed = [":genopenapi"]
line indicates that thegenopenapi
library is embedded in the test. This is a standard practice in Bazel to include the library being tested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you!
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [github.com/grpc-ecosystem/grpc-gateway/v2](https://togithub.com/grpc-ecosystem/grpc-gateway) | require | minor | `v2.16.0` -> `v2.18.0` | | [google.golang.org/protobuf](https://togithub.com/protocolbuffers/protobuf-go) | require | minor | `v1.30.0` -> `v1.31.0` | | | | lockFileMaintenance | All locks refreshed | | [jekyll-feed](https://togithub.com/jekyll/jekyll-feed) | | minor | `0.15.1` -> `0.17.0` | --- ### Release Notes <details> <summary>grpc-ecosystem/grpc-gateway (github.com/grpc-ecosystem/grpc-gateway/v2)</summary> ### [`v2.18.0`](https://togithub.com/grpc-ecosystem/grpc-gateway/releases/tag/v2.18.0) [Compare Source](https://togithub.com/grpc-ecosystem/grpc-gateway/compare/v2.17.1...v2.18.0) #### What's Changed - Enable a few more golangci-lint linters by [@​pkwarren](https://togithub.com/pkwarren) in [https://github.com/grpc-ecosystem/grpc-gateway/pull/3546](https://togithub.com/grpc-ecosystem/grpc-gateway/pull/3546) - Add .golangci.yml config by [@​pkwarren](https://togithub.com/pkwarren) in [https://github.com/grpc-ecosystem/grpc-gateway/pull/3548](https://togithub.com/grpc-ecosystem/grpc-gateway/pull/3548) - Fix: path item objects become block scalars \[[#​3557](https://togithub.com/grpc-ecosystem/grpc-gateway/issues/3557)] by [@​qawatake](https://togithub.com/qawatake) in [https://github.com/grpc-ecosystem/grpc-gateway/pull/3566](https://togithub.com/grpc-ecosystem/grpc-gateway/pull/3566) - Add remove_internal_comments option by [@​same-id](https://togithub.com/same-id) in [https://github.com/grpc-ecosystem/grpc-gateway/pull/3560](https://togithub.com/grpc-ecosystem/grpc-gateway/pull/3560) #### New Contributors - [@​benjx1990](https://togithub.com/benjx1990) made their first contribution in [https://github.com/grpc-ecosystem/grpc-gateway/pull/3552](https://togithub.com/grpc-ecosystem/grpc-gateway/pull/3552) - [@​qawatake](https://togithub.com/qawatake) made their first contribution in [https://github.com/grpc-ecosystem/grpc-gateway/pull/3566](https://togithub.com/grpc-ecosystem/grpc-gateway/pull/3566) **Full Changelog**: grpc-ecosystem/grpc-gateway@v2.17.1...v2.18.0 ### [`v2.17.1`](https://togithub.com/grpc-ecosystem/grpc-gateway/releases/tag/v2.17.1) [Compare Source](https://togithub.com/grpc-ecosystem/grpc-gateway/compare/v2.17.0...v2.17.1) #### What's Changed - genopenapi: set source code info explicitly by [@​johanbrandhorst](https://togithub.com/johanbrandhorst) in [https://github.com/grpc-ecosystem/grpc-gateway/pull/3544](https://togithub.com/grpc-ecosystem/grpc-gateway/pull/3544) - Record the filename of files that are missing SourceCodeInfo by [@​ebilling](https://togithub.com/ebilling) in [https://github.com/grpc-ecosystem/grpc-gateway/pull/3545](https://togithub.com/grpc-ecosystem/grpc-gateway/pull/3545) #### New Contributors - [@​ebilling](https://togithub.com/ebilling) made their first contribution in [https://github.com/grpc-ecosystem/grpc-gateway/pull/3545](https://togithub.com/grpc-ecosystem/grpc-gateway/pull/3545) **Full Changelog**: grpc-ecosystem/grpc-gateway@v2.17.0...v2.17.1 ### [`v2.17.0`](https://togithub.com/grpc-ecosystem/grpc-gateway/releases/tag/v2.17.0) [Compare Source](https://togithub.com/grpc-ecosystem/grpc-gateway/compare/v2.16.2...v2.17.0) #### What's Changed - Fix renovate.yml overwriting .bazelrc by [@​adambabik](https://togithub.com/adambabik) in [https://github.com/grpc-ecosystem/grpc-gateway/pull/3451](https://togithub.com/grpc-ecosystem/grpc-gateway/pull/3451) - fix: successful typo by [@​testwill](https://togithub.com/testwill) in [https://github.com/grpc-ecosystem/grpc-gateway/pull/3510](https://togithub.com/grpc-ecosystem/grpc-gateway/pull/3510) - Update example buf.gen.yaml by [@​pkwarren](https://togithub.com/pkwarren) in [https://github.com/grpc-ecosystem/grpc-gateway/pull/3522](https://togithub.com/grpc-ecosystem/grpc-gateway/pull/3522) - fix(deps): replace all uses of golang/protobuf/protobuf by [@​aimuz](https://togithub.com/aimuz) in [https://github.com/grpc-ecosystem/grpc-gateway/pull/3516](https://togithub.com/grpc-ecosystem/grpc-gateway/pull/3516) - Feature/issue 3051 swagger preserve rpc order by [@​CemGurhan](https://togithub.com/CemGurhan) in [https://github.com/grpc-ecosystem/grpc-gateway/pull/3500](https://togithub.com/grpc-ecosystem/grpc-gateway/pull/3500) #### New Contributors - [@​testwill](https://togithub.com/testwill) made their first contribution in [https://github.com/grpc-ecosystem/grpc-gateway/pull/3510](https://togithub.com/grpc-ecosystem/grpc-gateway/pull/3510) - [@​pkwarren](https://togithub.com/pkwarren) made their first contribution in [https://github.com/grpc-ecosystem/grpc-gateway/pull/3522](https://togithub.com/grpc-ecosystem/grpc-gateway/pull/3522) - [@​aimuz](https://togithub.com/aimuz) made their first contribution in [https://github.com/grpc-ecosystem/grpc-gateway/pull/3516](https://togithub.com/grpc-ecosystem/grpc-gateway/pull/3516) - [@​CemGurhan](https://togithub.com/CemGurhan) made their first contribution in [https://github.com/grpc-ecosystem/grpc-gateway/pull/3500](https://togithub.com/grpc-ecosystem/grpc-gateway/pull/3500) **Full Changelog**: grpc-ecosystem/grpc-gateway@v2.16.2...v2.17.0 ### [`v2.16.2`](https://togithub.com/grpc-ecosystem/grpc-gateway/releases/tag/v2.16.2) [Compare Source](https://togithub.com/grpc-ecosystem/grpc-gateway/compare/v2.16.1...v2.16.2) #### What's Changed - chore: replace the Goreleaser's deprecated option `--rm-dist` to `--clean` by [@​suzuki-shunsuke](https://togithub.com/suzuki-shunsuke) in [https://github.com/grpc-ecosystem/grpc-gateway/pull/3438](https://togithub.com/grpc-ecosystem/grpc-gateway/pull/3438) - chore: stop using the deprecated field `archives.replacements` by [@​suzuki-shunsuke](https://togithub.com/suzuki-shunsuke) in [https://github.com/grpc-ecosystem/grpc-gateway/pull/3436](https://togithub.com/grpc-ecosystem/grpc-gateway/pull/3436) #### New Contributors - [@​suzuki-shunsuke](https://togithub.com/suzuki-shunsuke) made their first contribution in [https://github.com/grpc-ecosystem/grpc-gateway/pull/3438](https://togithub.com/grpc-ecosystem/grpc-gateway/pull/3438) **Full Changelog**: grpc-ecosystem/grpc-gateway@v2.16.1...v2.16.2 ### [`v2.16.1`](https://togithub.com/grpc-ecosystem/grpc-gateway/releases/tag/v2.16.1) [Compare Source](https://togithub.com/grpc-ecosystem/grpc-gateway/compare/v2.16.0...v2.16.1) #### What's Changed - Rename LICENSE.txt to LICENSE by [@​pgmitche](https://togithub.com/pgmitche) in [https://github.com/grpc-ecosystem/grpc-gateway/pull/3345](https://togithub.com/grpc-ecosystem/grpc-gateway/pull/3345) - feat: message supports enum field option for query params by [@​zhb127](https://togithub.com/zhb127) in [https://github.com/grpc-ecosystem/grpc-gateway/pull/3352](https://togithub.com/grpc-ecosystem/grpc-gateway/pull/3352) - remove glog from a bunch of spots by [@​kn100](https://togithub.com/kn100) in [https://github.com/grpc-ecosystem/grpc-gateway/pull/3361](https://togithub.com/grpc-ecosystem/grpc-gateway/pull/3361) - Improve AIP support in field_configuration.path_param_name containing by [@​same-id](https://togithub.com/same-id) in [https://github.com/grpc-ecosystem/grpc-gateway/pull/3364](https://togithub.com/grpc-ecosystem/grpc-gateway/pull/3364) - Hide comments on omitted enum default values by [@​same-id](https://togithub.com/same-id) in [https://github.com/grpc-ecosystem/grpc-gateway/pull/3366](https://togithub.com/grpc-ecosystem/grpc-gateway/pull/3366) - fix(docs): correcting mux routing error code example by [@​tjasko](https://togithub.com/tjasko) in [https://github.com/grpc-ecosystem/grpc-gateway/pull/3409](https://togithub.com/grpc-ecosystem/grpc-gateway/pull/3409) - Fix the place where format property in placed for repeated fields by [@​far4599](https://togithub.com/far4599) in [https://github.com/grpc-ecosystem/grpc-gateway/pull/3410](https://togithub.com/grpc-ecosystem/grpc-gateway/pull/3410) - Handle httpbody not having data to return by [@​achew22](https://togithub.com/achew22) in [https://github.com/grpc-ecosystem/grpc-gateway/pull/3415](https://togithub.com/grpc-ecosystem/grpc-gateway/pull/3415) - bazel: bump Bazel repositories versions by [@​adambabik](https://togithub.com/adambabik) in [https://github.com/grpc-ecosystem/grpc-gateway/pull/3413](https://togithub.com/grpc-ecosystem/grpc-gateway/pull/3413) #### New Contributors - [@​pgmitche](https://togithub.com/pgmitche) made their first contribution in [https://github.com/grpc-ecosystem/grpc-gateway/pull/3345](https://togithub.com/grpc-ecosystem/grpc-gateway/pull/3345) - [@​zhb127](https://togithub.com/zhb127) made their first contribution in [https://github.com/grpc-ecosystem/grpc-gateway/pull/3352](https://togithub.com/grpc-ecosystem/grpc-gateway/pull/3352) - [@​kn100](https://togithub.com/kn100) made their first contribution in [https://github.com/grpc-ecosystem/grpc-gateway/pull/3361](https://togithub.com/grpc-ecosystem/grpc-gateway/pull/3361) - [@​tjasko](https://togithub.com/tjasko) made their first contribution in [https://github.com/grpc-ecosystem/grpc-gateway/pull/3409](https://togithub.com/grpc-ecosystem/grpc-gateway/pull/3409) - [@​far4599](https://togithub.com/far4599) made their first contribution in [https://github.com/grpc-ecosystem/grpc-gateway/pull/3410](https://togithub.com/grpc-ecosystem/grpc-gateway/pull/3410) **Full Changelog**: grpc-ecosystem/grpc-gateway@v2.16.0...v2.16.1 </details> <details> <summary>protocolbuffers/protobuf-go (google.golang.org/protobuf)</summary> ### [`v1.31.0`](https://togithub.com/protocolbuffers/protobuf-go/releases/tag/v1.31.0) [Compare Source](https://togithub.com/protocolbuffers/protobuf-go/compare/v1.30.0...v1.31.0) #### Notable changes <a name="v1.31-notable-changes"></a> **New Features** - [CL/489316](https://go.dev/cl/489316): types/dynamicpb: add NewTypes - Add a function to construct a dynamic type registry from a protoregistry.Files - [CL/489615](https://go.dev/cl/489615): encoding: add MarshalAppend to protojson and prototext **Minor performance improvements** - [CL/491596](https://go.dev/cl/491596): encoding/protodelim: If UnmarshalFrom gets a bufio.Reader, try to reuse its buffer instead of creating a new one - [CL/500695](https://go.dev/cl/500695): proto: store the size of tag to avoid multiple calculations **Bug fixes** - [CL/497935](https://go.dev/cl/497935): internal/order: fix sorting of synthetic oneofs to be deterministic - [CL/505555](https://go.dev/cl/505555): encoding/protodelim: fix handling of io.EOF </details> <details> <summary>jekyll/jekyll-feed (jekyll-feed)</summary> ### [`v0.17.0`](https://togithub.com/jekyll/jekyll-feed/blob/HEAD/History.markdown#0170--2022-10-14) [Compare Source](https://togithub.com/jekyll/jekyll-feed/compare/v0.16.0...v0.17.0) ##### Documentation - Update CI status badge ([#​363](https://togithub.com/jekyll/jekyll-feed/issues/363)) ##### Development Fixes - Add Ruby 3.1 to the CI matrix ([#​365](https://togithub.com/jekyll/jekyll-feed/issues/365)) ##### Minor Enhancements - Allow disabling of jekyll-feed while in development ([#​370](https://togithub.com/jekyll/jekyll-feed/issues/370)) ### [`v0.16.0`](https://togithub.com/jekyll/jekyll-feed/blob/HEAD/History.markdown#0160--2022-01-03) [Compare Source](https://togithub.com/jekyll/jekyll-feed/compare/v0.15.1...v0.16.0) ##### Minor Enhancements - Add support for `page.description` in front matter to become entry `<summary>` ([#​297](https://togithub.com/jekyll/jekyll-feed/issues/297)) ##### Bug Fixes - Fold private methods into the `:render` method as local variables ([#​327](https://togithub.com/jekyll/jekyll-feed/issues/327)) - Check `post.categories` instead of `post.category` ([#​357](https://togithub.com/jekyll/jekyll-feed/issues/357)) - Switched xml_escape for `<![CDATA[]]>` for post content ([#​332](https://togithub.com/jekyll/jekyll-feed/issues/332)) ##### Development Fixes - Add Ruby 3.0 to CI ([#​337](https://togithub.com/jekyll/jekyll-feed/issues/337)) - Lock RuboCop to v1.18.x ([#​348](https://togithub.com/jekyll/jekyll-feed/issues/348)) - Add workflow to release gem via GH Action ([#​355](https://togithub.com/jekyll/jekyll-feed/issues/355)) ##### Documentation - Use `.atom` extension in documented examples since we write an Atom feed ([#​359](https://togithub.com/jekyll/jekyll-feed/issues/359)) </details> --- ### Configuration 📅 **Schedule**: Branch creation - "before 6am on wednesday" in timezone Australia/Sydney, Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 👻 **Immortal**: This PR will be recreated if closed unmerged. Get [config help](https://togithub.com/renovatebot/renovate/discussions) if that's undesired. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/google/osv.dev). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNi42OC4xIiwidXBkYXRlZEluVmVyIjoiMzYuODMuMCIsInRhcmdldEJyYW5jaCI6Im1hc3RlciJ9-->
- Enable a few more golangci-lint linters [#3546](grpc-ecosystem/grpc-gateway#3546) - Add .golangci.yml config [#3548](grpc-ecosystem/grpc-gateway#3548) - Fix: path item objects become block scalars [#3566](grpc-ecosystem/grpc-gateway#3566) - Add remove_internal_comments option [#3560](grpc-ecosystem/grpc-gateway#3560)
- Enable a few more golangci-lint linters [#3546](grpc-ecosystem/grpc-gateway#3546) - Add .golangci.yml config [#3548](grpc-ecosystem/grpc-gateway#3548) - Fix: path item objects become block scalars [#3566](grpc-ecosystem/grpc-gateway#3566) - Add remove_internal_comments option [#3560](grpc-ecosystem/grpc-gateway#3560)
- Enable a few more golangci-lint linters [#3546](grpc-ecosystem/grpc-gateway#3546) - Add .golangci.yml config [#3548](grpc-ecosystem/grpc-gateway#3548) - Fix: path item objects become block scalars [#3566](grpc-ecosystem/grpc-gateway#3566) - Add remove_internal_comments option [#3560](grpc-ecosystem/grpc-gateway#3560)
- Enable a few more golangci-lint linters [#3546](grpc-ecosystem/grpc-gateway#3546) - Add .golangci.yml config [#3548](grpc-ecosystem/grpc-gateway#3548) - Fix: path item objects become block scalars [#3566](grpc-ecosystem/grpc-gateway#3566) - Add remove_internal_comments option [#3560](grpc-ecosystem/grpc-gateway#3560)
References to other Issues or PRs
Fixes #3557
Have you read the Contributing Guidelines?
Yes.
Brief description of what is fixed or changed
Fixes a bug where the path item object is marshaled as a block scalar in openapiv2 v2.17.0 and later.
Other comments
Summary by CodeRabbit
MarshalYAML
method ingenerator.go
to use a newtoYAMLNode
method for convertingPathItemObject
to a YAML node. This change addresses a bug in the go-yaml library.TestGenerateYAML
ingenerator_test.go
to validate the generation of YAML files from protobuf input.path_item_object.prototext
for testing purposes, which includes a service definition and a message type.go_test
rule inBUILD.bazel
to include all files under thetestdata
directory during the build process.