2017-01-19 8 views
0

私はカスタムヘッダを取るAPI終点を持っています。 このヘッダは次のようになりますオブジェクトです:私は次のように私にできるAPIメソッドにパラメータとしてタイプを持っている場合は任意のapiメソッドで使用されていない型の型定義を追加します。

User: {"UserId":"someguid"} 

public class AddFileParamTypes : IOperationFilter 
{ 
    public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription) 
    { 
     if (operation.operationId == "FileDelivery_Post") 
     { 

      operation.consumes.Add("multipart/form-data"); 
      operation.parameters.Add(new Parameter 
      { 
       name = "file", 
       required = true, 
       type = "file", 
       @in = "formData" 
      }); 
      operation.parameters.Add(new Parameter 
      { 
       name = "User", 
       required = true, 
       schema = new Schema() { @ref = "#/definitions/User" }, 
       @in = "header" 
      }); 
     } 
    } 
} 

しかし、ユーザータイプはなりませんメソッドのパラメータなので、スワッシュバックルに定義を追加するにはどうすればよいですか?見つけた

答えて

0

、それは簡単だったが、マニュアルに欠けている:

public class AddFileParamTypes : IOperationFilter 
{ 
    public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription) 
    { 
     if (operation.operationId == "FileDelivery_Post") 
     { 

      operation.consumes.Add("multipart/form-data"); 
      operation.parameters.Add(new Parameter 
      { 
       name = "file", 
       required = true, 
       type = "file", 
       @in = "formData" 
      }); 
      operation.parameters.Add(new Parameter 
      { 
       name = "User", 
       required = true, 
       schema = schemaRegistry.GetOrRegister(typeof(User)), 
       @in = "header" 
      }); 
     } 
    } 
} 
関連する問題