alibaba/spring-ai-alibaba · error · RuntimeException

ResponseBody Only Support object or array Type

Error message

ResponseBody Only Support object or array Type

What it means

parseSchemaToForm() validates the operation's success response schema and only allows type 'object' or 'array'; any other type (string, integer, no type, binary) throws RuntimeException("ResponseBody Only Support object or array Type") because output parameters are derived from object properties or array items.

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:304

				ApiResponses apiResponses = operation.getResponses();
				ApiResponse apiResponse = apiResponses.get("200");
				if (apiResponse != null && apiResponse.getContent() != null) {
					MediaType mediaType = apiResponse.getContent()
						.get(org.springframework.http.MediaType.APPLICATION_JSON_VALUE);
					if (mediaType == null) {
						mediaType = apiResponse.getContent()
							.get(org.springframework.http.MediaType.APPLICATION_FORM_URLENCODED_VALUE);
					}

					if (mediaType == null) {
						mediaType = apiResponse.getContent().get("*/*");
					}

					if (mediaType != null) {
						Schema responseSchema = mediaType.getSchema();
						String type = responseSchema.getType();
						if (!"object".equals(type) && !"array".equals(type)) {
							throw new RuntimeException("ResponseBody Only Support object or array Type");
						}

						List<ApiParameter> outputParams = new ArrayList<>();
						if ("object".equals(type)) {
							Map<String, Schema> properties = responseSchema.getProperties();
							if (!CollectionUtils.isEmpty(properties)) {

								properties.forEach((name, nameSchema) -> {
									ApiParameter yamlParamInfo = new ApiParameter();
									yamlParamInfo.setKey(name);
									yamlParamInfo.setDescription(nameSchema.getDescription());
									String nameSchemaType = nameSchema.getType();
									if ("array".equals(nameSchemaType)) {
										Schema schemItem = nameSchema.getItems();
										String itemType = schemItem.getType();
										if ("object".equals(itemType)) {
											// 增加父类
											yamlParamInfo.setType("Array<Object>");

View on GitHub (pinned to f82da0b50f)

Solutions

  1. Wrap the primitive response in an object in the spec: {type: object, properties: {result: {type: string}}}
  2. For binary responses, exclude the endpoint from import or wrap metadata in an object
  3. Add the missing type keyword to the response schema if it was simply omitted

Example fix

// before
responses:
  '200':
    content:
      application/json:
        schema: {type: string}
// after
responses:
  '200':
    content:
      application/json:
        schema:
          type: object
          properties:
            result: {type: string}
Defensive patterns

Strategy: validation

Validate before calling

Schema<?> resp = apiResponse.getContent().values().iterator().next().getSchema();
if (!("object".equals(resp.getType()) || "array".equals(resp.getType()))) {
    throw new IllegalArgumentException("Response schema must be object or array");
}

Type guard

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

Try / catch

try {
    OpenApiUtils.parseSchemaToForm(spec);
} catch (RuntimeException e) {
    if (e.getMessage().contains("ResponseBody Only Support")) {
        // wrap primitive response in an object schema and retry
    }
}

Prevention

When it happens

Trigger: Importing an OpenAPI operation whose 2xx response schema is a primitive (e.g. {type: string}), a binary download, or is missing the type keyword entirely.

Common situations: Endpoints returning plain strings/numbers (echo, status checks); file download endpoints returning binary; loosely written specs omitting response schema types.

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/782363996a475f5e. Report an issue: GitHub.