[rust-axum] Honor additionalProperties: false on object models

Merged
LU
23d ago
+237-0

rust-axum currently accepts and silently discards unknown JSON fields even when an object schema explicitly sets additionalProperties: false. Generate #[serde(deny_unknown_fields)] on these object structs so deserialization rejects unknown fields. Recognize both Boolean false and false-valued Schema representations used by the parser, including OpenAPI 3.1.

Schemas with omitted, true, or schema-valued additionalProperties retain their existing behavior, and open objects inside declared properties remain accepted. The fix adds an internal model flag and three template lines, without a generator option or post-processing script.

Generator regressions cover OpenAPI 3.0 and 3.1, closed/nested/optional objects, and open models. Negative assertions first check that the model exists. Runtime regressions live in the existing oneOf sample and cover unknown-field rejection on object structs and tagged closed variants, plus acceptance of open nested objects and models without explicit false. The existing closed variants' generated models are updated.

Fixes https://github.com/OpenAPITools/openapi-generator/issues/25255.

Validation:

  • Confirmed the OpenAPI 3.0 regression fails on master before the fix and the new OpenAPI 3.1 regression fails on the initial PR commit; all seven RustAxumServerCodegenTest cases now pass.
  • Built the CLI and validated both regression specifications.
  • Full core/generator/CLI test suites: 5,473 passed, with 14 existing tests skipped.
  • Axum sample workspace: 362 tests passed with all features and with no default features; one existing test ignored in each run.
  • Strict Clippy (-D warnings) and formatting passed for the added Rust regression target.
  • Generator documentation export produced no changes.

PR checklist

  • Read the contribution guidelines.
  • Built the CLI, updated the relevant samples, and exported generator documentation.
  • Included regression coverage and searched for related issues/PRs.
  • Rust reviewers: @jacob-pro; rust-axum template author: @linxGnu.