我正在使用https://www.npmjs.com/package/swagger,我正在尝试创建配置。我有swagger.js的这一部分
"dummy\/{id}\/related_dummies": {
"get": {
"tags": [
"RelatedDummy"
],
"operationId": "get_by_parentRelatedDummyCollection",
"produces": [
"application\/ld+json",
"application\/hal+json",
"application\/xml",
"text\/xml",
"application\/json",
"text\/html"
],
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"type": "integer"
}
],
"summary": "Retrieves the collection of RelatedDummy resources.",
"responses": {
"200": {
"description": "RelatedDummy collection response",
"schema": {
"type": "array",
"items": {
"$ref": "#\/definitions\/RelatedDummy"
}
}
}
}
}
但是当我运行swagger验证swagger.js时,我不断收到此错误:
Project Errors
--------------
#/paths: Additional properties not allowed: dummy/{id}/related_dummies
Results: 1 errors, 0 warnings
错误的原因是什么?感谢
答案 0 :(得分:7)
问题是路径dummy/{id}/related_dummies
不以斜杠开头。
要被识别为有效的路径项对象,它必须是/dummy/{id}/related_dummies
。
使用示例中的转义语法,名称应为"\/dummy\/{id}\/related_dummies"
Swagger-OpenAPI 2.0规范的相关部分在Paths Object定义中。