From 987932fb30c5ca9117fc60e8011dd3326f93756e Mon Sep 17 00:00:00 2001 From: Zheming Bao <56347255+EZ4Jam1n@users.noreply.github.com> Date: Sun, 22 Sep 2024 00:10:05 +0800 Subject: [PATCH] chore: add readme en/cn doc (#7) --- CODE_OF_CONDUCT.md | 128 ------------------------------------------- CONTRIBUTING.md | 55 ------------------- README.md | 108 +++++++++++++++++++++++++++++++++++- README_CN.md | 106 +++++++++++++++++++++++++++++++++++ check_branch_name.sh | 10 ---- profile/README.md | 13 ----- 6 files changed, 213 insertions(+), 207 deletions(-) delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md create mode 100644 README_CN.md delete mode 100755 check_branch_name.sh delete mode 100644 profile/README.md diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md deleted file mode 100644 index 25ceb89..0000000 --- a/CODE_OF_CONDUCT.md +++ /dev/null @@ -1,128 +0,0 @@ -# Contributor Covenant Code of Conduct - -## Our Pledge - -We as members, contributors, and leaders pledge to make participation in our -community a harassment-free experience for everyone, regardless of age, body -size, visible or invisible disability, ethnicity, sex characteristics, gender -identity and expression, level of experience, education, socio-economic status, -nationality, personal appearance, race, religion, or sexual identity -and orientation. - -We pledge to act and interact in ways that contribute to an open, welcoming, -diverse, inclusive, and healthy community. - -## Our Standards - -Examples of behavior that contributes to a positive environment for our -community include: - -* Demonstrating empathy and kindness toward other people -* Being respectful of differing opinions, viewpoints, and experiences -* Giving and gracefully accepting constructive feedback -* Accepting responsibility and apologizing to those affected by our mistakes, - and learning from the experience -* Focusing on what is best not just for us as individuals, but for the - overall community - -Examples of unacceptable behavior include: - -* The use of sexualized language or imagery, and sexual attention or - advances of any kind -* Trolling, insulting or derogatory comments, and personal or political attacks -* Public or private harassment -* Publishing others' private information, such as a physical or email - address, without their explicit permission -* Other conduct which could reasonably be considered inappropriate in a - professional setting - -## Enforcement Responsibilities - -Community leaders are responsible for clarifying and enforcing our standards of -acceptable behavior and will take appropriate and fair corrective action in -response to any behavior that they deem inappropriate, threatening, offensive, -or harmful. - -Community leaders have the right and responsibility to remove, edit, or reject -comments, commits, code, wiki edits, issues, and other contributions that are -not aligned to this Code of Conduct, and will communicate reasons for moderation -decisions when appropriate. - -## Scope - -This Code of Conduct applies within all community spaces, and also applies when -an individual is officially representing the community in public spaces. -Examples of representing our community include using an official e-mail address, -posting via an official social media account, or acting as an appointed -representative at an online or offline event. - -## Enforcement - -Instances of abusive, harassing, or otherwise unacceptable behavior may be -reported to the community leaders responsible for enforcement at -conduct@cloudwego.io. -All complaints will be reviewed and investigated promptly and fairly. - -All community leaders are obligated to respect the privacy and security of the -reporter of any incident. - -## Enforcement Guidelines - -Community leaders will follow these Community Impact Guidelines in determining -the consequences for any action they deem in violation of this Code of Conduct: - -### 1. Correction - -**Community Impact**: Use of inappropriate language or other behavior deemed -unprofessional or unwelcome in the community. - -**Consequence**: A private, written warning from community leaders, providing -clarity around the nature of the violation and an explanation of why the -behavior was inappropriate. A public apology may be requested. - -### 2. Warning - -**Community Impact**: A violation through a single incident or series -of actions. - -**Consequence**: A warning with consequences for continued behavior. No -interaction with the people involved, including unsolicited interaction with -those enforcing the Code of Conduct, for a specified period of time. This -includes avoiding interactions in community spaces as well as external channels -like social media. Violating these terms may lead to a temporary or -permanent ban. - -### 3. Temporary Ban - -**Community Impact**: A serious violation of community standards, including -sustained inappropriate behavior. - -**Consequence**: A temporary ban from any sort of interaction or public -communication with the community for a specified period of time. No public or -private interaction with the people involved, including unsolicited interaction -with those enforcing the Code of Conduct, is allowed during this period. -Violating these terms may lead to a permanent ban. - -### 4. Permanent Ban - -**Community Impact**: Demonstrating a pattern of violation of community -standards, including sustained inappropriate behavior, harassment of an -individual, or aggression toward or disparagement of classes of individuals. - -**Consequence**: A permanent ban from any sort of public interaction within -the community. - -## Attribution - -This Code of Conduct is adapted from the [Contributor Covenant][homepage], -version 2.0, available at -https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. - -Community Impact Guidelines were inspired by [Mozilla's code of conduct -enforcement ladder](https://github.com/mozilla/diversity). - -[homepage]: https://www.contributor-covenant.org - -For answers to common questions about this code of conduct, see the FAQ at -https://www.contributor-covenant.org/faq. Translations are available at -https://www.contributor-covenant.org/translations. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md deleted file mode 100644 index e60a59e..0000000 --- a/CONTRIBUTING.md +++ /dev/null @@ -1,55 +0,0 @@ -# How to Contribute - -## Your First Pull Request -We use github for our codebase. You can start by reading [How To Pull Request](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-requests). - -## Branch Organization -We use [git-flow](https://nvie.com/posts/a-successful-git-branching-model/) as our branch organization, as known as [FDD](https://en.wikipedia.org/wiki/Feature-driven_development) - -## Bugs -### 1. How to Find Known Issues -We are using [Github Issues](https://github.com/cloudwego/kitex/issues) for our public bugs. We keep a close eye on this and try to make it clear when we have an internal fix in progress. Before filing a new task, try to make sure your problem doesn’t already exist. - -### 2. Reporting New Issues -Providing a reduced test code is a recommended way for reporting issues. Then can placed in: -- Just in issues -- [Golang Playground](https://play.golang.org/) - -### 3. Security Bugs -Please do not report the safe disclosure of bugs to public issues. Contact us by [Support Email](mailto:conduct@cloudwego.io) - -## How to Get in Touch -- [Email](mailto:conduct@cloudwego.io) - -## Submit a Pull Request -Before you submit your Pull Request (PR) consider the following guidelines: -1. Search [GitHub](https://github.com/cloudwego/kitex/pulls) for an open or closed PR that relates to your submission. You don't want to duplicate existing efforts. -2. Be sure that an issue describes the problem you're fixing, or documents the design for the feature you'd like to add. Discussing the design upfront helps to ensure that we're ready to accept your work. -3. [Fork](https://docs.github.com/en/github/getting-started-with-github/fork-a-repo) the cloudwego/kitex repo. -4. In your forked repository, make your changes in a new git branch: - ``` - git checkout -b my-fix-branch develop - ``` -5. Create your patch, including appropriate test cases. -6. Follow our [Style Guides](#code-style-guides). -7. Commit your changes using a descriptive commit message that follows [AngularJS Git Commit Message Conventions](https://docs.google.com/document/d/1QrDFcIiPjSLDn3EL15IJygNPiHORgU1_OOAqWjiDU5Y/edit). - Adherence to these conventions is necessary because release notes are automatically generated from these messages. -8. Push your branch to GitHub: - ``` - git push origin my-fix-branch - ``` -9. In GitHub, send a pull request to `kitex:develop` - -## Contribution Prerequisites -- Our development environment keeps up with [Go Official](https://golang.org/project/). -- You need fully checking with lint tools before submit your pull request. [gofmt](https://golang.org/pkg/cmd/gofmt/) and [golangci-lint](https://github.com/golangci/golangci-lint) -- You are familiar with [Github](https://github.com) -- Maybe you need familiar with [Actions](https://github.com/features/actions)(our default workflow tool). - -## Code Style Guides -Also see [Pingcap General advice](https://pingcap.github.io/style-guide/general.html). - -Good resources: -- [Effective Go](https://golang.org/doc/effective_go) -- [Go Code Review Comments](https://github.com/golang/go/wiki/CodeReviewComments) -- [Uber Go Style Guide](https://github.com/uber-go/guide/blob/master/style.md) diff --git a/README.md b/README.md index a46ae92..a9d5768 100644 --- a/README.md +++ b/README.md @@ -1 +1,107 @@ -# .github \ No newline at end of file +# Swagger Generate + +English | [中文](README_CN.md) + +**Swagger Generate** is a collection of plugins that generate Swagger documentation and provide Swagger-UI access for debugging HTTP and RPC services. This project is compatible with the [CloudWeGo](https://www.cloudwego.io) ecosystem frameworks such as [Cwgo](https://github.com/cloudwego/cwgo), [Hertz](https://github.com/cloudwego/hertz), and [Kitex](https://github.com/cloudwego/kitex). It offers a convenient toolset for developers to automatically generate Swagger documentation, simplifying the API documentation and debugging process. + +## Included Plugins + +- **protoc-gen-http-swagger**: Generates Swagger documentation and provides Swagger UI debugging for HTTP services based on Protobuf. +- **thrift-gen-http-swagger**: Generates Swagger documentation and provides Swagger UI debugging for HTTP services based on Thrift. +- **protoc-gen-rpc-swagger**: Generates Swagger documentation and provides Swagger UI debugging for RPC services based on Protobuf. +- **thrift-gen-rpc-swagger**: Generates Swagger documentation and provides Swagger UI debugging for RPC services based on Thrift. + +## Key Advantages + +- **Automated Generation**: Supports generating complete Swagger documentation from Protobuf and Thrift files, simplifying API documentation maintenance. +- **Integrated Debugging**: The generated Swagger UI can be used directly for service debugging, supporting both HTTP and RPC modes. +- **Hertz and Kitex Integration**: Provides seamless documentation generation and debugging support for [Hertz](https://github.com/cloudwego/hertz) and [Kitex](https://github.com/cloudwego/kitex). +- **Flexible Annotation Support**: Allows extending the generated Swagger documentation through annotations, supporting OpenAPI annotations such as `openapi.operation`, `openapi.schema`, etc. + +## Installation + +You can install the plugins using the following methods: + +```sh +# Install from the official repository +git clone https://github.com/hertz-contrib/swagger-generate +cd +go install + +# Direct installation +go install github.com/hertz-contrib/swagger-generate/@latest +``` + +## Usage Examples + +### Generating HTTP Swagger Documentation + +For HTTP services based on Protobuf: + +```sh +protoc --http-swagger_out=swagger -I idl hello.proto +``` + +For HTTP services based on Thrift: + +```sh +thriftgo -g go -p http-swagger hello.thrift +``` + +### Generating RPC Swagger Documentation + +For RPC services based on Protobuf: + +```sh +protoc --rpc-swagger_out=swagger -I idl idl/hello.proto +``` + +For RPC services based on Thrift: + +```sh +thriftgo -g go -p rpc-swagger hello.thrift +``` + +### Integrating Swagger-UI in Hertz or Kitex Services + +In a Hertz service: + +```go +func main() { + h := server.Default() + swagger.BindSwagger(h) // Add this line + register(h) + h.Spin() +} +``` +Or: + +```go +func register(r *server.Hertz) { + swagger.BindSwagger(r) // Add this line + + router.GeneratedRegister(r) + + customizedRegister(r) +} +``` + +In a Kitex service: + +```go +func main() { + svr := example.NewServer(new(HelloService1Impl), server.WithTransHandlerFactory(&swagger.MixTransHandlerFactory{})) // Modify this line + + err := svr.Run() + + if err != nil { + log.Println(err.Error()) + } +} +``` + +For more examples, please refer to [kitex_swagger_gen](https://github.com/cloudwego/kitex-examples/tree/main/bizdemo/kitex_swagger_gen) and [hertz_swagger_gen](https://github.com/cloudwego/hertz-examples/tree/main/bizdemo/hertz_swagger_gen). + +## More Information + +Refer to the README of each plugin for more detailed usage information. \ No newline at end of file diff --git a/README_CN.md b/README_CN.md new file mode 100644 index 0000000..00b1fb5 --- /dev/null +++ b/README_CN.md @@ -0,0 +1,106 @@ +# Swagger Generate + +[English](README.md) | 中文 + +**Swagger Generate** 是一个为 HTTP 和 RPC 服务生成 Swagger 文档及 Swagger-UI 访问调试的插件集合。该项目适用于 [CloudWeGo](https://www.cloudwego.io) 生态下的 [Cwgo](https://github.com/cloudwego/cwgo)、 [Hertz](https://github.com/cloudwego/hertz) 和 [Kitex](https://github.com/cloudwego/kitex) 框架。它提供了一套便捷的工具来帮助开发者自动生成 Swagger 文档,从而简化 API 文档编写及调试过程。 + +## 包含的插件 + +- **protoc-gen-http-swagger**:为基于 Protobuf 的 HTTP 服务生成 Swagger 文档和 Swagger UI 进行调试。 +- **thrift-gen-http-swagger**:为基于 Thrift 的 HTTP 服务生成 Swagger 文档和 Swagger UI 进行调试。 +- **protoc-gen-rpc-swagger**:为基于 Protobuf 的 RPC 服务生成 Swagger 文档和 Swagger UI 进行调试。 +- **thrift-gen-rpc-swagger**:为基于 Thrift 的 RPC 服务生成 Swagger 文档和 Swagger UI 进行调试。 + +## 项目优势 + +- **自动化生成**:支持通过 Protobuf 和 Thrift 文件生成完整的 Swagger 文档,简化了 API 文档的维护。 +- **集成调试**:生成的 Swagger UI 能直接用于调试服务,支持 HTTP 和 RPC 两种模式。 +- **Hertz 和 Kitex 集成**:为 [Hertz](https://github.com/cloudwego/hertz) 和 [Kitex](https://github.com/cloudwego/kitex) 提供了无缝的文档生成和调试支持。 +- **灵活的注解支持**:允许通过注解扩展生成的 Swagger 文档内容,支持 `openapi.operation`、`openapi.schema` 等 OpenAPI 注解。 + +## 安装 + +可以通过以下方式安装各个插件: + +```sh +# 官方仓库安装 +git clone https://github.com/hertz-contrib/swagger-generate +cd +go install + +# 直接安装 +go install github.com/hertz-contrib/swagger-generate/@latest +``` + +## 使用示例 + +### 生成 HTTP Swagger 文档 + +对于基于 Protobuf 的 HTTP 服务: + +```sh +protoc --http-swagger_out=swagger -I idl hello.proto +``` + +对于基于 Thrift 的 HTTP 服务: + +```sh +thriftgo -g go -p http-swagger hello.thrift +``` + +### 生成 RPC Swagger 文档 + +对于基于 Protobuf 的 RPC 服务: + +```sh +protoc --rpc-swagger_out=swagger -I idl idl/hello.proto +``` + +对于基于 Thrift 的 RPC 服务: + +```sh +thriftgo -g go -p rpc-swagger hello.thrift +``` + +### 在 Hertz 或 Kitex 服务中集成 Swagger-UI + +在 Hertz 服务中: + +```go +func main() { + h := server.Default() + swagger.BindSwagger(h) //增加改行 + register(h) + h.Spin() +} +``` +或者 + +```go +func register(r *server.Hertz) { + swagger.BindSwagger(r) //增加改行 + + router.GeneratedRegister(r) + + customizedRegister(r) +} +``` +在 Kitex 服务中: + +```go +func main() { + svr := example.NewServer(new(HelloService1Impl), server.WithTransHandlerFactory(&swagger.MixTransHandlerFactory{})) //改动改行 + + err := svr.Run() + + if err != nil { + log.Println(err.Error()) + } +} +``` + +请参考 [kitex_swagger_gen](https://github.com/cloudwego/kitex-examples/tree/main/bizdemo/kitex_swagger_gen) 和 [hertz_swagger_gen](https://github.com/cloudwego/hertz-examples/tree/main/bizdemo/hertz_swagger_gen) 获取更多使用场景示例。 + +## 更多信息 + +请参考各个插件的 readme 文档获取更多使用细节。 \ No newline at end of file diff --git a/check_branch_name.sh b/check_branch_name.sh deleted file mode 100755 index 1876fc0..0000000 --- a/check_branch_name.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash - -current=$(git status | head -n1 | sed 's/On branch //') -name=${1:-$current} -if [[ ! $name =~ ^(((opt(imize)?|feat(ure)?|(bug|hot)?fix|test|refact(or)?|ci)/.+)|(main|develop)|(release-v[0-9]+\.[0-9]+)|(release/v[0-9]+\.[0-9]+\.[0-9]+(-[a-z0-9.]+(\+[a-z0-9.]+)?)?)|revert-[a-z0-9]+)$ ]]; then - echo "branch name '$name' is invalid" - exit 1 -else - echo "branch name '$name' is valid" -fi diff --git a/profile/README.md b/profile/README.md deleted file mode 100644 index 2127160..0000000 --- a/profile/README.md +++ /dev/null @@ -1,13 +0,0 @@ -## Hi there 👋 - -🙋‍♀️ A short introduction - CloudWeGo is an open-source middleware set launched by ByteDance that can be used to quickly build enterprise-class cloud native architectures. The common characteristics of CloudWeGo projects are high performance, high scalability, high reliability and focusing on microservices communication and governance. - -🌈 Community Membership - the [Responsibilities and Requirements](https://github.com/cloudwego/community/blob/main/COMMUNITY_MEMBERSHIP.md) of contributor roles in CloudWeGo. - -👩‍💻 Useful resources - [Portal](https://www.cloudwego.io/), [Community](https://www.cloudwego.io/zh/community/), [Blogs](https://www.cloudwego.io/zh/blog/), [Use Cases](https://www.cloudwego.io/zh/cooperation/) - -🍿 Security - [Vulnerability Reporting](https://www.cloudwego.io/zh/security/vulnerability-reporting/), [Safety Bulletin](https://www.cloudwego.io/zh/security/safety-bulletin/) - -🌲 Ecosystem - [Kitex-contrib](https://github.com/kitex-contrib), [Hertz-contrib](https://github.com/hertz-contrib), [Volo-rs](https://github.com/volo-rs) - -🎊 Example - [kitex-example](https://github.com/cloudwego/kitex-examples), [hertz-example](https://github.com/cloudwego/hertz-examples), [biz-demo](https://github.com/cloudwego/biz-demo), [netpoll-example](https://github.com/cloudwego/netpoll-examples)