![](/img/trans.png)
[英]Swagger parameter error “is not exactly one from <#/definitions/parameter>”?
[英]Referencing multiple pre-defined swagger 2.0 parameter definitions throwing error
我在swagger 2.0文件中定义了两个可重复使用的参数:
parameters:
cursorParam:
name: cursor
in: query
description: Pagination cursor.
required: false
type: string
limitParam:
name: limit
in: query
description: Result limiter.
required: false
type: integer
然后在我的路由定义(在本例中为GET)中,我试图像这样引用两者:
parameters:
- $ref: '#/parameters/cursorParam'
- $ref: '#/parameters/limitParam'
如果我使用一个$ ref,它似乎可以正常工作(没有编译错误),但是如果我尝试同时使用两个,则它会凝视我:
Operation parameter already defined: undefined
at paths ▹ /users ▹ get ▹ parameters ▹ 1 ▹ name
Operation parameter already defined: undefined
at paths ▹ /authorisations ▹ get ▹ parameters ▹ 1 ▹ name
此外,如果我在查询字符串中传递这些参数并输出req.swagger.params
, req.swagger.params
得到一个空对象。 我究竟做错了什么?
这是规格的完整SSCCE,会产生相同的错误:
swagger: "2.0"
info:
version: "0.0.1"
title: Test
# during dev, should point to your local machine
host: localhost
# basePath prefixes all resource paths
basePath: /
#
schemes:
# tip: remove http to make production-grade
- http
- https
# format of bodies a client can send (Content-Type)
consumes:
- application/json
# format of the responses to the client (Accepts)
produces:
- application/json
x-a127-config: {}
x-volos-resources: {}
paths:
/authorisations:
x-swagger-router-controller: authorizations
x-volos-authorizations: {}
x-volos-apply: {}
get:
description: Returns all authorizations. Requires administrator rights to view unfiltered results, or if authenticated, returns the authorization entity belonging to the OAuth token.
operationId: authorizationsGetAll #controller method name
parameters:
- $ref: '#/parameters/cursorParam'
- $ref: '#/parameters/limitParam'
responses:
200:
description: OK
# reusable parameters have parameter definitions
parameters:
cursorParam:
name: cursor
in: query
description: Pagination cursor passed to a BaaS collection. Note that if this parameter is present, lastAccessedTimestamp.{channelType} should not be updated.
required: false
type: string
limitParam:
name: limit
in: query
description: Result limiter to be passed to a BaaS collection.
required: false
type: integer
看来您使用的是旧版本的a127。 Swagger文档的所有部分都缺乏参考支持,最近已修复,因此更新应解决此问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.