bufbuild / buf

The best way of working with Protocol Buffers.
https://buf.build
Apache License 2.0
9.18k stars 278 forks source link

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

Closed godcong closed 2 weeks ago

godcong commented 2 weeks ago

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 commented 2 weeks ago

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 commented 2 weeks ago

@doriable Thanks for the reply.

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

That's ok~