【问题标题】:Semantic error at paths./MyType.get.responses.200.schema.$ref $ref values must be RFC3986-compliant percent-encoded URIs路径中的语义错误。/MyType.get.responses.200.schema.$ref $ref 值必须是符合 RFC3986 的百分比编码 URI
【发布时间】:2019-05-09 05:04:42
【问题描述】:

我有一个 OData api,并为此启用了 swagger。当我将我的 OData api 的 json 信息粘贴到“editor.swagger.io”中时,它给了我错误: (路径上的语义错误 ./BankBranches.get.responses.200.schema.$ref $ref 值必须是 符合 RFC3986 的百分比编码 URI)

我的回复如下:

回应: “200”: 描述:好的 架构: $ref: '#/definitions/ODataResponse[List[BankBranch]]'

我知道我可以通过删除所有的 "[" , "]" 来解决问题,但是在大型项目中这太难了并且需要太多时间。 我不知道如何在我的 OData api 中更改以没有这个问题??

【问题讨论】:

  • 如果你能提供minimal reproducible example就太好了
  • 我不知道如何更好地解释。简单地说,我在我用 OData 制作的 api 中安装了 swashbuckle.OData 和 swashbuckle。当我在浏览器中运行应用程序时,我将“localhost:53000/swagger”放在地址栏中,它给了我它的招摇文档。然后我将收到的地址(localhost:53000/swagger/docs/v1)粘贴到浏览器另一个选项卡的地址栏中,然后它给了我一些 json 格式的数据,我将整个数据粘贴到“editor.swagger.io”的网站上,然后我在“editor.swagger.io”中遇到上层错误。
  • 错误是 ==>> 路径中的语义错误。/BankBranches.get.responses.200.schema.$ref $ref 值必须是符合 RFC3986 的百分比编码 URI
  • 如您所知,“editor.swagger.io”中有一部分是“responses:”。我在这部分有以下代码:
  • 响应:'200':描述:OK 架构:$ref:'#/definitions/ODataResponse[List[BankAcc]]'

标签: c# asp.net odata swagger-2.0


【解决方案1】:

如果你的 swaggerResponse 看起来像

[SwaggerResponse(HttpStatusCode.OK, "OK Result", typeof(IEnumerable<int>))]

你可以为响应创建一个包装器

public class MyResponse: IEnumerable<ItemGroup>> {}

更新

[SwaggerResponse(HttpStatusCode.OK, "OK Result", typeof(MyResponse))]

【讨论】:

    猜你喜欢
    • 2022-11-02
    • 1970-01-01
    • 2020-01-12
    • 1970-01-01
    • 2019-12-07
    • 2011-08-20
    • 2014-09-16
    • 2014-12-20
    • 2017-02-23
    相关资源
    最近更新 更多