kev*_*c45 8 json yaml swagger swagger-ui
我有一个最近创建的RESTful API,我不记得几个月后如何使用它.我决定用Swagger记录我的API,但是我疯了.
我使用http://editor.swagger.io/创建了YAML文件,然后我将其转换为Swagger可以使用的JSON文件.当我将文件放入Swagger UI时,它就会陷入困境fetching resource list: localhost/swagger.json并且控制台说Uncaught TypeError: Cannot read property '$ref' of undefined .

我正在使用Swagger UI的2.1.0-alpha.5版本.
这是我的spec文件:
swagger: '2.0'
info:
title: TITLE
description: BLAH, 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,你会看到你定义了type: array但是你没有在它旁边提供一个'items'属性来说明它是哪个数组(这是必须的).您可能打算type: integer像上面的属性一样使用它,这与它一起使用format: int64.
由于我不知道您打算提供什么,因此很难给出准确的解决方案,但如果您根据自己的意图添加评论,我可以提供更详细的答案.
经过一些额外的测试,我发现UI中存在一个错误.进行修改并加载规范后,除非单击Expand Operations链接,否则操作本身不会展开.我已经开了一个关于它的问题,随便在那里关注它.
| 归档时间: |
|
| 查看次数: |
8583 次 |
| 最近记录: |