{"record":{"id":"782363996a475f5e","repo":"alibaba/spring-ai-alibaba","slug":"responsebody-only-support-object-or-array-type","errorCode":null,"errorMessage":"ResponseBody Only Support object or array Type","messagePattern":"ResponseBody Only Support object or array Type","errorType":"validation","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-core/src/main/java/com/alibaba/cloud/ai/studio/core/utils/api/OpenApiUtils.java","lineNumber":304,"sourceCode":"\t\t\t\tApiResponses apiResponses = operation.getResponses();\n\t\t\t\tApiResponse apiResponse = apiResponses.get(\"200\");\n\t\t\t\tif (apiResponse != null && apiResponse.getContent() != null) {\n\t\t\t\t\tMediaType mediaType = apiResponse.getContent()\n\t\t\t\t\t\t.get(org.springframework.http.MediaType.APPLICATION_JSON_VALUE);\n\t\t\t\t\tif (mediaType == null) {\n\t\t\t\t\t\tmediaType = apiResponse.getContent()\n\t\t\t\t\t\t\t.get(org.springframework.http.MediaType.APPLICATION_FORM_URLENCODED_VALUE);\n\t\t\t\t\t}\n\n\t\t\t\t\tif (mediaType == null) {\n\t\t\t\t\t\tmediaType = apiResponse.getContent().get(\"*/*\");\n\t\t\t\t\t}\n\n\t\t\t\t\tif (mediaType != null) {\n\t\t\t\t\t\tSchema responseSchema = mediaType.getSchema();\n\t\t\t\t\t\tString type = responseSchema.getType();\n\t\t\t\t\t\tif (!\"object\".equals(type) && !\"array\".equals(type)) {\n\t\t\t\t\t\t\tthrow new RuntimeException(\"ResponseBody Only Support object or array Type\");\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tList<ApiParameter> outputParams = new ArrayList<>();\n\t\t\t\t\t\tif (\"object\".equals(type)) {\n\t\t\t\t\t\t\tMap<String, Schema> properties = responseSchema.getProperties();\n\t\t\t\t\t\t\tif (!CollectionUtils.isEmpty(properties)) {\n\n\t\t\t\t\t\t\t\tproperties.forEach((name, nameSchema) -> {\n\t\t\t\t\t\t\t\t\tApiParameter yamlParamInfo = new ApiParameter();\n\t\t\t\t\t\t\t\t\tyamlParamInfo.setKey(name);\n\t\t\t\t\t\t\t\t\tyamlParamInfo.setDescription(nameSchema.getDescription());\n\t\t\t\t\t\t\t\t\tString nameSchemaType = nameSchema.getType();\n\t\t\t\t\t\t\t\t\tif (\"array\".equals(nameSchemaType)) {\n\t\t\t\t\t\t\t\t\t\tSchema schemItem = nameSchema.getItems();\n\t\t\t\t\t\t\t\t\t\tString itemType = schemItem.getType();\n\t\t\t\t\t\t\t\t\t\tif (\"object\".equals(itemType)) {\n\t\t\t\t\t\t\t\t\t\t\t// 增加父类\n\t\t\t\t\t\t\t\t\t\t\tyamlParamInfo.setType(\"Array<Object>\");","sourceCodeStart":286,"sourceCodeEnd":322,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-core/src/main/java/com/alibaba/cloud/ai/studio/core/utils/api/OpenApiUtils.java#L286-L322","documentation":"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.","triggerScenarios":"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.","commonSituations":"Endpoints returning plain strings/numbers (echo, status checks); file download endpoints returning binary; loosely written specs omitting response schema types.","solutions":["Wrap the primitive response in an object in the spec: {type: object, properties: {result: {type: string}}}","For binary responses, exclude the endpoint from import or wrap metadata in an object","Add the missing type keyword to the response schema if it was simply omitted"],"exampleFix":"// before\nresponses:\n  '200':\n    content:\n      application/json:\n        schema: {type: string}\n// after\nresponses:\n  '200':\n    content:\n      application/json:\n        schema:\n          type: object\n          properties:\n            result: {type: string}","handlingStrategy":"validation","validationCode":"Schema<?> resp = apiResponse.getContent().values().iterator().next().getSchema();\nif (!(\"object\".equals(resp.getType()) || \"array\".equals(resp.getType()))) {\n    throw new IllegalArgumentException(\"Response schema must be object or array\");\n}","typeGuard":"static boolean isSupportedResponseSchema(Schema<?> s) {\n    return s != null && (\"object\".equals(s.getType()) || \"array\".equals(s.getType()));\n}","tryCatchPattern":"try {\n    OpenApiUtils.parseSchemaToForm(spec);\n} catch (RuntimeException e) {\n    if (e.getMessage().contains(\"ResponseBody Only Support\")) {\n        // wrap primitive response in an object schema and retry\n    }\n}","preventionTips":["Define all success responses as object/array schemas","Wrap plain scalar returns in {result: ...} objects","Lint 2xx response schemas before import"],"tags":["openapi","import","validation","java"],"backgroundTag":"schema-validation-failed","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}