【发布时间】:2020-02-02 00:39:42
【问题描述】:
我正在使用 Swashbuckle.AspNetCore 并开箱即用地获取此架构部分:
我的响应模式看起来是空的,但实际上我返回了子类。如何将它们添加到此部分?
我有这个请求模型:
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Runtime.Serialization;
using Newtonsoft.Json;
using static Assignment_1.AppGlobals;
namespace Assignment_1
{
public class ExecuteMoveRequest: IValidatableObject, ICloneable
{
public int? Move { get; set; }
[Required]
public BoardSymbol AzurePlayerSymbol { get; set; }
[Required]
public BoardSymbol HumanPlayerSymbol { get; set; }
[MinLength(9)]
[MaxLength(9)]
public BoardSymbol[] GameBoard { get; set; }
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
//...
我将它用于我的响应模型:
using System;
using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;
using static Assignment_1.AppGlobals;
namespace Assignment_1
{
public interface ExecuteMoveResponse
{
}
[KnownType(typeof(ValidExecuteMoveResponse))]
public class ValidExecuteMoveResponse: ExecuteMoveRequest, ExecuteMoveResponse
{
public string type { get; set; }
}
[KnownType(typeof(InProgressExecuteMoveResponse))]
public class InProgressExecuteMoveResponse : ValidExecuteMoveResponse
{
}
[KnownType(typeof(WonExecuteMoveResponse))]
public class WonExecuteMoveResponse : ValidExecuteMoveResponse
{
[Required]
public BoardSymbol Winner { get; set; }
[Required]
public int[] WinPositions { get; set; }
}
}
【问题讨论】:
标签: c# asp.net-core swagger swashbuckle