Sayi / swagger-dubbo

:page_with_curl: Dubbo的Swagger服务文档
Apache License 2.0
331 stars 187 forks source link

dubbo入参对象没有解析 #17

Open hfq-yangyang-yangyang opened 6 years ago

hfq-yangyang-yangyang commented 6 years ago

入参对象没有解析出来

ChannelOutput offlineRefund(OfflineRefundInput)线下退款 最好将OfflineRefundInput内部属性解析并展示出来。

json片段: "/h/com.huifenqi.jedi.resultprocess.facade.RefundFacade/offlineRefund": { "post": { "tags": [ "RefundFacade" ], "summary": "线下退款", "description": "ChannelOutput offlineRefund(com.huifenqi.jedi.resultprocess.params.OfflineRefundInput)线下退款", "operationId": "offlineRefund", "parameters": [ { "name": "offlineRefundInput", "in": "formData", "required": false, "type": "string" } ], "responses": { "200": { "description": "", "schema": { "$ref": "#/definitions/ChannelOutput" } } } } },

Sayi commented 6 years ago

升级swagger-dubbo到2.0.1版本试试。

基于 @JKTerrific 的PR #16 做了一点点的修改。

hfq-yangyang-yangyang commented 6 years ago

swagger-dubbo到2.0.1版本

返回的json参数 没有显示到swagger页面上,显示以下

Response Body no content Response Code 0 Response Headers { "error": "no response from server" }

Sayi commented 6 years ago
no response from server

这是服务端没响应,看看服务是否正常启动了,是否有异常日志。

hfq-yangyang-yangyang commented 6 years ago

你这个return是有数据的,到swagger页面就没有了

@RequestMapping(value = "/{interfaceClass}/{methodName}", produces = "application/json; charset=utf-8") @ResponseBody public ResponseEntity invokeDubbo(@PathVariable("interfaceClass") String interfaceClass, @PathVariable("methodName") String methodName, HttpServletRequest request, HttpServletResponse response) throws Exception { return invokeDubbo(interfaceClass, methodName, null, request, response); }

Sayi commented 6 years ago

可以把api-docs暴露的JSON数据发给我吗?

hfq-yangyang-yangyang commented 6 years ago

找的问题了,还是SwaggerDubboController 跨域问题

Sayi commented 6 years ago

文档上有推荐的跨域做法,如果Spring版本过低,自己写个拦截器 对/sawgger-dubbo/api-docs 设置跨域。

hfq-yangyang-yangyang commented 6 years ago

由于swagger作为独立服务不集成到项目中(尽可能降低耦合),

springboot 跨域 DubboHttpController和SwaggerDubboController 都要加上,否则会有上面的问题

sunwulovelove1 commented 3 years ago

我也遇到这个情况了 POST 请求时,传递RequestBody

看了一下代码: com.deepoove.swagger.dubbo.web.DubboHttpController#invokeDubbo(java.lang.String, java.lang.String, java.lang.String, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)

里面解析使用: request.getParameter

POST/RequestBody 下无法获取到值。

debug过程:

获取到传入 Object suggestPrameterValue = this.suggestPrameterValue(parameterTypes[i], parameterClazz[i], request.getParameter(parameterNames[i])); 中:

request.getParameter(parameterNames[i])) 无法获取到参数,suggestPrameterValue null

将request 解析 IOUtils.read(new BufferedReader(new InputStreamReader(request.getInputStream()))) 可以获取到requestbody里面的内容