2017-05-04 1 views
1

내 응용 프로그램에서 [Swashbuckle] [1]을 통해 멋진 도구를 구현하려했지만 내 끝내주는 UI가 전혀 없었으며 내 문서에서이 값을 반환합니다.API 2.0 및 Odata 3.0을 사용하는 Swagger 2.0

내 webApiConfig에서
{ 
"swagger": "2.0", 
    "info": { 
    "version": "v1", 
    "title": "NB.EAM.WebAPI.V4" 
    }, 
    "host": "localhost:24320", 
    "schemes": [ 
    "http" 
    ], 
    "paths": {}, 
    "definitions": {} 
} 

내가는 dummys에게

var에 swagConfig = 새로운 HttpSelfHostConfiguration ("http://localhost:24320")를 다음에서 다음 구성을 설정;

GlobalConfiguration.Configuration 
.EnableSwagger(c => 
{      
    c.SingleApiVersion("v1", "NB.EAM.WebAPI.Odata"); 

    var baseDirectory = AppDomain.CurrentDomain.BaseDirectory; 
    var commentsFileName = Assembly.GetExecutingAssembly().GetName().Name + ".XML"; 
    var commentsFile = Path.Combine(baseDirectory, "bin", commentsFileName); 
    c.IncludeXmlComments(commentsFile); 

    c.DocumentFilter<ApplyResourceDocumentation>(); 

    c.CustomProvider(defaultProvider => new ODataSwaggerProvider(defaultProvider, c, GlobalConfiguration.Configuration).Configure(odataConfig => 
    { 

     odataConfig.IncludeNavigationProperties(); 
    })); 
}) 
.EnableSwaggerUi(c => 
{       
}); 

어떤 생각이 내가 누락 될 수 있습니다 :

SwaggerConfig.Register(); 
WebApiConfig.Register(swagConfig); 

using (var server = new HttpSelfHostServer(swagConfig)) 
{ 
    server.OpenAsync().Wait(); 
} 

내 자신감 구성 Swashbuckle에 의해 생성 된 STANDART 하나?

편집 : 여기 내이

설정에 대한 자세한 정보입니다 내 WebApiConfig의

전체 코드 :

public static void Register(HttpConfiguration config) 

     GlobalConfiguration.Configuration.MessageHandlers.Insert(0, new ServerCompressionHandler(new GZipCompressor(), new DeflateCompressor())); 
     GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore; 

     var conventions = ODataRoutingConventions.CreateDefault(); 
     conventions.Insert(0, new CompositeKeyRoutingConvention()); 
     conventions.Insert(1, new CompositeKeyNavigationRoutingConvention()); 

     conventions.Insert(2, new CountODataRoutingConvention()); 

     ODataBatchHandler batchHandler = new UnitOfWorkBatchHandler(GlobalConfiguration.DefaultServer); 

     config.Routes.MapODataServiceRoute("odata", "odata", GenerateEdmModel(), new CountODataPathHandler(), conventions, batchHandler); 

     config.Filters.Add(new SqlExceptionFilterAttribute()); 
     config.Filters.Add(new FilterInterceptor()); 

     InitContentRepository(); 

     log4net.Config.XmlConfigurator.Configure(); 

     var swagConfig = new HttpSelfHostConfiguration("http://localhost:24320"); 

     SwaggerConfig.Register(); 
     WebApiConfig.Register(swagConfig); 

     using (var server = new HttpSelfHostServer(swagConfig)) 
     { 
      server.OpenAsync().Wait(); 
     } 
    } 

public static Microsoft.Data.Edm.IEdmModel GenerateEdmModel() 
    { 
     ODataModelBuilder builder = new ODataConventionModelBuilder(); 
     builder.ContainerName = "NBContext"; 

     builder.EntitySet<as_portfolio>("as_portfolio"); 
     builder.EntitySet<cf_usersportfolio>("cf_usersportfolio"); 
     builder.EntitySet<as_locatportfolio>("as_locatportfolio"); 
     builder.EntitySet<ac_bdgaset>("ac_bdgaset"); 
     builder.EntitySet<ac_bdgcc>("ac_bdgcc"); 
     builder.EntitySet<ac_bdgdtl>("ac_bdgdtl"); 
     builder.EntitySet<ac_bdgloca>("ac_bdgloca"); 
     builder.EntitySet<ac_bdgress>("ac_bdgress"); 
     builder.EntitySet<ac_bdgsect>("ac_bdgsect"); 
     builder.EntitySet<ac_bdgwoa>("ac_bdgwoa"); 
     builder.EntitySet<ac_bdgwob>("ac_bdgwob"); 
     builder.EntitySet<ac_bdgwolb>("ac_bdgwolb"); 
     builder.EntitySet<ac_bdgwost>("ac_bdgwost"); 
     builder.EntitySet<ac_bgdcc>("ac_bgdcc"); 
     builder.EntitySet<ac_custome>("ac_custome"); 
     ----Very long list of enetitySets 
     return builder.GetEdmModel(); 

} 

내 API의 예

using NB.EAM.DataV2; 
using System.Linq; 
using System.Net; 
using System.Web.Http; 
using System.Web.Http.ModelBinding; 
using System.Web.Http.OData; 

namespace NB.EAM.WebAPI.Controllers 
{ 
public class wo_hrtypeController : BaseODataController 
{ 
    // GET: odata/wo_hrtype 

    [Queryable] 
    public IQueryable<wo_hrtype> Getwo_hrtype() 
    { 
     return this.GetWo_HrtypeBll.GetAll(); 
    } 

    // GET: odata/wo_hrtype(5) 
    [Queryable] 
    public SingleResult<wo_hrtype> Getwo_hrtype([FromODataUri] string key) 
    { 
     return SingleResult.Create(this.GetWo_HrtypeBll.Find(wo_hrtype => 
     wo_hrtype.lb_tyhr == key)); 
    } 
} 

답변

0

작동 할 많은 정보가 없습니다 그곳에.

우리는 ApplyResourceDocumentation에 aplied되는 필터의 종류를 모른다는 (실제로는,이 클래스는 swashbuckle.odata 샘플 proyect에 당신의 necesities 맞지 않을 수 있습니다 https://github.com/rbeauchamp/Swashbuckle.OData/blob/master/Swashbuckle.OData.Sample/DocumentFilters/ApplyResourceDocumentation.cs을).

엔티티와 함수 정의도 확인할 수 없습니다. 예를 들어 이것을 확인하십시오 : https://github.com/rbeauchamp/Swashbuckle.OData/blob/master/Swashbuckle.OData.Sample/App_Start/ODataConfig.cs

그리고 우리는 컨트롤러가 적절한 방법으로 정의되어 있는지 확인할 수 없습니다. (동사로 메서드를 사용합니다. 사용자 지정 명명 된 메서드는 함수로 정의 된 경우에만 고려됩니다)

+0

답변을 주셔서 감사합니다. 필터를 사용해 보았지만 찾고자하는 것이 아닙니다. 제 질문에 대한 정보를 추가했습니다. – Seiferos

+0

나는 메소드의 이름 때문에 표준 이름 (그냥 Get, Put, Patch, Post ...)을 사용해 볼 수 있다고 생각한다. 다른 이름은 edm에 정의 된 액션/함수로만 작동한다고 생각합니다. 그래도 작동하지 않으면 ODataRoutePreffix와 결합되었거나 결합되지 않은 메서드에서 ODataRoute 특성을 사용해 볼 수 있습니다. – Cibergarri

+0

[HttpGet] 특성을 사용하여 메서드를 호출하는 데 사용되는 동사를 나타내야합니다. – Cibergarri