2017-06-05 69 views

回答

1

雖然這篇文章已經很老了,但我認爲如果在相同的情況下卡住 會有幫助。

public class AddRequiredHeaderParameter : IOperationFilter 
{ 
    public void Apply(Operation operation, SchemaRegistry schemaRegistry, 
         ApiDescription apiDescription) 
    { 
     if (operation.parameters == null) 
     { 
      operation.parameters = new List<Parameter>(); 
     } 

     /*System.Diagnostics.Trace.WriteLine(apiDescription.RelativePath + 
      "=paath");*/ 
     if (apiDescription.RelativePath.Contains(***{url***})) 
     { 
      operation.parameters.Add(new Parameter 
      { 
       name = "X-User-Token", 
       @in = "header", 
       type = "string", 
       required = false, 
       description="" 
      }); 
      operation.parameters.Add(new Parameter 
      { 
       name = "authorization", 
       @in = "header", 
       description = "Token", 
       type = "string", 
       required = true 
      }); 
     } 
     else 
     { 
      operation.parameters.Add(new Parameter 
      { 
       name = "X-User-Token", 
       @in = "header", 
       type = "string", 
       required = false, 
       description="description" 
      }); 
     } 
    } 
} 
相關問題