2016-11-16 57 views
0

我正在使用带有ASP.NET Core Web API的Swashbuckle 6(Swagger)。我的模型有DTO作为后缀,例如,使用ASP.NET Core Web API在Swashbuckle 6(Swagger)中重命名模型

public class TestDTO { 
    public int Code { get; set; } 
    public string Message { get; set; } 
} 

如何生成的文档重命名为只是“测试”?我试过用名称添加DataContract属性,但这没有帮助。

[HttpGet] 
public IActionResult Get() { 
    //... create List<TestDTO> 
    return Ok(list); 
} 

回答

1

想通了......类似的答案在这里:Swashbuckle rename Data Type in Model

唯一的区别是该属性现在被称为CustomSchemaIds代替SchemaId:

options.CustomSchemaIds(schemaIdStrategy); 

而不是看DataContract属性,我只是删除了“DTO”:

private static string schemaIdStrategy(Type currentClass) { 
    string returnedValue = currentClass.Name; 
    if (returnedValue.EndsWith("DTO")) 
     returnedValue = returnedValue.Replace("DTO", string.Empty); 
    return returnedValue; 
} 
相关问题