Skip to content

[BUG][rust-server] serde_valid validation stops at generated model wrappers #25261

Open

Description

@EricLiu2000

Bug Report Checklist

  • Minimal spec provided and validated with the CLI.
  • Reproduced on latest master (1fdc3307942fcf853990cda8701d71c7e0753157).
  • Searched open and closed issues and PRs.
  • Actual and expected output provided below.
Description

With the Rust server generator's validate feature, a root model's serde_valid::Validate call can return success when a nested model is invalid. Generated array newtypes derive Validate, but their inner fields do not have #[validate]. Named oneOf/anyOf newtypes have the same missing recursion step. Object fields also omit nested validation when they have length or item bounds.

This makes a root validation call unreliable as a structural validation boundary. Applications must walk generated model graphs by hand to find invalid children.

OpenAPI Generator version

Latest master, built locally at 1fdc3307942fcf853990cda8701d71c7e0753157. The array-wrapper case also applies to 7.22.0 and 7.26.0.

Minimal OpenAPI definition
openapi: 3.0.3
info:
  title: Nested validation
  version: '1.0'
paths: {}
components:
  schemas:
    Positive:
      type: object
      required: [value]
      properties:
        value:
          type: integer
          minimum: 1
    Positives:
      type: array
      items:
        $ref: '#/components/schemas/Positive'
    Parent:
      type: object
      required: [children]
      properties:
        children:
          $ref: '#/components/schemas/Positives'
Generation and reproduction

Generate with:

java -jar openapi-generator-cli.jar generate \
  -g rust-server -i nested.yaml --generate-alias-as-model \
  --additional-properties packageName=recursive_validation -o generated

Add this integration test and run cargo test --no-default-features --features validate --test recursive_validation:

use recursive_validation::models::{Parent, Positive, Positives};
use serde_valid::Validate;

#[test]
fn root_validation_reaches_array_items() {
    let root = Parent {
        children: Positives::from(vec![Positive { value: 0 }]),
    };
    assert!(root.validate().is_err());
}

Actual: the assertion fails because validation returns Ok(()). Expected: the root reports the child's minimum violation.

Proposed fix

Generate recursion through model-valued wrapper fields and keep recursive validation when a field also has collection bounds. Primitive-valued wrappers and primitive union alternatives must still compile; Rust primitives such as String do not implement serde_valid::Validate.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions