How to configure Swashbuckle to ignore property on model

后端 未结 15 1787
旧巷少年郎
旧巷少年郎 2020-12-02 15:10

I\'m using Swashbuckle to generate swagger documentation\\UI for a webapi2 project. Our models are shared with some legacy interfaces so there are a couple of properties I

15条回答
  •  忘掉有多难
    2020-12-02 16:14

    (Based on mutex's answer.)

    I added another line to not have problems with NullReferenceException.

    public void Apply(Schema schema, SchemaRegistry schemaRegistry, Type type)
    {
      var excludeProperties = new[] { "myProp1", "myProp2, myProp3"};
    
       foreach (var prop in excludeProperties)
         if(schema.properties != null) // This line
           if (schema.properties.ContainsKey(prop))
            schema.properties.Remove(prop);        
    }

    If you want to delete all schemas

    public void Apply(Schema schema, SchemaRegistry schemaRegistry, Type type)
    {
      schema.properties = null;       
    } 
    

提交回复
热议问题