yapi OpenAPI 3 的 json 数据导入无法显示接口定义的响应实体信息

sd2nnvve  于 2021-12-03  发布在  Java
关注(0)|答案(6)|浏览(2013)

版本号

1.9.2

什么问题

系统集成 springdoc-openapi-ui 1.4.3 生成 OpenAPI 3 的 json,导入 YApi,“返回数据“ 无法显示接口定义的实体字段

如何复现此问题

测试 json 如下:

{"openapi":"3.0.1","info":{"title":"接口文档","description":"","license":{"name":"Apache 2.0","url":""},"version":"v0.0.1"},"servers":[{"url":"http://localhost:8080","description":"Generated server url"}],"paths":{"/user/register":{"post":{"tags":["用户接口"],"summary":"用户注册","description":"获取用户帐号基本信息,用于创建用户帐号","operationId":"register","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/RegisterModel"}}},"required":true},"responses":{"200":{"description":"操作成功","content":{"*/*":{"schema":{"$ref":"#/components/schemas/ResponseInfoRegisterModel"}}}},"500":{"description":"系统异常","content":{"*/*":{"schema":{"$ref":"#/components/schemas/ResponseInfoRegisterModel"}}}}}}}},"components":{"schemas":{"RegisterModel":{"required":["mobile","password"],"type":"object","properties":{"mobile":{"title":"手机号码","maxLength":20,"minLength":1,"type":"string","description":"手机号码,必填","example":"13800138000"},"password":{"title":"密码","maxLength":20,"minLength":1,"type":"string","description":"密码,必填","example":"123456"}}},"ResponseInfoRegisterModel":{"required":["code","data","message","success"],"type":"object","properties":{"success":{"title":"成功标识","type":"boolean","description":"成功标识:true:成功;false:失败","example":true},"code":{"title":"响应代码","type":"integer","description":"响应代码","format":"int32","example":200},"message":{"title":"响应信息","type":"string","description":"响应信息","example":"操作成功"},"data":{"$ref":"#/components/schemas/RegisterModel"}}}}}}

将上面的 json 复制到 swagger 官网的在线编辑器( https://app.swaggerhub.com/home)能看到响应的实体的 Schemas

什么浏览器

360 极速浏览器

什么系统(Linux, Windows, macOS)

windows 10

3gtaxfhh

3gtaxfhh1#

遇到同样问题,刚才临时找到一个方法,你可以试试。

修改vendors/exts/yapi-plugin-import-swagger/run.js文件的openapi2swagger方法,然后重启yapi服务。

if (
            res.content &&
            res.content['application/json'] &&
            typeof res.content['application/json'] === 'object'
          ) {
            Object.assign(res, res.content['application/json']);
            delete res.content;
          }

修改为

if (
            res.content &&
            res.content['application/json'] &&
            typeof res.content['application/json'] === 'object'
          ) {
            Object.assign(res, res.content['application/json']);
            delete res.content;
          }
          if (
            res.content &&
            res.content['application/hal+json'] &&
            typeof res.content['application/hal+json'] === 'object'
          ) {
            Object.assign(res, res.content['application/hal+json']);
            delete res.content;
          }
          if (
            res.content &&
            res.content['*/*'] &&
            typeof res.content['*/*'] === 'object'
          ) {
            Object.assign(res, res.content['*/*']);
            delete res.content;
          }
lh80um4z

lh80um4z2#

非常感谢你的回答。但是我试了,问题并没有解决。 如果是版本支持问题的话,非常希望官方下个版本能解决。…

------------------ 原始邮件 ------------------ 发件人: "Li Feixiang"<notifications@github.com>; 发送时间: 2020年8月4日(星期二) 晚上10:42 收件人: "YMFE/yapi"<yapi@noreply.github.com>; 抄送: "小赞"<291080828@qq.com>; "Author"<author@noreply.github.com>; 主题: Re: [YMFE/yapi] OpenAPI 3 的 json 数据导入无法显示接口定义的响应实体信息 (#1887) 遇到同样问题,刚才临时找到一个方法,你可以试试。 修改vendors/exts/yapi-plugin-import-swagger/run.js文件的openapi2swagger方法,然后重启yapi服务。 if ( res.content && res.content['application/json'] && typeof res.content['application/json'] === 'object' ) { Object.assign(res, res.content['application/json']); delete res.content; } 修改为 if ( res.content && res.content['application/json'] && typeof res.content['application/json'] === 'object' ) { Object.assign(res, res.content['application/json']); delete res.content; } if ( res.content && res.content['application/hal+json'] && typeof res.content['application/hal+json'] === 'object' ) { Object.assign(res, res.content['application/hal+json']); delete res.content; } if ( res.content && res.content['/'] && typeof res.content['/'] === 'object' ) { Object.assign(res, res.content['/']); delete res.content; } — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

kqlmhetl

kqlmhetl3#

我是用的命令行导入方式,拿你的json也试了下没问题,但是界面导入确实不行,难道不是一个方法?
通过命令行导入接口数据

sz81bmfz

sz81bmfz4#

又看了下代码,命令行导入是在服务端解析openapi的json,界面导入是在客户端解析openapi的json,所以需要将修改后代码编译发布。

xqnpmsa8

xqnpmsa85#

我的是通过npm安装的,不知道要怎样进行编译发布呢?是要在npm下载的模块里找到对应的代码,进行修改,再重新初始化 yapi,是这个意思吗?另外,这样子修改了源码后,对于以后的升级会不会有影响?…

------------------ 原始邮件 ------------------ 发件人: "Li Feixiang"<notifications@github.com>; 发送时间: 2020年8月5日(星期三) 上午9:44 收件人: "YMFE/yapi"<yapi@noreply.github.com>; 抄送: "小赞"<291080828@qq.com>; "Author"<author@noreply.github.com>; 主题: Re: [YMFE/yapi] OpenAPI 3 的 json 数据导入无法显示接口定义的响应实体信息 (#1887) 又看了下代码,命令行导入是在服务端解析openapi的json,界面导入是在客户端解析openapi的json,所以需要将修改后代码编译发布。 — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

trnvg8h3

trnvg8h36#

配置文件指定不适用3.0的规范就行了

springfox:
  documentation:
    swagger:
      use-model-v3: false

相关问题