{"record":{"id":"8599f8e29b034b24","repo":"windmill-labs/windmill","slug":"could-not-generate-openapi-document-in-json-format","errorCode":null,"errorMessage":"Could not generate OpenAPI document in JSON format: {}","messagePattern":"Could not generate OpenAPI document in JSON format: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/windmill-api-openapi/src/lib.rs","lineNumber":644,"sourceCode":"    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 {\n    folder_regex: String,\n    path_regex: String,\n    route_path_regex: String,\n}\n\n#[derive(Debug, Deserialize)]","sourceCodeStart":626,"sourceCodeEnd":662,"githubUrl":"https://github.com/windmill-labs/windmill/blob/e474e8803ce2ff5c2df09a58dab51d45f5c922ca/backend/windmill-api-openapi/src/lib.rs#L626-L662","documentation":"Same as the YAML variant: generate_openapi_document serializes the OpenAPI document to pretty JSON via serde_json::to_string_pretty, wrapping failures as 'Could not generate OpenAPI document in JSON format: {}'. Thrown when the assembled document cannot be converted to a JSON string.","triggerScenarios":"Calling generate_openapi_document (via generate_openapi_spec or download_spec) with format=JSON when the document contains values serde_json cannot serialize (NaN floats, non-string map keys created via serde_json::Value maps, non-JSON types inserted by generators).","commonSituations":"A path/component generator inserts an invalid serde_json::Value (e.g. from to_value on a non-serializable struct); float NaN in schema defaults; a recent code change added a component with exotic types.","solutions":["Read the wrapped serde_json error to locate the offending value and fix the generator inserting it","Ensure numeric defaults/schemas never contain NaN or Infinity","Verify all inserted values are valid serde_json::Value instances (use to_value and handle errors)","Check serde_json version consistency in the workspace"],"exampleFix":"// before\nlet default = f64::NAN;\n\"default\": serde_json::json!(default) // not JSON-representable\n// after\n\"default\": serde_json::json!(0.0)","handlingStrategy":"try-catch","validationCode":"// ensure values are JSON-safe before insertion\nlet v = serde_json::to_value(&schema)?; // rejects NaN etc. via custom serializer\nassert!(v.as_f64().map(|f| f.is_finite()).unwrap_or(true));","typeGuard":null,"tryCatchPattern":"match generate_openapi_document(paths, url, Format::JSON) {\n    Ok(doc) => doc,\n    Err(e) if e.to_string().contains(\"JSON format\") => {\n        tracing::error!(\"json spec generation failed: {e:#}\");\n        return Err(e);\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Sanitize numeric defaults to finite values","Convert all inserted components through serde_json::to_value with error handling","Add a spec-generation test to CI catching serialization regressions"],"tags":["openapi","json","serialization"],"backgroundTag":"json-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"}