alibaba/spring-ai-alibaba · error · RuntimeException

RequestBody Only Support object Type

Error message

RequestBody Only Support object Type

What it means

parseSchemaToForm() inspects the OpenAPI requestBody and requires its media-type schema to be of type 'object' (properties map). Any other type (string, array, binary, or a schema without an explicit type) throws RuntimeException("RequestBody Only Support object Type").

Source

Thrown at spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-core/src/main/java/com/alibaba/cloud/ai/studio/core/utils/api/OpenApiUtils.java:213

				List<ApiParameter> inputYamlParamList = new ArrayList<>();
				paramToYamlParam(parameters, inputYamlParamList);
				Operation operation = null;
				if (pathItem.getPost() != null) {
					operation = pathItem.getPost();
					toolConfig.setRequestMethod("Post");
					if (operation.getParameters() != null) {
						paramToYamlParam(operation.getParameters(), inputYamlParamList);
					}

					RequestBody requestBody = operation.getRequestBody();
					if (requestBody != null) {
						Content content = requestBody.getContent();
						toolConfig.setContentType(content.keySet().iterator().next());
						content.values().forEach(e -> {
							Schema schema = e.getSchema();
							String type = schema.getType();
							if (!"object".equals(type)) {
								throw new RuntimeException("RequestBody Only Support object Type");
							}

							Map<String, Schema> properties = schema.getProperties();
							List<String> requiredKeys = schema.getRequired();
							properties.forEach((name, nameSchema) -> {
								ApiParameter yamlParamInfo = new ApiParameter();
								yamlParamInfo.setKey(name);
								yamlParamInfo.setDescription(nameSchema.getDescription());
								yamlParamInfo.setLocation("Body");

								if (requiredKeys != null && requiredKeys.contains(name)) {
									yamlParamInfo.setRequired(true);
								}

								if (nameSchema.getDefault() != null) {
									yamlParamInfo.setDefaultValue(nameSchema.getDefault().toString());
								}

View on GitHub (pinned to f82da0b50f)

Solutions

  1. Wrap the body in an object: {type: object, properties: {data: {...}}} in the OpenAPI spec
  2. For file uploads, define the body as an object property of type string/format binary inside an object schema
  3. For raw/array bodies, change the endpoint or pre-transform the spec to an object wrapper before import

Example fix

// before
requestBody:
  content:
    application/json:
      schema:
        type: array
        items: {type: string}
// after
requestBody:
  content:
    application/json:
      schema:
        type: object
        properties:
          values:
            type: array
            items: {type: string}
Defensive patterns

Strategy: validation

Validate before calling

Schema<?> body = requestBody.getContent().values().iterator().next().getSchema();
if (!"object".equals(body.getType())) {
    throw new IllegalArgumentException("requestBody schema must be type object");
}

Type guard

static boolean isObjectBodySchema(Schema<?> s) { return s != null && "object".equals(s.getType()); }

Try / catch

try {
    OpenApiUtils.parseSchemaToForm(spec);
} catch (RuntimeException e) {
    if (e.getMessage().contains("RequestBody Only Support object")) {
        // wrap body in object schema and retry import
    }
}

Prevention

When it happens

Trigger: Importing an OpenAPI operation whose requestBody schema is type: string (raw text), type: array (JSON array top-level), type: string format: binary (file upload), or lacks a type field.

Common situations: File-upload endpoints (multipart binary bodies); APIs accepting raw text/plain or top-level JSON arrays; specs produced by generators that omit the top-level type keyword.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09). Data as JSON: /api/errors/55b651c2fc10ee95. Report an issue: GitHub.