{"id":13765905,"url":"https://github.com/swaggest/go-asyncapi","last_synced_at":"2025-04-07T05:15:46.764Z","repository":{"id":40589393,"uuid":"156310150","full_name":"swaggest/go-asyncapi","owner":"swaggest","description":"AsyncAPI spec from Go code","archived":false,"fork":false,"pushed_at":"2024-09-12T15:14:26.000Z","size":304,"stargazers_count":78,"open_issues_count":2,"forks_count":11,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-30T21:14:39.811Z","etag":null,"topics":["asyncapi"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/swaggest.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-11-06T01:51:37.000Z","updated_at":"2025-01-30T20:53:15.000Z","dependencies_parsed_at":"2024-06-18T18:28:51.108Z","dependency_job_id":"51d1ecc5-06e4-4588-8bff-56f5f3d4faa7","html_url":"https://github.com/swaggest/go-asyncapi","commit_stats":null,"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swaggest%2Fgo-asyncapi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swaggest%2Fgo-asyncapi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swaggest%2Fgo-asyncapi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swaggest%2Fgo-asyncapi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/swaggest","download_url":"https://codeload.github.com/swaggest/go-asyncapi/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247595335,"owners_count":20963943,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["asyncapi"],"created_at":"2024-08-03T16:00:48.496Z","updated_at":"2025-04-07T05:15:46.665Z","avatar_url":"https://github.com/swaggest.png","language":"Go","funding_links":[],"categories":["Tools"],"sub_categories":[],"readme":"# AsyncAPI Generator for Go\n\n[![Build Status](https://github.com/swaggest/go-asyncapi/workflows/test-unit/badge.svg)](https://github.com/swaggest/go-asyncapi/actions?query=branch%3Amaster+workflow%3Atest-unit)\n[![Coverage Status](https://codecov.io/gh/swaggest/go-asyncapi/branch/master/graph/badge.svg)](https://codecov.io/gh/swaggest/go-asyncapi)\n[![GoDoc](https://godoc.org/github.com/swaggest/go-asyncapi?status.svg)](https://godoc.org/github.com/swaggest/go-asyncapi)\n![Code lines](https://sloc.xyz/github/swaggest/go-asyncapi/?category=code)\n![Comments](https://sloc.xyz/github/swaggest/go-asyncapi/?category=comments)\n\nThis library helps to create [AsyncAPI](https://www.asyncapi.com/) spec from your Go message structures.\n\nSupported AsyncAPI versions:\n* `v2.4.0` \n* `v2.1.0` \n* `v2.0.0`\n* `v1.2.0`\n\n## Example\n\n```go\npackage asyncapi_test\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"time\"\n\n\t\"github.com/swaggest/go-asyncapi/reflector/asyncapi-2.4.0\"\n\t\"github.com/swaggest/go-asyncapi/spec-2.4.0\"\n)\n\nfunc main() {\n\ttype SubItem struct {\n\t\tKey    string  `json:\"key\" description:\"Item key\"`\n\t\tValues []int64 `json:\"values\" uniqueItems:\"true\" description:\"List of item values\"`\n\t}\n\n\ttype MyMessage struct {\n\t\tName      string    `path:\"name\" description:\"Name\"`\n\t\tCreatedAt time.Time `json:\"createdAt\" description:\"Creation time\"`\n\t\tItems     []SubItem `json:\"items\" description:\"List of items\"`\n\t}\n\n\ttype MyAnotherMessage struct {\n\t\tTraceID string  `header:\"X-Trace-ID\" description:\"Tracing header\" required:\"true\"`\n\t\tItem    SubItem `json:\"item\" description:\"Some item\"`\n\t}\n\n\tasyncAPI := spec.AsyncAPI{}\n\tasyncAPI.Info.Version = \"1.2.3\"\n\tasyncAPI.Info.Title = \"My Lovely Messaging API\"\n\n\tasyncAPI.AddServer(\"live\", spec.Server{\n\t\tURL:             \"api.{country}.lovely.com:5672\",\n\t\tDescription:     \"Production instance.\",\n\t\tProtocolVersion: \"0.9.1\",\n\t\tProtocol:        \"amqp\",\n\t\tVariables: map[string]spec.ServerVariable{\n\t\t\t\"country\": {\n\t\t\t\tEnum:        []string{\"RU\", \"US\", \"DE\", \"FR\"},\n\t\t\t\tDefault:     \"US\",\n\t\t\t\tDescription: \"Country code.\",\n\t\t\t},\n\t\t},\n\t})\n\n\treflector := asyncapi.Reflector{}\n\treflector.Schema = \u0026asyncAPI\n\n\tmustNotFail := func(err error) {\n\t\tif err != nil {\n\t\t\tpanic(err.Error())\n\t\t}\n\t}\n\n\tmustNotFail(reflector.AddChannel(asyncapi.ChannelInfo{\n\t\tName: \"one.{name}.two\",\n\t\tBaseChannelItem: \u0026spec.ChannelItem{\n\t\t\tBindings: \u0026spec.ChannelBindingsObject{\n\t\t\t\tAmqp: \u0026spec.AmqpChannel{\n\t\t\t\t\tIs: spec.AmqpChannelIsRoutingKey,\n\t\t\t\t\tExchange: \u0026spec.AmqpChannelExchange{\n\t\t\t\t\t\tName: \"some-exchange\",\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\tPublish: \u0026asyncapi.MessageSample{\n\t\t\tMessageEntity: spec.MessageEntity{\n\t\t\t\tDescription: \"This is a sample schema.\",\n\t\t\t\tSummary:     \"Sample publisher\",\n\t\t\t},\n\t\t\tMessageSample: new(MyMessage),\n\t\t},\n\t}))\n\n\tmustNotFail(reflector.AddChannel(asyncapi.ChannelInfo{\n\t\tName: \"another.one\",\n\t\tSubscribe: \u0026asyncapi.MessageSample{\n\t\t\tMessageEntity: spec.MessageEntity{\n\t\t\t\tDescription: \"This is another sample schema.\",\n\t\t\t\tSummary:     \"Sample consumer\",\n\t\t\t},\n\t\t\tMessageSample: new(MyAnotherMessage),\n\t\t},\n\t}))\n\n\tyaml, err := reflector.Schema.MarshalYAML()\n\tmustNotFail(err)\n\n\tfmt.Println(string(yaml))\n\tmustNotFail(os.WriteFile(\"sample.yaml\", yaml, 0o600))\n\t// output:\n\t// asyncapi: 2.4.0\n\t// info:\n\t//   title: My Lovely Messaging API\n\t//   version: 1.2.3\n\t// servers:\n\t//   live:\n\t//     url: api.{country}.lovely.com:5672\n\t//     description: Production instance.\n\t//     protocol: amqp\n\t//     protocolVersion: 0.9.1\n\t//     variables:\n\t//       country:\n\t//         enum:\n\t//         - RU\n\t//         - US\n\t//         - DE\n\t//         - FR\n\t//         default: US\n\t//         description: Country code.\n\t// channels:\n\t//   another.one:\n\t//     subscribe:\n\t//       message:\n\t//         $ref: '#/components/messages/Asyncapi240TestMyAnotherMessage'\n\t//   one.{name}.two:\n\t//     parameters:\n\t//       name:\n\t//         schema:\n\t//           description: Name\n\t//           type: string\n\t//     publish:\n\t//       message:\n\t//         $ref: '#/components/messages/Asyncapi240TestMyMessage'\n\t//     bindings:\n\t//       amqp:\n\t//         bindingVersion: 0.2.0\n\t//         is: routingKey\n\t//         exchange:\n\t//           name: some-exchange\n\t// components:\n\t//   schemas:\n\t//     Asyncapi240TestMyAnotherMessage:\n\t//       properties:\n\t//         item:\n\t//           $ref: '#/components/schemas/Asyncapi240TestSubItem'\n\t//           description: Some item\n\t//       type: object\n\t//     Asyncapi240TestMyMessage:\n\t//       properties:\n\t//         createdAt:\n\t//           description: Creation time\n\t//           format: date-time\n\t//           type: string\n\t//         items:\n\t//           description: List of items\n\t//           items:\n\t//             $ref: '#/components/schemas/Asyncapi240TestSubItem'\n\t//           type:\n\t//           - array\n\t//           - \"null\"\n\t//       type: object\n\t//     Asyncapi240TestSubItem:\n\t//       properties:\n\t//         key:\n\t//           description: Item key\n\t//           type: string\n\t//         values:\n\t//           description: List of item values\n\t//           items:\n\t//             type: integer\n\t//           type:\n\t//           - array\n\t//           - \"null\"\n\t//           uniqueItems: true\n\t//       type: object\n\t//   messages:\n\t//     Asyncapi240TestMyAnotherMessage:\n\t//       headers:\n\t//         properties:\n\t//           X-Trace-ID:\n\t//             description: Tracing header\n\t//             type: string\n\t//         required:\n\t//         - X-Trace-ID\n\t//         type: object\n\t//       payload:\n\t//         $ref: '#/components/schemas/Asyncapi240TestMyAnotherMessage'\n\t//       summary: Sample consumer\n\t//       description: This is another sample schema.\n\t//     Asyncapi240TestMyMessage:\n\t//       payload:\n\t//         $ref: '#/components/schemas/Asyncapi240TestMyMessage'\n\t//       summary: Sample publisher\n\t//       description: This is a sample schema.\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswaggest%2Fgo-asyncapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fswaggest%2Fgo-asyncapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswaggest%2Fgo-asyncapi/lists"}