Skip to content

Rust Axum: allow building models-only (e.g. WASM) without server dependencies - #25196

Merged
wing328 merged 3 commits into
OpenAPITools:masterfrom
unrealhoang:rust-axum-non-server-feature
Oct 9, 2026
Merged

wing328 merged 3 commits into
OpenAPITools:masterfrom
unrealhoang:rust-axum-non-server-feature

Conversation

@unrealhoang

@unrealhoang unrealhoang commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Rust Axum: allow building models-only (e.g. WASM) without server dependencies

Generated rust-axum crates always pulled in axum, tokio, ammonia, etc., even when you only want the models. As a result, you couldn't share the models with a WASM frontend.

This change puts all server-only code and dependencies behind the existing server feature, which is still on by default. Nothing changes for current users.

my_api = { path = "...", default-features = false } # models + types only

Changes

  • Cargo.mustache: ammonia, async-trait, axum, axum-extra, futures-util, headers, http, serde_html_form, tokio and tracing are now optional and enabled by server.
  • lib.mustache: the apis module now requires the server feature, because its API traits and response types depend on axum.
  • models.mustache: the http::HeaderValue import and the axum-based SSE alias now require server. XSS detection goes through a small contains_html() helper. With server enabled it calls ammonia::is_html. Without it the check is a no-op, and all other validation (length, range, pattern, nested) still runs.
  • README.mustache: documents the models-only setup.

PR checklist

  • Read the contribution guidelines.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@linxGnu (rust-axum)


Summary by cubic

Allows building rust-axum generated crates in models-only mode (e.g. for WASM frontends) by moving all server dependencies behind the existing server feature.

Previously, generated crates always pulled in axum, tokio, ammonia, and other server stack even when only models and types were needed. Now default-features = false leaves only models and types; the apis module, SSE type, and header-related imports are gated on server, and XSS detection becomes a no-op when ammonia isn't compiled in. Existing users are unaffected because server remains the default feature.

Written for commit b619fe9. Summary will update on new commits.

View guided diff

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 68 files

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

Comment thread samples/server/petstore/rust-axum/output/apikey-auths/README.md
Comment thread samples/server/petstore/rust-axum/output/apikey-auths/Cargo.toml
Comment thread samples/server/petstore/rust-axum/output/petstore/Cargo.toml
Comment thread samples/server/petstore/rust-axum/output/openapi-v3/Cargo.toml

@linxGnu linxGnu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you.

@wing328 Please help to merge this PR. Thank you

@wing328
wing328 merged commit b84b005 into OpenAPITools:master Oct 9, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants