Skip to main content

detect_yaml_type

Function detect_yaml_type 

Source
pub fn detect_yaml_type(data: &Value) -> YamlType
Expand description

Detect the format of a parsed YAML document.

Uses explicit markers first (apiVersion/kind for Kubernetes, $schema in the validator), then structural heuristics for Docker Compose, GitLab CI, GitHub Actions, Prometheus, Alertmanager, Helm, Ansible, and OpenAPI. Returns YamlType::Generic when no format is recognised.

ยงExample

use devops_validate::validator::{parse_yaml, detect_yaml_type};
use devops_models::models::validation::YamlType;

let data = parse_yaml("apiVersion: apps/v1\nkind: Deployment\nmetadata:\n  name: x\nspec:\n  selector:\n    matchLabels:\n      app: x\n  template:\n    metadata:\n      labels:\n        app: x\n    spec:\n      containers: []").unwrap();
assert_eq!(detect_yaml_type(&data), YamlType::K8sDeployment);