2016-11-09 5 views
3

私はSwashbucklまたはSwaggerの新機能ですが、クライアントからSwaggerを使用してドキュメントを作成する必要があるWeb APIを作成しました。私は既に作成しましたが、APIバージョンの詳細をSwageer UIに表示する必要がありますが、これはどのように達成するかわかりません。SwashbuckleにAPIの説明を追加するにはどうすればよいですか?

public class SwaggerConfig 
{ 
    public static void Register() 
    { 
     var thisAssembly = typeof(SwaggerConfig).Assembly; 

     GlobalConfiguration.Configuration 
      .EnableSwagger(c => 
       { 
        c.SingleApiVersion("v1", "Demo Api"); 
        c.IncludeXmlComments(string.Format(@"{0}\bin\WebApi.XML", 
             System.AppDomain.CurrentDomain.BaseDirectory)); 
       }) 
     .EnableSwaggerUi(); 

    } 
} 

コントローラ例:

は、ここに私のコードです

 /// <summary> 
    /// Get the Next IdKey 
    /// </summary> 
    /// <remarks>Get the Next IdKey from Dettagli Table</remarks> 
    /// <response code="404">Not found</response> 
    /// <response code="500">Internal Server Error</response> 
    [HttpGet] 
    public int GetNextIdDettagli() 
    { 
     try 
     { 
      DettagliRepo repo = new DettagliRepo(); 
      return repo.GetNextIdDettagli(); 
     } 
     catch (Exception ex) 
     { 
      throw (ex); 
     } 
    } 

これは、コントローラのすべてのアクションが行われている方法です。ここで

は私の闊歩UIの出力です:

enter image description here

これは、1,2および3でマークされた私のクライアントからの期待出力されます:

enter image description here

私は理解することができますスクリーンショットから、APIの説明、タイトル、その他の情報が表示されることを望んでいますが、それらを表示する方法はわかりません。私を助けてください、私はその部分をどのように達成するのですか?前もって感謝します。

私は次のコードでFollowing link

から1と2を達成した

更新:

    .EnableSwagger(c => 
    { 
     c.RootUrl(req => GetRootUrlFromAppConfig()); 

     c.Schemes(new[] { "http", "https" }); 

     c.SingleApiVersion("v1", "Swashbuckle.Dummy") 
      .Description("A sample API for testing and prototyping Swashbuckle features") 
      .TermsOfService("Some terms") 
      .Contact(cc => cc 
       .Name("Some contact") 
       .Url("http://tempuri.org/contact") 
       .Email("[email protected]")) 
      .License(lc => lc 
       .Name("Some License") 
       .Url("http://tempuri.org/license")); 
    }); 

しかし、それでもまだ、私はポイント3感謝のために助けが必要。

答えて

4

ドキュメントフィルタを実際に作成し、ドキュメントフィルタを使用してスワッガードキュメント内のタグノードを更新できます。

以下のサンプルドキュメントのフィルタを参照してください:

public class DocumentFilter : IDocumentFilter 
{ 
    /// <summary> 
    /// This method is for applying the filter 
    /// </summary> 
    /// <param name="swaggerDoc">Swagger Document</param> 
    /// <param name="schemaRegistry">Schema Registry</param> 
    /// <param name="apiExplorer">API Explorer</param> 
    public void Apply(SwaggerDocument swaggerDoc, SchemaRegistry schemaRegistry, IApiExplorer apiExplorer) 
    { 
     var methods = swaggerDoc.paths.Select(i => i.Value); 
     List<string> tags = new List<string>(); 
     foreach (var method in methods) 
     { 
      if (method.delete != null) 
      { 
       tags.AddRange(method.delete.tags); 
      } 

      if (method.get != null) 
      { 
       tags.AddRange(method.get.tags); 
      } 

      if (method.put != null) 
      { 
       tags.AddRange(method.put.tags); 
      } 

      if (method.post != null) 
      { 
       tags.AddRange(method.post.tags); 
      } 

      if (method.patch != null) 
      { 
       tags.AddRange(method.patch.tags); 
      }     
     } 

     swaggerDoc.tags = new List<Tag>(); 
     foreach (var tag in tags) 
     { 
      swaggerDoc.tags.Add(new Tag() { name = tag, description = "This is a group of methods for " + tag }); 
     } 
    } 
} 
+0

が、これは私をたくさん助けたありがとうございました。 – barsan

関連する問題