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

[BUG]Error generating openapi.yaml when proto is in multiple directories. #3456

Closed
godcong opened this issue Nov 8, 2024 · 2 comments
Closed
Labels
Bug Something isn't working

Comments

@godcong
Copy link

godcong commented Nov 8, 2024

GitHub repository with your minimal reproducible example (do not leave this field blank or fill out this field with "github.com/bufbuild/buf" or we will automatically close your issue, see the instructions above!)

https://github.com/origadmin/basic-layout

Commands

go generate
# runs 
# go:generate buf dep update
# go:generate buf build
# go:generate buf generate

# correct run
make openapi

Output

duplicate generated file name "openapi.yaml". Generation will continue without error here and drop the second occurrence of this file, but please raise an issue with the maintainer of the plugin.

Expected Output

output api into openapi.yaml with no errors

Anything else?

The openapi tool used

	go install github.com/google/gnostic/cmd/protoc-gen-openapi@latest

and uncomment this at file buf.gen.yaml on root directory:

  - local: protoc-gen-openapi
    out: resources/docs/openapi
    opt:
      - naming=proto # Naming convention. Using "proto" passes the name directly from the proto file. The default value is json
      #      - depth=2 # Recursion depth of the loop message. The default value is 2
      #      - default_response=false # Adds a default response message. If true, a default response is automatically added for actions using the google.rpc.Status message. This is useful if you use envoy or grpc-gateway for transcoding, as they use this type as the default error response. Default value: true.
      #      - enum_type=string # Serialized type of enumeration type. Use "string" for string-based serialization. The default value is integer.
      - output_mode=merge # Output file generation mode. By default, only one openapi.yaml file is generated in the output folder. Using "source_relative" generates a separate "[inputfile].openapi.yaml" file for each '[inputfile].proto' file. The default is: merged.
      - fq_schema_naming=true # Schema named whether to add a package name, is true, will add a package name, for example: system. Service. V1. ListDictDetailResponse, otherwise as follows: ListDictDetailResponse. The default value is false.

It looks like, buf is splitting the proto into multiple commands for different directories.

@doriable
Copy link
Member

doriable commented Nov 8, 2024

I cloned the repro and unfortunately there doesn't seem to be a buf.gen.yaml present in the repository you provided?

That being said, looking at your issue description:

It looks like, buf is splitting the proto into multiple commands for different directories.

The strategy key in buf.gen.yaml might be helpful to you. The default is to split the input file by directory and run the plugin across each. However, if you set strategy: all for your plugin, it will run the plugin against your entire.

@godcong
Copy link
Author

godcong commented Nov 8, 2024

@doriable Thanks for the reply.

I fixed buf.gen.yaml
https://github.com/origadmin/basic-layout/blob/a84adaa12633071b85cdb1645d71007f8338f0cb/buf.gen.yaml

That's ok~

@godcong godcong closed this as completed Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants