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

Debugging generated code

To see what the macro produces, set OPENAPI_TRAIT_DEBUG when you build. Each annotated module is written as a pretty-printed <module_name>.rs file:

OPENAPI_TRAIT_DEBUG=1 cargo build
OPENAPI_TRAIT_DEBUGBehaviour
unset, empty, 0, falsedisabled (default)
1, truewrite to $OUT_DIR/openapi-trait-debug, or to <temp dir>/openapi-trait-debug if the crate has no build script
any other valueused as the output directory, e.g. OPENAPI_TRAIT_DEBUG=./gen

The build prints the path of each file to stderr. Write failures are reported, but they never stop the build.

Things to know

  • Only this macro’s output is expanded. Unlike cargo expand, nested derives such as Serialize stay as #[derive(...)], so the output shows only what openapi-trait generated.
  • Dumps are written when the crate compiles. Run cargo clean -p <crate> or touch the spec to get a fresh dump.
  • Files are named after the module. Two mod petstore {} blocks writing to the same directory overwrite each other. Give each build its own directory to keep both.
  • To navigate the code in your IDE, use source_file instead. It writes the code that is actually compiled, so go-to-definition opens it.