You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It seems that it is not possible to generate a single, combined swagger.json file when using gateway_openapiv2_compile with multiple proto file inputs.
The openapiv2 protoc plugin has allow_merge=true and merge_file_name={name}.json options that allow for the creation of a single, combined swagger.json file. When attempting to use those options with gateway_openapiv2_compile the build fails because the expected outputs are not generated.
merged_swagger.json DOES get generated but the expected a.swagger.json and b.swagger.json are not generated which causes the build to fail. This is due to this block of code in modules/core/internal/compile.bzl that specifies the plugin_outputs without an option to override:
for proto_info in proto_infos:
for proto in proto_info.direct_sources:
# Check for exclusion
if any([
proto.dirname.endswith(exclusion) or proto.path.endswith(exclusion)
for exclusion in plugin.exclusions
]) or proto in protos:
# When using import_prefix, the ProtoInfo.direct_sources list appears to contain
# duplicate records, the final check 'proto in protos' removes these. See
# https://github.com/bazelbuild/bazel/issues/9127
continue
# Proto not excluded
protos.append(proto)
# Add per-proto outputs
for pattern in plugin.outputs:
plugin_outputs.append(ctx.actions.declare_file("{}/{}".format(
rel_premerge_root,
get_output_filename(proto, pattern, proto_info),
)))
# Get proto path for protoc
proto_paths.append(descriptor_proto_path(proto, proto_info))
As seen in this issue comment a possible remedy for this is to create a new plugin that sets output_directory=True instead of outputs = ["{protopath}.swagger.json"] which allows the build to succeed.
From reading over the code I'm not quite sure what the right remedy is. The fundamental issue with gateway_openapiv2_compile seems to be that options can be passed to protoc which change its outputs and the implementation of this rule does not support that functionality. I seems that perhaps outputs = ["{protopath}.swagger.json"] should not be hardcoded into the proto_plugin definition because it's not always the case that we want a separate swagger.json file per proto but again, I'm not sure how best to change the code to account for this case.
I think that I may go the route of defining my own, slightly modified proto_plugin and associated rule or perhaps just use a genrule to generate combined swagger the file that I want. I'm curious what others have done when they've encountered this problem.
If there's an obvious solution that I've missed or I've misread the code and it is indeed possible to generate a single, combined swagger file I'd love to know that as well. Cheers!
Log Output
No response
rules_proto_grpc Version
4.1.1, 5.0.0
Bazel Version
6.4.0
OS
Ubuntu
Link to Demo Repo
No response
MODULE.bazel or WORKSPACE Content
No response
BUILD Content
No response
Proto Content
No response
Any Other Content
No response
The text was updated successfully, but these errors were encountered:
gateway_openapiv2_compile_combined_swagger(
name = "gateway_swagger",
options = {
# the leading @ is important so the Label function does not prepend @rules_proto_grpc to this string
"@//path/to/my/plugin:openapiv2_plugin_custom": [
"allow_merge=true",
"merge_file_name=combined",
],
},
protos = [....],
)
I hope this helps anyone else that runs into this issue.
Issue Description
It seems that it is not possible to generate a single, combined swagger.json file when using
gateway_openapiv2_compile
with multiple proto file inputs.The openapiv2 protoc plugin has
allow_merge=true
andmerge_file_name={name}.json
options that allow for the creation of a single, combined swagger.json file. When attempting to use those options withgateway_openapiv2_compile
the build fails because the expected outputs are not generated.merged_swagger.json
DOES get generated but the expecteda.swagger.json
andb.swagger.json
are not generated which causes the build to fail. This is due to this block of code inmodules/core/internal/compile.bzl
that specifies theplugin_outputs
without an option to override:As seen in this issue comment a possible remedy for this is to create a new plugin that sets
output_directory=True
instead ofoutputs = ["{protopath}.swagger.json"]
which allows the build to succeed.From reading over the code I'm not quite sure what the right remedy is. The fundamental issue with
gateway_openapiv2_compile
seems to be that options can be passed to protoc which change its outputs and the implementation of this rule does not support that functionality. I seems that perhapsoutputs = ["{protopath}.swagger.json"]
should not be hardcoded into theproto_plugin
definition because it's not always the case that we want a separateswagger.json
file per proto but again, I'm not sure how best to change the code to account for this case.I think that I may go the route of defining my own, slightly modified
proto_plugin
and associated rule or perhaps just use agenrule
to generate combined swagger the file that I want. I'm curious what others have done when they've encountered this problem.If there's an obvious solution that I've missed or I've misread the code and it is indeed possible to generate a single, combined swagger file I'd love to know that as well. Cheers!
Log Output
No response
rules_proto_grpc Version
4.1.1, 5.0.0
Bazel Version
6.4.0
OS
Ubuntu
Link to Demo Repo
No response
MODULE.bazel or WORKSPACE Content
No response
BUILD Content
No response
Proto Content
No response
Any Other Content
No response
The text was updated successfully, but these errors were encountered: