小编HTT*_*HTT的帖子

在我的 .Net 核心 API 中向 Swagger 添加自定义序列化程序

我使用来自jsonapi.orgJSONAPI规范,然后我使用JsonApiSerializer来完成 JSONAPI 规范,所以我的响应和请求正文如下所示:

{    
    "data": {
    "type": "articles",
    "id": "stringId",
    "attributes": {
      "title": "JSON:API paints my bikeshed!"
    }
}
Run Code Online (Sandbox Code Playgroud)

我有一个实体“文章”,它看起来像:

public class Article
{
     public string Id { get; set; }
     public string title { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

然后我尝试使用Swashbuckle Swagger来记录我的 API,但在Swagger UI 中,我的示例请求和响应正文如下所示:

{
     "id": "string",
     "title": "string"
}
Run Code Online (Sandbox Code Playgroud)

我认为 swagger 忽略了JsonApiSerializer,有没有办法更改 swagger 的默认序列化程序并使用我自己的序列化程序?

我的 Startup.cs 看起来像:

public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            this.Configuration = …
Run Code Online (Sandbox Code Playgroud)

c# swagger-ui json-api swashbuckle asp.net-core

8
推荐指数
1
解决办法
1644
查看次数

标签 统计

asp.net-core ×1

c# ×1

json-api ×1

swagger-ui ×1

swashbuckle ×1