2015-12-30 11 views
6

मेरे पास एक वेब एपीआई 2 प्रोजेक्ट है। यह ओविन का उपयोग करके स्वयं होस्ट करने के लिए कॉन्फ़िगर किया गया है। इसमें कोई वैश्विक.एक्सएक्स फ़ाइल नहीं है। मुझे वेब एपीआई के लिए सहायता पृष्ठ की आवश्यकता है, और इसके लिए swaschbuckle का उपयोग किया है। लेकिन rooturl/swagger/docs कोई आउटपुट नहीं दे रहा है। मैंने यहां दिए गए निर्देशों का पालन किया है 'https://github.com/domaindrivendev/Swashbuckle/issues/196', लेकिन यह अभी भी काम नहीं कर रहा है। नीचे मेरा कॉन्फ़िगरेशन कोडस्वाशबकल स्वेगर काम नहीं कर रहा है

 
public void Configuration(IAppBuilder app) 
     { 
      // Configure DI 
      container = BuildDI(); 

      // Create the configuration. OWIN Should create a new httpconfiguration. 
      // GlobalConfiguration can't be used. 
      HttpConfiguration = new HttpConfiguration(); 

      HttpConfiguration.Formatters.XmlFormatter.UseXmlSerializer = true; 
      HttpConfiguration.MapHttpAttributeRoutes(); 
      HttpConfiguration.DependencyResolver = new AutofacWebApiDependencyResolver(container); 
      // Set ServicePointManager properties. 
      ServicePointManager.ServerCertificateValidationCallback = ((sender, cert, chain, sslPolicyErrors) => true); 
      // 10 concurrent connections can be made on the service point. 
      ServicePointManager.DefaultConnectionLimit = 10; 
      // After the idle time expires, the ServicePoint object is eligible for 
      // garbage collection and cannot be used by the ServicePointManager object. 
      ServicePointManager.MaxServicePointIdleTime = 30000; // 30 Seconds. 

      app.UseSerilogRequestContext("RequestId"); 
      // Middleware is injected form DI. 
      app.UseAutofacMiddleware(container); 

      app.UseAutofacWebApi(HttpConfiguration); 

      //Enable swashbuckle 
      SwaggerConfig.Register(HttpConfiguration); 

      // Webapi middleware. Do it at the end. 
      app.UseWebApi(HttpConfiguration); 

      // Register callback to dispose container. 
      RegisterShutdownCallback(app, container); 
     } 

--------------------------------------------------------------- 
public class SwaggerConfig 
     { 
      public static void Register(HttpConfiguration config) 
      { 
       config.EnableSwagger(c => 
       { 
        c.RootUrl(rurl => ConfigurationManager.AppSettings["hostUrl"].ToString()); 
        c.IncludeXmlComments(GetXmlCommentsFileLocation()); 
        c.SingleApiVersion("v1", "Isone"); 
       }) 
       .EnableSwaggerUi(c => 
       { 
       }); 
      } 

      private static string GetXmlCommentsFileLocation() 
      { 
       var baseDirectory = AppDomain.CurrentDomain.BaseDirectory + "\\bin"; 
       var commentsFileName = Assembly.GetExecutingAssembly().GetName().Name + ".XML"; 
       var commentsFileLocation = Path.Combine(baseDirectory, commentsFileName); 
       return commentsFileLocation; 
      } 
     } 
-------------------------------------------------------------- 

कोड में कोई भी गलती बताएं।

उत्तर

1

चरण निम्न प्रकार से किया जाना चाहिए:

1) जोड़ें "Swashbuckle.Core" एक NuGet निर्भरता (केवल कोर पैकेज Owin साथ आवश्यक है)

package.json रूप

<packages>  
    <package id="Swashbuckle.Core" version="5.5.3" targetFramework="net462" /> 
    ... 
</packages> 

2) के भीतर आप स्टार्टअप वर्ग रजिस्टर अकड़

Startup.cs

public partial class Startup 
{ 
    /// <summary> 
    ///  Used to create an instance of the Web application 
    /// </summary> 
    /// <param name="app">Parameter supplied by OWIN implementation which our configuration is connected to</param> 
    public void Configuration(IAppBuilder app) 
    { 
     // Wire-in the authentication middleware 
     ConfigureAuth(app); 

     // In OWIN you create your own HttpConfiguration rather than re-using the GlobalConfiguration. 
     HttpConfiguration config = new HttpConfiguration(); 

     // Handle registration of Swagger API docs 
     SwaggerConfig.Register(config); 

     // Handles registration of the Web API's routes 
     WebApiConfig.Register(config); 

     // Register web api 
     app.UseWebApi(config); 
    } 

SwaggerConfig.cs

public class SwaggerConfig 
{ 
    public static void Register(HttpConfiguration config) 
    { 
     config 
      .EnableSwagger(c => 
      { 
       c.IncludeXmlComments(GetXmlCommentsPath()); 
      }) 
      .EnableSwaggerUi(c => 
      { 
       c.EnableApiKeySupport("Authorization", "header"); 
      }); 
    } 

    private static string GetXmlCommentsPath() 
    { 
     return [email protected]"{AppDomain.CurrentDomain.BaseDirectory}\bin\Example.XML"; 
    } 
} 

3) अपने निर्माण गुण

Build Properties

में XML प्रलेखन आउटपुट सक्षम

4) स्वैगर यूआई हो जाएगा swagger/ui/अनुक्रमणिका

पर परोसा गया

enter image description here

संबंधित मुद्दे