2017-07-19 126 views
2

根據documentation for Swashbuckle,最新版本只支持一些XML註釋。看起來好像XML的評論,如<example><see>目前不支持but will be implemented in Swashbuckle v6在描述中添加鏈接到Swagger中的其他操作(通過Swashbuck)

在那之前,有沒有一種解決方法可以模仿<example><see>的行爲?

我想以某種方式在端點模型下列出的enum的<summary>中添加一個鏈接(使用<see> with cref)以指向枚舉的相應端點(Swagger中的另一個端點,獲取該枚舉類型的列表)。

編輯(不知道如何在註釋格式):

我想揚鞭檢測<see>並顯示在枚舉的描述鏈接到不同的端點

/// <summary> 
/// Generic description. 
/// Find enum types <see cref="ContactEntityType">here</see> 
/// </summary> 
[PropertyRequired, PropertyStringAsEnum(typeof(ContactEntityType))] 
[DataMember(Name = "entityType")] 
public NamedReference EntityType { get; set; } 
+0

我一直對我的叉子Swashbuckle和我們添加了對示例的支持:https://github.com/heldersepu/Swagger-Net/blob/master/Tests/Swagger.Net.Dummy.Core/Controllers/AnnotatedTypesContro ller.cs#L28 – HelderSepu

+0

你可以給我一個完整的樣本,你將如何使用 HelderSepu

+0

我在原始問題 –

回答

0

您可以使用ISchemaFilterIDocumentFilter修改生成的SwaggerDoc。

下面是一些樣本:

private class ApplySchemaVendorExtensions : ISchemaFilter 
    { 
     public void Apply(Schema schema, SchemaRegistry schemaRegistry, Type type) 
     { 
      // Modify the example values in the final SwaggerDocument 
      // 
      if (schema.properties != null) 
      { 
       foreach (var p in schema.properties) 
       { 
        switch (p.Value.format) 
        { 
         case "int32": 
          p.Value.example = 123; 
          break; 
         case "double": 
          p.Value.example = 9858.216; 
          break; 
        } 
       } 
      } 
     } 
    } 

_

private class ApplyDocumentVendorExtensions : IDocumentFilter 
    { 
     public void Apply(SwaggerDocument swaggerDoc, SchemaRegistry schemaRegistry, IApiExplorer apiExplorer) 
     { 
      schemaRegistry.GetOrRegister(typeof(ExtraType)); 
      //schemaRegistry.GetOrRegister(typeof(BigClass)); 

      var paths = new Dictionary<string, PathItem>(swaggerDoc.paths); 
      swaggerDoc.paths.Clear(); 
      foreach (var path in paths) 
      { 
       if (path.Key.Contains("foo")) 
        swaggerDoc.paths.Add(path); 
      } 
     } 
    } 

,並添加一個鏈接只使用錨標記:

/// <summary>Details - testing anchor: <a href="?filter=TestPost">TestPost</a></summary> 
+0

我在這裏有幾個例子: https://github.com/heldersepu/SwashbuckleTest/blob/master/Swagger_Test/App_Start/SwaggerConfig.cs – HelderSepu