简体   繁体   中英

Mixing System.Text.Json and Newtonsoft.Json with Swagger

One of my company's applications import packages that contain models that become responses from our API

using Newtonsoft.Json;
public class Foo 
{
    [JsonProperty("bar"]
    public string Bar { get; set;} 
}

We have for our own models migrated to System.Text.Json , which uses [JsonPropertyName("foobaz")]

Swagger picks up the correct formatting for our own models automatically, but not for the imported packages.

If we add AddSwaggerGenNewtonsoftSupport in program.cs, it picks it up for the imported models, but not for our models.

Is there any way to tell swagger to handle both?

use both attributes

    [JsonProperty("bar"]
    [JsonPropertyName("foobaz")]
    public string Bar { get; set;} 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM