Skip to main content

validate_auto

Function validate_auto 

Source
pub fn validate_auto(content: &str) -> ValidationResult
Expand description

Auto-detect the YAML format and validate it.

This is the main entry point for one-call validation. It:

  1. Splits multi-document YAML files (separated by ---) and validates each document independently, merging the results.
  2. Calls detect_yaml_type on the parsed content.
  3. Dispatches to the appropriate per-format validator.

The returned ValidationResult is always populated — if parsing fails, valid is false and errors contains the parse error.

§Example

use devops_validate::validator::validate_auto;

// Valid multi-replica deployment — no errors, but possible warnings
let yaml = r#"
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app
spec:
  replicas: 3
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
    spec:
      containers:
        - name: app
          image: my-app:v1.0.0
"#;

let result = validate_auto(yaml);
assert!(result.valid);
assert_eq!(result.yaml_type.unwrap().to_string(), "K8s Deployment");