2017-12-30 16 views
0

My AspNet 5 WebApi 프로젝트에 Swashbuckle 5.6.0 (현재 최신 버전)을 설치했습니다. 나는 UI가 나타나기는 힘들지 만, 내 API 방법 중 아무 것도 나열되지 않습니다.Swagger에서 내 owin api 컨트롤러를 나열하는 방법

나는 영원히 성공하지 못하고 무언가를 망쳤다. 그런 다음 깨끗한 출발을했다. 작동중인 API에서 Swashbuckle을 설치하고 관련성을 높이기 위해 왼쪽으로 두었습니다.

API는 Express가 아니라 IIS에서 호스팅됩니다. 그것은 밖으로 시도합니다.

어떻게 디버깅합니까? 또는 더 나은 것은, 누구든지 내가 뭘 잘못하고 있는지 알 수 있습니까?

아래 코드는; stackoverflow를 만족시키기 위해 가독성을 위해 빈 줄을 제거해야했습니다.

시작

public class Startup 
{ 
    public void Configuration(IAppBuilder app) 
    { 
     JwtSecurityTokenHandler.InboundClaimTypeMap = new Dictionary<string, string>(); 
     app.UseIdentityServerBearerTokenAuthentication(
      new IdentityServerBearerTokenAuthenticationOptions 
      { 
       Authority = ConfigurationManager.AppSettings["IdentityServerApplicationUrl"], 
       RequiredScopes = new[] {"gallerymanagement"} 
      }); 
     var config = WebApiConfig.Register(); 
     app.UseWebApi(config); 
    } 
} 

WebApiConfig 당신은 초기화 swashbuckle를 그리워

[EnableCors("*", "*", "GET, POST, DELETE")] 
public class EventsController : ApiController 
{ 
    [Route("api/Events/{sub}")] 
    public async Task<IHttpActionResult> GetSingleEvent(string sub) 
    { 
    } 

    [Route("api/Events/")] 
    public async Task<IHttpActionResult> Get() 
    { 
    } 
} 
+0

swashbuckler 유닛이 누락되었습니다. https://github.com/domaindrivendev/Swashbuckle ... add를 참조하십시오. config. .EnableSwagger (c => c.SingleApiVersion ("v1", "API 제목")) .EnableSwaggerUi(); WebApiConfig. 서식을 지정하기 위해 태블릿에서 온라인 상태입니다. – DotNetDev

답변

0

public static class WebApiConfig 
{ 
    public static HttpConfiguration Register() 
    { 
     var config = new HttpConfiguration(); 
     // Web API routes 
     config.MapHttpAttributeRoutes(); 
     config.Routes.MapHttpRoute(
      name: "DefaultRouting", 
      routeTemplate: "api/{controller}/{id}", 
      defaults: new { id = RouteParameter.Optional } 
     ); 
     config.EnableCors(); 
     // clear the supported mediatypes of the xml formatter 
     config.Formatters.XmlFormatter.SupportedMediaTypes.Clear(); 
     config.Formatters.JsonFormatter.SupportedMediaTypes.Add(
      new MediaTypeHeaderValue("application/json-patch+json")); 
     var json = config.Formatters.JsonFormatter; 
     json.SerializerSettings.Formatting = Newtonsoft.Json.Formatting.Indented; 
     json.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); 
     return config; 
    } 
} 

EventsController. https://github.com/domaindrivendev/Swashbuckle를 참조 , 당신은 WebApiConfig에

config 
.EnableSwagger(c => c.SingleApiVersion("v1", "A title for your API")) 
.EnableSwaggerUi(); 

을 추가해야합니다.

관련 문제