![](/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.