OpenAPI Swagger

Use protoc to generate openapi.yaml

The new project Makefile has been integrated by default with the commands associated with generating openapi.yaml, and here’s how to use them

Installation

First, install the protoc plug-in globally.

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

Generation

If you’re using kratos-layout, execute this command directly to generate.

  1. make api

Or you can use the protoc command directly at the root of the project, note that modifying the final proto file path of the command is the actual path

  1. protoc --proto_path=. \
  2. --proto_path=./third_party \
  3. --openapi_out=fq_schema_naming=true,default_response=false:. \
  4. api/helloworld/v1/greeter.proto

Usage

Once the above command has been executed successfully, the corresponding openapi.yaml file will be generated in the directory where your proto file is located. You can import it into any platform that supports the Open API specification for browsing, such as: