Customize generated model names - Swagger UI

前端 未结 2 1652
心在旅途
心在旅途 2021-02-19 20:50

I\'m trying to adjust the \"displayName\" of the model being used in an automatically generated Swagger definition.

This will only affect the Swagger names, meaning the

2条回答
  •  不要未来只要你来
    2021-02-19 21:38

    (Accounts for .net core:)
    I would combine the display attribute of the class with a custom swagger schema:

    [DisplayName("NewCompany")]
    public class Company
    {
    }
    

    and then in Startup:

    services.AddSwaggerGen(c =>
    {                     
        c.CustomSchemaIds(x => x.GetCustomAttributes().SingleOrDefault().DisplayName);
    });
    

    see also this answer

提交回复
热议问题