如何在raml查询参数中定义map[string][]string



我愿意在RAML中定义一个查询参数,即map[string][]string,但我不知道如何定义它。相反,我使用示例,但API设计器没有在我定义时显示它。

我的问题:为什么API设计器中没有显示查询参数的示例

示例:

#%RAML 1.0
title: sample API
baseUri: http://localhost:3000/api/{version}
version: v1
protocols: [http]
mediaType: application/json
traits:
filterProducts: 
usage: filter products
queryParameters: 
filters:
displayName: filters
type: object
description: filter returned products
examples:
required-general-filters: {
"page": 1,
"limit": 10,
}
filter-based-on-product-id: {
"productId": 123,
"returnedProducts": ["similar", "related", "buyed"],
}
required: true
resourceTypes:
products: 
get: 
is: [FilterTraits.filterProducts]
description: get all products
responses: 
200:
body:
application/json:
example: {
success: true,
data: "data",
error: null,
}
/products:
type: {ResourceTypes.products}

我想明白了。您可以简单地将查询字符串定义为RAML中的类型,然后在查询参数中使用它,如下所示:

#%RAML 1.0
types:
filterCollection:
description: filter collection query strings
properties:
hasSell:
description: collection has sell
type: boolean
required: false
example: true
minSell:
description: collection total sell is greater than minSell
type: number
required: false
example: 10
traits:
filters:
usage: getting products based on query parameters.
queryParameters:
pid:
displayName: Product Id
type: string
required: false
filter:
type: Types.filters
/product:
type: { ResourceTypes.Collection }
is: [filters]
put:

最新更新