папка. Исправлено для меня после обновления до ASP.NET Core 2.1
довал нескольким учебникам и заставил это работать на работе, но по какой-то причине я не могу отобразить пользовательский интерфейс, но Swagger Json создан. Последний урок, на который я смотрелВот.
Моя установка выглядит так:
Пакет Nuget: Swashbuckle.AspNetCore(1.0.0)
ConfigureServices
Метод:
services.AddSwaggerGen(options =>
{
options.SwaggerDoc("v1",
new Info
{
Title = "MediatR Example",
Version = "v1",
Description = "Trying out the MediatR library to simplify Request and Response logic.",
TermsOfService = "WTFPL",
Contact = new Contact
{
Email = "",
Name = "",
Url = "https://github.com/CubicleJockey/MediatR-Playground"
}
}
);
var xmlDocFile = Path.Combine(PlatformServices.Default.Application.ApplicationBasePath, @"MediatR-Messages.Api.xml");
options.IncludeXmlComments(xmlDocFile);
options.DescribeAllEnumsAsStrings();
});
Configure
Метод:
app.UseMvcWithDefaultRoute();
// Enable middleware to serve generated Swagger as a JSON endpoint.
app.UseSwagger();
// Enable middleware to serve swagger-ui (HTML, JS, CSS etc.), specifying the Swagger JSON endpoint
app.UseSwaggerUI(config =>
{
config.SwaggerEndpoint("/swagger/v1/swagger.json", "V1 Docs");
});
launchSettings.json
:
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger/",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
Запуск и посещение URL-адреса Swagger JSON создает соответствующий JSON:
{
"swagger":"2.0",
"info":{
"version":"v1",
"title":"MediatR Example",
"description":"Trying out the MediatR library to simplify Request and Response logic.",
"termsOfService":"WTFPL",
"contact":{
"name":"André Davis",
"url":"https://github.com/CubicleJockey/MediatR-Playground",
"email":"[email protected]"
}
},
"basePath":"/",
"paths":{
"/api/Addition":{
"get":{
"tags":[
"Addition"
],
"summary":"Get Methods that takes two numbers and gets the sum.",
"operationId":"ApiAdditionGet",
"consumes":[
],
"produces":[
"text/plain",
"application/json",
"text/json"
],
"parameters":[
{
"name":"left",
"in":"query",
"description":"Left hand side of the equation.",
"required":false,
"type":"integer",
"format":"int32"
},
{
"name":"right",
"in":"query",
"description":"Right hand side of the equation.",
"required":false,
"type":"integer",
"format":"int32"
}
],
"responses":{
"200":{
"description":"Success",
"schema":{
"$ref":"#/definitions/Task[AdditionResponse]"
}
}
}
}
}
},
"definitions":{
"Task[AdditionResponse]":{
"type":"object",
"properties":{
"result":{
"$ref":"#/definitions/AdditionResponse",
"readOnly":true
},
"id":{
"format":"int32",
"type":"integer",
"readOnly":true
},
"exception":{
"type":"object",
"readOnly":true
},
"status":{
"enum":[
"Created",
"WaitingForActivation",
"WaitingToRun",
"Running",
"WaitingForChildrenToComplete",
"RanToCompletion",
"Canceled",
"Faulted"
],
"type":"string",
"readOnly":true
},
"isCanceled":{
"type":"boolean",
"readOnly":true
},
"isCompleted":{
"type":"boolean",
"readOnly":true
},
"isCompletedSuccessfully":{
"type":"boolean",
"readOnly":true
},
"creationOptions":{
"enum":[
"None",
"PreferFairness",
"LongRunning",
"AttachedToParent",
"DenyChildAttach",
"HideScheduler",
"RunContinuationsAsynchronously"
],
"type":"string",
"readOnly":true
},
"asyncState":{
"type":"object",
"readOnly":true
},
"isFaulted":{
"type":"boolean",
"readOnly":true
}
}
},
"AdditionResponse":{
"type":"object",
"properties":{
"answer":{
"format":"int32",
"type":"integer",
"readOnly":true
},
"equation":{
"type":"string",
"readOnly":true
}
}
}
},
"securityDefinitions":{
}
}
При посещении стандартного URL Swagger UI я получаю 404. Пробовал несколько вариантов.
локальный: 64881 / чванство /локальный: 64881 / чванство / щлокальный: 64881 / чванство / index.htmlлокальный: 64881 / чванство / щ / index.htmlВсе вышеперечисленное возвращает 404. Они работали раньше, в зависимости от версии. Чего мне не хватает
Мой полный исходный код можно найти на GitHubВот, Это ветвь для этого вопроса, поэтому код соответствует моему запросу.