{"record":{"id":"55b651c2fc10ee95","repo":"alibaba/spring-ai-alibaba","slug":"requestbody-only-support-object-type","errorCode":null,"errorMessage":"RequestBody Only Support object Type","messagePattern":"RequestBody Only Support object 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":213,"sourceCode":"\t\t\t\tList<ApiParameter> inputYamlParamList = new ArrayList<>();\n\t\t\t\tparamToYamlParam(parameters, inputYamlParamList);\n\t\t\t\tOperation operation = null;\n\t\t\t\tif (pathItem.getPost() != null) {\n\t\t\t\t\toperation = pathItem.getPost();\n\t\t\t\t\ttoolConfig.setRequestMethod(\"Post\");\n\t\t\t\t\tif (operation.getParameters() != null) {\n\t\t\t\t\t\tparamToYamlParam(operation.getParameters(), inputYamlParamList);\n\t\t\t\t\t}\n\n\t\t\t\t\tRequestBody requestBody = operation.getRequestBody();\n\t\t\t\t\tif (requestBody != null) {\n\t\t\t\t\t\tContent content = requestBody.getContent();\n\t\t\t\t\t\ttoolConfig.setContentType(content.keySet().iterator().next());\n\t\t\t\t\t\tcontent.values().forEach(e -> {\n\t\t\t\t\t\t\tSchema schema = e.getSchema();\n\t\t\t\t\t\t\tString type = schema.getType();\n\t\t\t\t\t\t\tif (!\"object\".equals(type)) {\n\t\t\t\t\t\t\t\tthrow new RuntimeException(\"RequestBody Only Support object Type\");\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tMap<String, Schema> properties = schema.getProperties();\n\t\t\t\t\t\t\tList<String> requiredKeys = schema.getRequired();\n\t\t\t\t\t\t\tproperties.forEach((name, nameSchema) -> {\n\t\t\t\t\t\t\t\tApiParameter yamlParamInfo = new ApiParameter();\n\t\t\t\t\t\t\t\tyamlParamInfo.setKey(name);\n\t\t\t\t\t\t\t\tyamlParamInfo.setDescription(nameSchema.getDescription());\n\t\t\t\t\t\t\t\tyamlParamInfo.setLocation(\"Body\");\n\n\t\t\t\t\t\t\t\tif (requiredKeys != null && requiredKeys.contains(name)) {\n\t\t\t\t\t\t\t\t\tyamlParamInfo.setRequired(true);\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tif (nameSchema.getDefault() != null) {\n\t\t\t\t\t\t\t\t\tyamlParamInfo.setDefaultValue(nameSchema.getDefault().toString());\n\t\t\t\t\t\t\t\t}\n","sourceCodeStart":195,"sourceCodeEnd":231,"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#L195-L231","documentation":"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\").","triggerScenarios":"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.","commonSituations":"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.","solutions":["Wrap the body in an object: {type: object, properties: {data: {...}}} in the OpenAPI spec","For file uploads, define the body as an object property of type string/format binary inside an object schema","For raw/array bodies, change the endpoint or pre-transform the spec to an object wrapper before import"],"exampleFix":"// before\nrequestBody:\n  content:\n    application/json:\n      schema:\n        type: array\n        items: {type: string}\n// after\nrequestBody:\n  content:\n    application/json:\n      schema:\n        type: object\n        properties:\n          values:\n            type: array\n            items: {type: string}","handlingStrategy":"validation","validationCode":"Schema<?> body = requestBody.getContent().values().iterator().next().getSchema();\nif (!\"object\".equals(body.getType())) {\n    throw new IllegalArgumentException(\"requestBody schema must be type object\");\n}","typeGuard":"static boolean isObjectBodySchema(Schema<?> s) { return s != null && \"object\".equals(s.getType()); }","tryCatchPattern":"try {\n    OpenApiUtils.parseSchemaToForm(spec);\n} catch (RuntimeException e) {\n    if (e.getMessage().contains(\"RequestBody Only Support object\")) {\n        // wrap body in object schema and retry import\n    }\n}","preventionTips":["Always define request bodies as object schemas","Wrap raw/array/binary payloads in a named property","Run an OpenAPI linter tuned to these import rules"],"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"}