{"record":{"id":"1926bab1c07c59d4","repo":"OpenAPITools/openapi-generator","slug":"error-failed-to-process-getpydantictype-when-gett","errorCode":null,"errorMessage":"Error! Failed to process getPydanticType when getting the content: %s","messagePattern":"Error! Failed to process getPydanticType when getting the content: (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java","lineNumber":2362,"sourceCode":"            PythonType result = fromCommon(cp);\n\n            if (result == null) {\n                if (!cp.isPrimitiveType) {\n                    // add model prefix\n                    hasModelsToImport = true;\n                    modelImports.add(cp.getDataType());\n                    exampleImports.add(cp.getDataType());\n                    result = new PythonType(cp.getDataType());\n                } else if (cp.getContent() != null) {\n                    LinkedHashMap<String, CodegenMediaType> contents = cp.getContent();\n                    for (String key : contents.keySet()) {\n                        CodegenMediaType cmt = contents.get(key);\n                        // TODO process the first one only at the moment\n                        if (cmt != null)\n                            // TODO: don't loop back to the deprecated getPydanticType method\n                            return getPydanticType(cmt.getSchema(), modelImports, exampleImports, postponedModelImports, postponedExampleImports, moduleImports, classname);\n                    }\n                    throw new RuntimeException(\"Error! Failed to process getPydanticType when getting the content: \" + cp);\n                } else {\n                    throw new RuntimeException(\"Error! Codegen Parameter not yet supported in getPydanticType: \" + cp);\n                }\n            }\n\n            return result;\n        }\n\n        private String finalizeType(CodegenParameter cp, PythonType pt) {\n            if (!cp.required || cp.isNullable) {\n                moduleImports.add(TYPING, \"Optional\");\n                PythonType opt = new PythonType(\"Optional\");\n                opt.addTypeParam(pt);\n                pt = opt;\n            }\n\n            if (!StringUtils.isEmpty(cp.description)) { // has description\n                pt.annotate(\"description\", cp.description);","sourceCodeStart":2344,"sourceCodeEnd":2380,"githubUrl":"https://github.com/OpenAPITools/openapi-generator/blob/fcec517be3cf5b7964296bcba25fbc97541484e7/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java#L2344-L2380","documentation":"In AbstractPythonCodegen's getPydanticType(CodegenParameter, ...), a parameter that carries request-body style content is handled by looping over the content media-type map and returning on the first non-null CodegenMediaType schema. If the content map is non-null but yields no usable entry (empty map or all-null values), the loop finishes without returning and this RuntimeException fires — a degenerate content definition the type mapper cannot process.","triggerScenarios":"A request-body-bearing parameter whose content map is empty or whose CodegenMediaType entries are all null, e.g. content: {} with no media-type keys, or content stripped by a preprocessing/vendor-extension hook. Note the loop only processes the first entry even when valid (source TODO).","commonSituations":"Hand-edited specs with content: {} placeholders; specs run through middleware or converters that drop schemas while copying; rare parser edge cases on malformed media-type keys.","solutions":["Fix the spec so every requestBody content has at least one media type with a schema: content: { application/json: { schema: { type: object } } }","Remove empty content blocks entirely so the parameter takes the normal typed path","If the spec looks correct, upgrade openapi-generator and then report the issue with the operation snippet — an all-null content map indicates a generator gap"],"exampleFix":"# before\nrequestBody:\n  content: {}\n\n# after\nrequestBody:\n  content:\n    application/json:\n      schema:\n        type: object","handlingStrategy":"validation","validationCode":"// JS: flag empty request-body content maps before generating\nfor (const [p, item] of Object.entries(spec.paths || {})) {\n  for (const op of Object.values(item)) {\n    const c = op && op.requestBody && op.requestBody.content;\n    if (c && Object.keys(c).length === 0) fail(`empty content in ${p}`);\n  }\n}","typeGuard":null,"tryCatchPattern":"try { generator.generate(); } catch (RuntimeException e) { if (String.valueOf(e.getMessage()).contains(\"when getting the content\")) { /* empty/degenerate content map: fix the requestBody */ } throw e; }","preventionTips":["Never commit content: {} placeholders; either fill a media type or drop the block","Run swagger-cli validate / Spectral on the spec before every generation","Watch out for custom preprocessors that strip inner schemas from content blocks"],"tags":["pydantic","python","request-body","openapi-spec"],"backgroundTag":"invalid-openapi-spec","analyzedSha":"fcec517be3cf5b7964296bcba25fbc97541484e7","analyzedAt":"2026-08-22T11:13:11.613Z","schemaVersion":2},"datasetVersion":"2026-08-22T14:17:55.899Z"}