|
1 | 1 | # protoc-gen-openapi |
2 | 2 |
|
3 | | -> This directory contains a protoc plugin that generates an |
4 | | -OpenAPI description for a REST API that corresponds to a |
5 | | -Protocol Buffer service. |
| 3 | +- 本项目一个 protobuf openapi 插件的实现 |
| 4 | +- 本项目早期参考了[protoc-gen-openapi](https://github.com/google/gnostic/tree/master/cmd/protoc-gen-openapi), 由于 gnostic 长时间不更新,并发现了优秀的替代品[protoc-gen-connect-openapi](https://github.com/sudorandom/protoc-gen-connect-openapi), 现在基于[protoc-gen-connect-openapi](https://github.com/sudorandom/protoc-gen-connect-openapi) 做了部分修改 |
| 5 | +- internal/converter 大部分都是来自于 protoc-gen-connect-openapi, copy.go 部分是自己的实现 |
6 | 6 |
|
7 | | -> This project is a simplification of the [google/gnostic](https://github.com/google/gnostic/tree/main/openapiv3) project, dedicated to providing a simple version of the protoc-gen-openapi |
| 7 | +## 为什么修改 protoc-gen-connect-openapi |
| 8 | +- protoc-gen-connect-openapi 刚好和本项目早期底层使用一致, 为本项目重构提供了很好的思路和想法 |
| 9 | +- protoc-gen-connect-openapi 是为了 connect-go 生成 openapi 文档, 包含不少 connect 关键词 |
| 10 | +- protoc-gen-connect-openapi 不支持 grpc service 级别的注解 |
| 11 | +- protoc-gen-connect-openapi 针对企业内部业务级别的修改无法支持 |
8 | 12 |
|
9 | | -Installation: |
| 13 | +## 改动部分 |
10 | 14 |
|
11 | | - go install github.com/pubgo/protoc-gen-openapi@latest |
| 15 | +- 使用原生的 [google.golang.org/protobuf/compiler/protogen](https://pkg.go.dev/google.golang.org/protobuf/compiler/protogen) |
| 16 | +- 添加了 grpc service 级别的注解 [service.proto](./proto/openapiv3/service.proto), [example](./examples/tests/openapiv3annotations/message.proto) |
| 17 | +- 添加了 [lava](https://github.com/pubgo/lava) 相关的 header 信息 |
| 18 | +- 添加了 Error Code 定义 [error.proto](https://github.com/pubgo/funk/blob/master/proto/errorpb/errors.proto) |
| 19 | +- 使用 [protobuild](https://github.com/pubgo/protobuild) 进行 protobuf 构建和管理 |
| 20 | + |
| 21 | + ## Installation: |
12 | 22 |
|
13 | | -Usage: |
| 23 | + go install github.com/pubgo/protoc-gen-openapi@latest |
14 | 24 |
|
15 | | - protoc sample.proto -I=. --openapi_out=. |
| 25 | +## 使用 |
16 | 26 |
|
17 | | -This runs the plugin for a file named `sample.proto` which |
18 | | -refers to additional .proto files in the same directory as |
19 | | -`sample.proto`. Output is written to the current directory. |
| 27 | +参考 `make protobuf_test` |
20 | 28 |
|
21 | | -## options |
| 29 | +## 计划 |
22 | 30 |
|
23 | | -1. `version`: version number text, e.g. 1.2.3 |
24 | | - - **default**: `0.0.1` |
25 | | -2. `title`: name of the API |
26 | | - - **default**: empty string or service name if there is only one service |
27 | | -3. `description`: description of the API |
28 | | - - **default**: empty string or service description if there is only one service |
29 | | -4. `naming`: naming convention. Use "proto" for passing names directly from the proto files |
30 | | - - **default**: `json` |
31 | | - - `json`: will turn field `updated_at` to `updatedAt` |
32 | | - - `proto`: keep field `updated_at` as it is |
33 | | -5. `fq_schema_naming`: schema naming convention. If "true", generates fully-qualified schema names by prefixing them with the proto message package name |
34 | | - - **default**: false |
35 | | - - `false`: keep message `Book` as it is |
36 | | - - `true`: turn message `Book` to `google.example.library.v1.Book`, it is useful when there are same named message in different package |
37 | | -6. `enum_type`: type for enum serialization. Use "string" for string-based serialization |
38 | | - - **default**: `integer` |
39 | | - - `integer`: setting type to `integer` |
40 | | - ```yaml |
41 | | - schema: |
42 | | - type: integer |
43 | | - format: enum |
44 | | - ``` |
45 | | - - `string`: setting type to `string`, and list available values in `enum` |
46 | | - ```yaml |
47 | | - schema: |
48 | | - enum: |
49 | | - - UNKNOWN_KIND |
50 | | - - KIND_1 |
51 | | - - KIND_2 |
52 | | - type: string |
53 | | - format: enum |
54 | | - ``` |
55 | | -7. `depth`: depth of recursion for circular messages |
56 | | - - **default**: 2, this depth only used in query parameters, usually 2 is enough |
57 | | -8. `default_response`: add default response. If "true", automatically adds a default response to operations which use the google.rpc.Status message. |
58 | | - Useful if you use envoy or grpc-gateway to transcode as they use this type for their default error responses. |
59 | | - - **default**: true, this option will add this default response for each method as following: |
60 | | - ```yaml |
61 | | - default: |
62 | | - description: Default error response |
63 | | - content: |
64 | | - application/json: |
65 | | - schema: |
66 | | - $ref: '#/components/schemas/google.rpc.Status' |
67 | | - ``` |
| 31 | +- 长期兼容 gnostic, 兼容 protoc-gen-connect-openapi, 后期会进行重构 |
0 commit comments