{"id":15091395,"url":"https://github.com/chenrui333/rules_openapi","last_synced_at":"2025-04-07T09:20:44.316Z","repository":{"id":40571806,"uuid":"91534512","full_name":"chenrui333/rules_openapi","owner":"chenrui333","description":"🍃 bazel rules for generating code from openapi specifications","archived":false,"fork":false,"pushed_at":"2025-03-24T19:00:37.000Z","size":92,"stargazers_count":53,"open_issues_count":10,"forks_count":25,"subscribers_count":75,"default_branch":"master","last_synced_at":"2025-03-31T07:09:25.362Z","etag":null,"topics":["bazel","bazel-rules","openapi","openapi-gen","openapi-specification","swagger-codegen"],"latest_commit_sha":null,"homepage":null,"language":"Starlark","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/chenrui333.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":"2017-05-17T04:47:26.000Z","updated_at":"2025-02-05T21:54:18.000Z","dependencies_parsed_at":"2025-02-27T22:18:19.678Z","dependency_job_id":"ddfabebf-8ad9-4b33-a2a4-34ca59707e64","html_url":"https://github.com/chenrui333/rules_openapi","commit_stats":{"total_commits":114,"total_committers":20,"mean_commits":5.7,"dds":0.7017543859649122,"last_synced_commit":"41df8d99b94fb75ac62c578aef0f7d5924fa7d2a"},"previous_names":["chenrui333/rules_openapi"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chenrui333%2Frules_openapi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chenrui333%2Frules_openapi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chenrui333%2Frules_openapi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chenrui333%2Frules_openapi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chenrui333","download_url":"https://codeload.github.com/chenrui333/rules_openapi/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247622983,"owners_count":20968575,"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":["bazel","bazel-rules","openapi","openapi-gen","openapi-specification","swagger-codegen"],"created_at":"2024-09-25T10:40:55.890Z","updated_at":"2025-04-07T09:20:44.294Z","avatar_url":"https://github.com/chenrui333.png","language":"Starlark","readme":"# OpenAPI rules for Bazel \u003c!-- omit in toc --\u003e\n\n[![Workflow Status](https://github.com/meetup/rules_openapi/workflows/Main/badge.svg)](https://github.com/meetup/rules_openapi/actions)\n\n\u003e [Bazel](https://bazel.build/) rules for generating sources and libraries from [openapi](https://www.openapis.org/) schemas.\n\n- [Rules](#rules)\n- [Getting started](#getting-started)\n- [OpenAPI generator](#openapi-generator)\n- [openapi_gen](#openapi_gen)\n\n## Rules\n\n* [openapi_gen](#openapi_gen)\n\n## Getting started\n\nTo use the OpenAPI rules, add the following to your projects `WORKSPACE` file\n\n```python\nload(\"@bazel_tools//tools/build_defs/repo:http.bzl\", \"http_archive\")\n\nRULES_OPEN_API_COMMIT = \"f0f42afb855139ad5346659d089c32fb756d068e\" # see compatibility matrix\nRULES_OPEN_API_SHA256 = \"9570186948f1f65c61d2c6c6006840ea70888b270f028bbd0eb736caae1cd9df\" # see compatibility matrix\n\nhttp_archive(\n    name = \"io_bazel_rules_openapi\",\n    strip_prefix = \"rules_openapi-%s\" % RULES_OPEN_API_COMMIT,\n    url = \"https://github.com/meetup/rules_openapi/archive/%s.tar.gz\" % RULES_OPEN_API_COMMIT,\n    sha256 = RULES_OPEN_API_SHA256\n)\n\nload(\"@io_bazel_rules_openapi//openapi:openapi.bzl\", \"openapi_repositories\")\nopenapi_repositories()\n```\n\nThen in your `BUILD` file, just add the following so the rules will be available:\n\n```python\nload(\"@io_bazel_rules_openapi//openapi:openapi.bzl\", \"openapi_gen\")\n```\n\n## OpenAPI generator\n\nBy default the code will be generated using [Swagger's codegen](https://github.com/swagger-api/swagger-codegen#swagger-code-generator) it is however possible to switch\nto [OpenAPI's generator](https://github.com/OpenAPITools/openapi-generator). This can be done by passing some parameters to the `openapi_repositories` function:\n\nWORKSPACE:\n```python\nload(\"@io_bazel_rules_openapi//openapi:openapi.bzl\", \"openapi_repositories\")\nopenapi_repositories(\n    codegen_cli_version = \"5.0.0\",\n    codegen_cli_sha256 = \"839fade01e54ce1eecf012b8c33adb1413cff0cf2e76e23bc8d7673f09626f8e\",\n    codegen_cli_provider = \"openapi\"\n)\n```\n\nFor most languages, changing the generator should be seamless. You might however need to change the `language` field in you rule to match one available on the selected generator.\n\n## openapi_gen\n\n```python\nopenapi_gen(name, spec, api_package, model_package, invoker_package)\n```\n\nThis generates a `.srcjar` archive containing generated source files from a given openapi specification.\n\nThese rules rely on [swagger-codegen](https://github.com/swagger-api/swagger-codegen#swagger-code-generator) which defines many [configuration options](https://github.com/swagger-api/swagger-codegen#to-generate-a-sample-client-library). Not all configuration options\nare implemented in these rules yet but contributions are welcome. You can also request features [here](https://github.com/meetup/rules_openapi/issues/new?title=I%20would%20like%20to%20see...)\n\n\u003ctable class=\"table table-condensed table-bordered table-params\"\u003e\n  \u003ccolgroup\u003e\n    \u003ccol class=\"col-param\" /\u003e\n    \u003ccol class=\"param-description\" /\u003e\n  \u003c/colgroup\u003e\n  \u003cthead\u003e\n    \u003ctr\u003e\n      \u003cth colspan=\"2\"\u003eAttributes\u003c/th\u003e\n    \u003c/tr\u003e\n  \u003c/thead\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e\u003ccode\u003ename\u003c/code\u003e\u003c/td\u003e\n      \u003ctd\u003e\n        \u003ccode\u003eName, required\u003c/code\u003e\n        \u003cp\u003eA unique name for this rule.\u003c/p\u003e\n      \u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e\u003ccode\u003espec\u003c/code\u003e\u003c/td\u003e\n      \u003ctd\u003e\n        \u003ccode\u003eString, required\u003c/code\u003e\n        \u003cp\u003e\n          Path to \u003ccode\u003e.yaml\u003c/code\u003e or \u003ccode\u003e.json\u003c/code\u003e file containing openapi specification\n        \u003c/p\u003e\n      \u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e\u003ccode\u003elanguage\u003c/code\u003e\u003c/td\u003e\n      \u003ctd\u003e\n        \u003ccode\u003eString, required\u003c/code\u003e\n        \u003cp\u003eName of language to generate.\u003c/p\u003e\n        \u003cp\u003eIf you wish to use a custom language, you'll need to create a jar containing your \u003ca href=\"https://github.com/swagger-api/swagger-codegen#making-your-own-codegen-modules\"\u003ecustom codegen module\u003c/a\u003e, then use \u003ccode\u003edeps\u003c/code\u003e to add the custom codegen module to the classpath.\u003c/p\u003e\n        \u003cp\u003e\n          Note, not all swagger codegen provided languages generate the exact same source given the exact same set of arguments.\n          Be aware of this in cases where you expect bazel not to perform a previous executed action for the same sources.\n        \u003c/p\u003e\n      \u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e\u003ccode\u003eapi_package\u003c/code\u003e\u003c/td\u003e\n      \u003ctd\u003e\n        \u003ccode\u003eString, optional\u003c/code\u003e\n        \u003cp\u003epackage for api.\u003c/p\u003e\n      \u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e\u003ccode\u003emodule_package\u003c/code\u003e\u003c/td\u003e\n      \u003ctd\u003e\n        \u003ccode\u003eString, optional\u003c/code\u003e\n        \u003cp\u003epackage for models.\u003c/p\u003e\n      \u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e\u003ccode\u003einvoker_package\u003c/code\u003e\u003c/td\u003e\n      \u003ctd\u003e\n        \u003ccode\u003eString, optional\u003c/code\u003e\n        \u003cp\u003epackage for invoker.\u003c/p\u003e\n      \u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e\u003ccode\u003eadditional_properties\u003c/code\u003e\u003c/td\u003e\n      \u003ctd\u003e\n        \u003ccode\u003eDict of strings, optional\u003c/code\u003e\n        \u003cp\u003eAdditional properties that can be referenced by the codegen\n        templates. This allows setting parameters that you'd normally put in\n        \u003ccode\u003econfig.json\u003c/code\u003e, for example the Java library template:\u003c/p\u003e\n        \u003cpre\u003e\n    language = \"java\",\n    additional_properties = {\n        \"library\": \"feign\",\n    },\u003c/pre\u003e\n      \u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e\u003ccode\u003esystem_properties\u003c/code\u003e\u003c/td\u003e\n      \u003ctd\u003e\n        \u003ccode\u003eDict of strings, optional\u003c/code\u003e\n        \u003cp\u003eSystem properties to pass to swagger-codegen.  This allows setting parameters that you'd normally\n        set with \u003ccode\u003e-D\u003c/code\u003e, for example to disable test generation:\u003c/p\u003e\n        \u003cpre\u003e\n    language = \"java\",\n    system_properties = {\n        \"apiTests\": \"false\",\n        \"modelTests\": \"false\",\n    },\u003c/pre\u003e\n      \u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e\u003ccode\u003etype_mappings\u003c/code\u003e\u003c/td\u003e\n      \u003ctd\u003e\n        \u003ccode\u003eDict of strings, optional\u003c/code\u003e\n        \u003cp\u003eAllows control of the types used in generated code with\n        swagger-codegen's \u003ccode\u003e--type-mappings\u003c/code\u003e parameter. For example to\n        use Java 8's LocalDateTime class:\u003c/p\u003e\n        \u003cpre\u003e\n    language = \"java\",\n    additional_properties = {\n        \"dateLibrary\": \"java8\",\n    },\n    type_mappings = {\n        \"OffsetDateTime\": \"java.time.LocalDateTime\",\n    },\u003c/pre\u003e\n      \u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\nAn example of what a custom language may look like\n\n```python\njava_import(\n  name = \"custom-scala-codegen\",\n  jars = [\"custom-scala-codegen.jar\"]\n)\n\nopenapi_gen(\n  name = \"petstore-client-src\",\n  language = \"custom-scala\",\n  spec = \"petstore-spec.json\",\n  api_package = \"com.example.api\",\n  model_package = \"com.example.model\",\n  invoker_package = \"com.example\",\n  deps = [\n    \":custom-scala-codegen\"\n  ]\n)\n\nscala_library(\n  name = \"petstore-client\",\n  srcs = [\":petstore-client-src\"]\n)\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchenrui333%2Frules_openapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchenrui333%2Frules_openapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchenrui333%2Frules_openapi/lists"}