我正在尝试记录用.NET Core API
开发的API。
这是Swagger UI中的结果视图。
这是将Swagger.json
导入PostMan时的结果视图。
如您所见,它们没有分组到FueLogs
集合中。
这是我在Startup.cs中配置Swagger Doc的方式
// Swagger API Explorer - You can browse and test the API: /swagger/ui/index.html
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new Info
{
Version = "v1",
Title = "API",
Description = "Documentation for API",
Contact = new Contact { Name = "Dawood Awan", Email = "m.dawood@gmail.com" },
});
c.DocInclusionPredicate((_, api) => !string.IsNullOrWhiteSpace(api.GroupName));
c.TagActionsBy(api => api.GroupName);
// Set the comments path for the Swagger JSON and UI.
var xmlFile = $"xPT.MyProj.xml";
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
c.IncludeXmlComments(xmlPath);
c.EnableAnnotations();
});
这就是我记录API控制器的方式。
[Authorize]
[Route("/api/[controller]")]
[ApiExplorerSettings(GroupName = "FuelLogs")]
public class FuelLogsController : BaseController
{
/// <summary>
/// Get fuel log details
/// </summary>
/// <param name="companyId">The company ID of the asset.</param>
/// <param name="fuelLogId">The fuel Log ID.</param>
/// <returns>Fuel log details</returns>
/// <response code="200">The fuel log details `FuelLogDTO`</response>
/// <response code="400">If an error occurs.</response>
/// <response code="401">If user doesn't have permission to perform the action.</response>
/// <response code="403">If the user doesn't have access to this resource.</response>
[SwaggerOperation(OperationId = "GetFuelLog")]
[ProducesResponseType(typeof(FuelLogDTO), 200)]
[HttpGet("{companyId}/{fuelLogId}")]
[Authorize(Policy = "View Fuel Logs")]
public async Task<IActionResult> Get(int companyId, int fuelLogId)
我在做什么错?如何导入到Postman,将每个控制器分组到一个Collection中?
Swagger.json
{"swagger":"2.0","info":{"version":"v1","title":"API","description":"Documentation for API","contact":{"name":"Dawood Awan","email":"m.dawood@gmail.com"}},"paths":{"/api/FuelLogs/{companyId}/{fuelLogId}":{"get":{"tags":["FuelLogs"],"summary":"Get fuel log details","operationId":"GetFuelLog","consumes":[],"produces":["text/plain","application/json","text/json"],"parameters":[{"name":"companyId","in":"path","description":"The company ID of the asset.","required":true,"type":"integer","format":"int32"},{"name":"fuelLogId","in":"path","description":"The fuel Log ID.","required":true,"type":"integer","format":"int32"}],"responses":{"200":{"description":"The fuel log details `FuelLogDTO`","schema":{"$ref":"#/definitions/FuelLogDTO"}},"400":{"description":"If an error occurs."},"401":{"description":"If user doesn't have permission to perform the action."},"403":{"description":"If the user doesn't have access to this resource."}}},"put":{"tags":["FuelLogs"],"summary":"Update an existing fuel Log","operationId":"UpdateFuelLog","consumes":["application/json-patch+json","application/json","text/json","application/*+json"],"produces":[],"parameters":[{"name":"companyId","in":"path","description":"The company ID.","required":true,"type":"integer","format":"int32"},{"name":"fuelLogId","in":"path","description":"The fuel log ID","required":true,"type":"integer","format":"int32"},{"name":"model","in":"body","description":"The details of the fuel Log","required":false,"schema":{"$ref":"#/definitions/FuelLogDTO"}}],"responses":{"200":{"description":"If update is success"},"400":{"description":"If an error occurs."},"401":{"description":"If user doesn't have permission to perform the action."},"403":{"description":"If the user doesn't have access to this resource."}}},"delete":{"tags":["FuelLogs"],"summary":"Delete an existing fuel Log","operationId":"DeleteFuelLog","consumes":[],"produces":[],"parameters":[{"name":"companyId","in":"path","description":"The company ID.","required":true,"type":"integer","format":"int32"},{"name":"fuelLogId","in":"path","description":"The fuel log ID","required":true,"type":"integer","format":"int32"}],"responses":{"200":{"description":"If delete is a success"},"400":{"description":"If an error occurs."},"401":{"description":"If user doesn't have permission to perform the action."},"403":{"description":"If the user doesn't have access to this resource."}}}},"/api/FuelLogs/fuelTypes":{"get":{"tags":["FuelLogs"],"summary":"Get fuel types supported by the system.","operationId":"GetFuelTypes","consumes":[],"produces":["text/plain","application/json","text/json"],"parameters":[],"responses":{"200":{"description":"List of fuel types supported by the system","schema":{"uniqueItems":false,"type":"array","items":{"$ref":"#/definitions/Dropdown"}}},"400":{"description":"If an error occurs."},"401":{"description":"If user doesn't have permission to perform the action."},"403":{"description":"If the user doesn't have access to this resource."}}}},"/api/FuelLogs/detailedList/{companyId}":{"get":{"tags":["FuelLogs"],"summary":"Get a list fuel log. Will return fuel logs filtered by AssetIds, start and end date.\r\nWill only return the number of fuel logs mentioned in pageSize parameter.","operationId":"GetFuelLogs","consumes":[],"produces":["text/plain","application/json","text/json"],"parameters":[{"name":"companyId","in":"path","description":"The company ID of the asset.","required":true,"type":"integer","format":"int32"},{"name":"PageSize","in":"query","required":false,"type":"integer","format":"int32"},{"name":"PageNumber","in":"query","required":false,"type":"integer","format":"int32"},{"name":"SortDirection","in":"query","required":false,"type":"string"},{"name":"SortBy","in":"query","required":false,"type":"string"},{"name":"TempSortBy","in":"query","required":false,"type":"string"},{"name":"TotalItems","in":"query","required":false,"type":"integer","format":"int32"},{"name":"CompanyId","in":"query","description":"The company ID of the asset.","required":false,"type":"integer","format":"int32"},{"name":"SiteId","in":"query","required":false,"type":"integer","format":"int32"},{"name":"CategoryId","in":"query","required":false,"type":"integer","format":"int32"},{"name":"GeofenceId","in":"query","required":false,"type":"integer","format":"int32"},{"name":"AssetId","in":"query","required":false,"type":"integer","format":"int32"},{"name":"DriverId","in":"query","required":false,"type":"integer","format":"int32"},{"name":"ReportId","in":"query","required":false,"type":"integer","format":"int32"},{"name":"AssetIds","in":"query","required":false,"type":"array","items":{"type":"integer","format":"int32"},"collectionFormat":"multi","uniqueItems":false},{"name":"StartDate","in":"query","required":false,"type":"string","format":"date-time"},{"name":"EndDate","in":"query","required":false,"type":"string","format":"date-time"},{"name":"FilterDate","in":"query","required":false,"type":"string","format":"date-time"}],"responses":{"200":{"description":"List of fuel log details `FuelLogDTO`","schema":{"$ref":"#/definitions/PaginationResponse[FuelLogDTO]"}},"400":{"description":"If an error occurs."},"401":{"description":"If user doesn't have permission to perform the action."},"403":{"description":"If the user doesn't have access to this resource."}}}},"/api/FuelLogs/{companyId}":{"post":{"tags":["FuelLogs"],"summary":"Create a new fuel Log.","operationId":"GetFuelLogs","consumes":["application/json-patch+json","application/json","text/json","application/*+json"],"produces":["text/plain","application/json","text/json"],"parameters":[{"name":"companyId","in":"path","description":"The company ID.","required":true,"type":"integer","format":"int32"},{"name":"model","in":"body","description":"The details of the fuel Log","required":false,"schema":{"$ref":"#/definitions/FuelLogDTO"}}],"responses":{"200":{"description":"The newly created fuel Log ID","schema":{"format":"int32","type":"integer"}},"400":{"description":"If an error occurs."},"401":{"description":"If user doesn't have permission to perform the action."},"403":{"description":"If the user doesn't have access to this resource."}}}}},"definitions":{"FuelLogDTO":{"type":"object","properties":{"fuelId":{"format":"int32","type":"integer"},"companyId":{"format":"int32","type":"integer"},"assetId":{"format":"int32","type":"integer"},"reference":{"type":"string"},"currencyId":{"format":"int32","type":"integer"},"currencySymbol":{"type":"string"},"fuelType":{"format":"int32","enum":[1,2,3],"type":"integer"},"fuelTypeName":{"type":"string"},"date":{"format":"date-time","type":"string"},"invoiceNumber":{"type":"string"},"odometerReading":{"format":"int32","type":"integer"},"pricePerLiter":{"format":"double","type":"number"},"quantity":{"format":"double","type":"number"},"total":{"format":"double","type":"number"}}},"Dropdown":{"type":"object","properties":{"id":{"format":"int32","type":"integer"},"stringId":{"type":"string"},"name":{"type":"string"}}},"PaginationResponse[FuelLogDTO]":{"type":"object","properties":{"totalItems":{"format":"int32","type":"integer"},"data":{"uniqueItems":false,"type":"array","items":{"$ref":"#/definitions/FuelLogDTO"}}}}},"securityDefinitions":{"Bearer":{"name":"Authorization","in":"header","type":"apiKey","description":"JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\""}},"security":[{"Bearer":[]}],"tags":[]}