Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

rules_openapi

API reference, generated from the module’s .bzl docstrings (stardoc).


OpenAPI plugin conformance test.

openapi_plugin_contract_test(name, plugin) runs the rules_openapi plugin contract scenarios against any plugin executable. Mirrors rules_jsonschema’s jsonschema_plugin_contract_test but with OpenAPI-flavored fixtures (a minimal OpenAPI 3.1 document instead of a JSON Schema).

openapi_plugin_contract_test

load("@rules_openapi//openapi:contract_test.bzl", "openapi_plugin_contract_test")

openapi_plugin_contract_test(name, plugin)

Run the rules_openapi plugin contract scenarios against a plugin binary.

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
pluginThe plugin binary to test.Labelrequired

Rust user-facing rules for rules_openapi.

openapi_rust_client is the Rust client codegen rule:

  1. Resolves the rust_client_codegen_toolchain_type toolchain.
  2. Runs the toolchain’s binary on the OpenAPI spec (stdin/argv/ stdout per //openapi/plugin_contract.md), producing a .rs.
  3. Wraps the .rs in a rust_library whose deps include progenitor-client, reqwest, serde, serde_json, and any additional crates the consumer threads through.

The default toolchain (registered by MODULE.bazel) points at the in-repo openapi_to_rust_client binary, which wraps progenitor under the hood. Swap by declaring your own openapi_codegen_toolchain and registering it ahead of the default.

openapi_rust_client

load("@rules_openapi//rust:defs.bzl", "openapi_rust_client")

openapi_rust_client(name, spec, extra_args, progenitor_client, reqwest, serde, serde_json, regress,
                    visibility, **rust_library_kwargs)

Generate a rust_library of a typed OpenAPI HTTP client.

The library exports a Client struct with one method per OpenAPI operation, plus a types module containing serde structs for components/schemas.

PARAMETERS

NameDescriptionDefault Value
namerust_library target name. Consumers add this to deps.none
speclabel of an OpenAPI .yaml / .yml / .json document.none
extra_argsextra --key=value flags passed to the plugin.None
progenitor_clientlabel of the progenitor_client runtime crate the generated code references. Defaults to @openapi_crates//:progenitor-client. Consumers using their own crates_universe must thread this through (and likewise the other runtime-dep attrs below) to avoid the same trait- identity mismatch rules_jsonschema documents.None
reqwestlabel of reqwest (HTTP client the generated code uses).None
serdelabel of serde.None
serde_jsonlabel of serde_json.None
regresslabel of regress (used by typify-generated types nested inside progenitor’s output).None
visibilityforwarded to rust_library.None
rust_library_kwargsforwarded to rust_library (e.g. extra deps).none

Providers exposed by rules_openapi.

Same shape as rules_jsonschema’s JsonschemaCodegenToolchainInfo — the plugin contract is identical (stdin/argv/stdout), the only difference is the schema content shipped on stdin (OpenAPI document rather than a JSON Schema).

OpenapiCodegenToolchainInfo

load("@rules_openapi//openapi:providers.bzl", "OpenapiCodegenToolchainInfo")

OpenapiCodegenToolchainInfo(binary)

An OpenAPI → code codegen tool.

FIELDS

NameDescription
binaryFile: the codegen executable. Invoked with --schema-name=NAME --rule-name=NAME plus per-plugin flags the calling rule passes through.

Toolchain rules for rules_openapi codegen.

openapi_codegen_toolchain wraps a single codegen executable as a Bazel toolchain. Toolchain types are split per (language, use_case) pair — Rust clients, Go clients, Rust servers, etc. — so a consumer can swap one plugin without affecting the rest.

Default toolchains are registered in the per-language directories (//rust:BUILD.bazel, …). To swap an implementation, declare your own openapi_codegen_toolchain and register_toolchains(...) it ahead of rules_openapi’s default in your MODULE.bazel.

openapi_codegen_toolchain

load("@rules_openapi//openapi:toolchains.bzl", "openapi_codegen_toolchain")

openapi_codegen_toolchain(name, binary)

Declare an OpenAPI → code codegen executable as a Bazel toolchain.

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
binaryThe codegen executable. Must accept --schema-name=NAME --rule-name=NAME plus any per-plugin flags the calling rule passes through.Labelrequired