joh*_*hni 5 c# asp.net asp.net-mvc swagger nswag
我有一个 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; }
}
}
Run Code Online (Sandbox Code Playgroud)
#
[HttpPut]
[Route("tenants/{tenant}/collections/{collection}")]
[SwaggerResponse(typeof(JobCollectionDtoV2))]
public async Task<IActionResult> CreateTask(JobCollectionDtoV2 collectionParams)
{
}
Run Code Online (Sandbox Code Playgroud)
#
{
"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"
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
具体来说,我遇到的问题是由于路径声明了两个变量tenant和collection小写,而 DTO 类用大写Tenant和Collection.
我希望找到一种方法来装饰 DTO 类属性,该属性将显式声明参数的名称,例如[JsonProperty("collection")](这个特定的不影响输出 Swagger)。
感谢你的帮助
| 归档时间: |
|
| 查看次数: |
729 次 |
| 最近记录: |