微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

json – Swagger UI 2.1坚持“获取资源列表”

我有一个最近创建的RESTful API,我不记得几个月后如何使用它.我决定用Swagger记录我的API,但是我疯了.

我使用http://editor.swagger.io/创建了YAML文件,然后我将其转换为Swagger可以使用的JSON文件.当我将文件放入Swagger UI时,它只是陷入获取资源列表:localhost / swagger.json并且控制台显示Uncaught TypeError:无法读取未定义的属性’$ref’.

我正在使用Swagger UI的2.1.0-alpha.5版本.

这是我的spec文件

swagger: '2.0'
info:
  title: TITLE
  description: BLAH,BLAH,ETC
  version: "1.0b"
host: api.example.com
schemes:
 - http
basePath: /v1
produces:
 - application/json
paths:
  /match.json:
    get:
     #summary: Match Data
      description: Used for getting data about a match
      parameters:
        - name: id
          in: query
          description: The match ID of from a game
          required: true
          type: integer
          format: int32
        - name: key
          in: query
          description: API key used for authentication.
          required: true
          type: string
      responses:
        200:
          description: Returns match data
          schema:
            type: array
            items:
              $ref: '#/deFinitions/MatchData'
        default:
          description: Unexpected error
          schema:
            $ref: '#/deFinitions/Error'

deFinitions:
  MatchData:
    properties:
      info:
        type: integer
        format: int64
        description: General information about the match
      time:
        type: integer
        format: int64
        description: information about the start/end time
      stats:
        type: array
        format: int64
        description: Stats about the match
  Error:
    required:
     - errorID
      - message
    properties:
      errorID:
        type: string
        description: Error ID.
      message:
        type: string
        description: information about the error.

解决方法

我已经测试了你的规格,虽然我没有得到同样的错误,但规格确实无效.

如果你看一下#/ deFinitions / MatchData / properties / stats,你会看到你定义了类型:array但是你没有在它旁边提供一个’items’属性来说明它是哪个数组(这是必须的) .您可能打算使用类型:整数,如上面的属性,它与格式:int64一起使用.

由于我不知道您打算提供什么,因此很难提供准确的解决方案,但如果您根据自己的意图添加评论,我可以提供更详细的答案.

经过一些额外的测试,我发现UI中存在一个错误.进行修改并加载规范后,除非单击“展开操作”链接,否则操作本身不会展开.我已经开了一个关于它的issue,随便在那里关注它.

原文地址:https://www.jb51.cc/js/158251.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐