我有一个asp.net核心项目,该项目使用NSwag作为其Swagger工具。 我遇到的问题如下:
#
namespace SchedulerApi.Entities
{
public class JobCollectionDtoV2
{
[Required]
[FromRoute]
[RegularExpression("^[a-z][a-z0-9]+$")]
[StringLength(maximumLength: 24, MinimumLength = 3)]
public string Collection { get; set; }
[Required]
[FromRoute]
[RegularExpression("^[a-z][a-z0-9]+$")]
[StringLength(maximumLength: 24, MinimumLength = 3)]
public string Tenant { get; set; }
}
}
#
[HttpPut]
[Route("tenants/{tenant}/collections/{collection}")]
[SwaggerResponse(typeof(JobCollectionDtoV2))]
public async Task<IActionResult> CreateTask(JobCollectionDtoV2 collectionParams)
{
}
#
{
"put": {
"tags": [
"JobCollectionsControllerV2"
],
"operationId": "JobCollectionsControllerV2_CreateTask",
"consumes": [
"application/json-patch+json",
"application/json",
"text/json",
"application/*+json"
],
"parameters": [
{
"type": "string",
"name": "Collection",
"in": "path",
"required": true,
"maxLength": 24,
"minLength": 3,
"pattern": "^[a-z][a-z0-9]+$",
"x-nullable": true
},
{
"type": "string",
"name": "Tenant",
"in": "path",
"required": true,
"maxLength": 24,
"minLength": 3,
"pattern": "^[a-z][a-z0-9]+$",
"x-nullable": true
},
{
"name": "CollectionDetails",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/JobCollectionDetails"
},
"x-nullable": false
}
],
"responses": {
"200": {
"x-nullable": true,
"description": "",
"schema": {
"$ref": "#/definitions/JobCollectionDtoV2"
}
}
}
}
}
我遇到的具体问题是由于以下事实引起的:路径以小写形式声明了两个变量tenant
和collection
,而DTO类以大写形式{{1}声明了相应的属性}和Tenant
。
我希望找到一种用显式声明参数名称的属性来修饰DTO类属性的方法,例如Collection
(此特定变量不会影响输出Swagger)。
感谢您的帮助