{"record":{"id":"fd7afdf0ec40265d","repo":"windmill-labs/windmill","slug":"could-not-generate-openapi-document-in-yaml-format","errorCode":null,"errorMessage":"Could not generate OpenAPI document in YAML format: {}","messagePattern":"Could not generate OpenAPI document in YAML format: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/windmill-api-openapi/src/lib.rs","lineNumber":638,"sourceCode":"    url: Option<&Url>,\n    paths: Vec<FuturePath>,\n    format: Format,\n) -> Result<String> {\n    let mut openapi_doc: IndexMap<&'static str, Value> = IndexMap::new();\n\n    openapi_doc.insert(\"openapi\", to_value(&DEFAULT_OPENAPI_GENERATED_VERSION)?);\n    openapi_doc.insert(\n        \"info\",\n        to_value(info.unwrap_or(&DEFAULT_OPENAPI_INFO_OBJECT))?,\n    );\n\n    openapi_doc.insert(\"components\", Value::Object(generate_components(&paths)));\n\n    openapi_doc.insert(\"paths\", to_value(generate_paths(paths, url)?)?);\n\n    let openapi_document = match format {\n        Format::YAML => serde_yml::to_string(&openapi_doc).map_err(|err| {\n            anyhow!(\n                \"Could not generate OpenAPI document in YAML format: {}\",\n                err\n            )\n        })?,\n        Format::JSON => serde_json::to_string_pretty(&openapi_doc).map_err(|err| {\n            anyhow!(\n                \"Could not generate OpenAPI document in JSON format: {}\",\n                err\n            )\n        })?,\n    };\n\n    Ok(openapi_document)\n}\n\n#[allow(unused)]\n#[derive(Debug, Deserialize)]\nstruct HttpRouteFilter {","sourceCodeStart":620,"sourceCodeEnd":656,"githubUrl":"https://github.com/windmill-labs/windmill/blob/e474e8803ce2ff5c2df09a58dab51d45f5c922ca/backend/windmill-api-openapi/src/lib.rs#L620-L656","documentation":"generate_openapi_document serializes the assembled OpenAPI document; in YAML format it uses serde_yml::to_string and wraps any serialization failure as 'Could not generate OpenAPI document in YAML format: {}'. Thrown when the in-memory document Value cannot be converted to a YAML string.","triggerScenarios":"Calling generate_openapi_document (via generate_openapi_spec or download_spec endpoint) with format=YAML when the document contains values serde_yml cannot serialize (e.g. non-string map keys, invalid Value variants injected by generators).","commonSituations":"A newly added component or path generator inserts a JSON value that is not YAML-representable; serde_yml version incompatibility; corrupted extension fields (x-*) added to the document.","solutions":["Inspect the wrapped error message to find the non-serializable value and fix the generator that inserts it","Test with format=JSON (serde_json) to confirm the document itself is valid and the issue is YAML-specific","Check/align serde_yml crate versions in Cargo.lock","Validate any custom x- extension objects use string keys"],"exampleFix":"// before\nopenapi_doc.insert(\"x-custom\", serde_json::json!({123: \"key\"})); // non-string key\n// after\nopenapi_doc.insert(\"x-custom\", serde_json::json!({\"123\": \"key\"}));","handlingStrategy":"try-catch","validationCode":"// ensure values are serializable before insertion\nlet v = serde_yml::to_value(&component)?; // fails early, clear error","typeGuard":null,"tryCatchPattern":"match generate_openapi_document(paths, url, Format::YAML) {\n    Ok(doc) => doc,\n    Err(e) if e.to_string().contains(\"YAML format\") => {\n        tracing::error!(\"yaml spec generation failed: {e:#}\");\n        generate_openapi_document(paths, url, Format::JSON)? // fallback\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Only insert valid serde_json::Value/serde_yml::Value nodes into openapi_doc","Use string keys for all extension objects","Pin and regularly update serde_yml in the workspace"],"tags":["openapi","yaml","serialization"],"backgroundTag":"yaml-serialization-failed","analyzedSha":"e474e8803ce2ff5c2df09a58dab51d45f5c922ca","analyzedAt":"2026-09-03T12:38:19.024Z","contentChangedAt":"2026-09-03T12:38:19.024Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}