OpenAPITools/openapi-generator · error · RuntimeException

Error! Failed to process getPydanticType when getting the co

Error message

Error! Failed to process getPydanticType when getting the content: %s

What it means

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.

Source

Thrown at modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java:2362

            PythonType result = fromCommon(cp);

            if (result == null) {
                if (!cp.isPrimitiveType) {
                    // add model prefix
                    hasModelsToImport = true;
                    modelImports.add(cp.getDataType());
                    exampleImports.add(cp.getDataType());
                    result = new PythonType(cp.getDataType());
                } else if (cp.getContent() != null) {
                    LinkedHashMap<String, CodegenMediaType> contents = cp.getContent();
                    for (String key : contents.keySet()) {
                        CodegenMediaType cmt = contents.get(key);
                        // TODO process the first one only at the moment
                        if (cmt != null)
                            // TODO: don't loop back to the deprecated getPydanticType method
                            return getPydanticType(cmt.getSchema(), modelImports, exampleImports, postponedModelImports, postponedExampleImports, moduleImports, classname);
                    }
                    throw new RuntimeException("Error! Failed to process getPydanticType when getting the content: " + cp);
                } else {
                    throw new RuntimeException("Error! Codegen Parameter not yet supported in getPydanticType: " + cp);
                }
            }

            return result;
        }

        private String finalizeType(CodegenParameter cp, PythonType pt) {
            if (!cp.required || cp.isNullable) {
                moduleImports.add(TYPING, "Optional");
                PythonType opt = new PythonType("Optional");
                opt.addTypeParam(pt);
                pt = opt;
            }

            if (!StringUtils.isEmpty(cp.description)) { // has description
                pt.annotate("description", cp.description);

View on GitHub (pinned to fcec517be3)

Solutions

  1. Fix the spec so every requestBody content has at least one media type with a schema: content: { application/json: { schema: { type: object } } }
  2. Remove empty content blocks entirely so the parameter takes the normal typed path
  3. 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

Example fix

# before
requestBody:
  content: {}

# after
requestBody:
  content:
    application/json:
      schema:
        type: object
Defensive patterns

Strategy: validation

Validate before calling

// JS: flag empty request-body content maps before generating
for (const [p, item] of Object.entries(spec.paths || {})) {
  for (const op of Object.values(item)) {
    const c = op && op.requestBody && op.requestBody.content;
    if (c && Object.keys(c).length === 0) fail(`empty content in ${p}`);
  }
}

Try / catch

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; }

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of OpenAPITools/openapi-generator@fcec517be3 (2026-08-22). Data as JSON: /api/errors/1926bab1c07c59d4. Report an issue: GitHub.