Я использую 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; }
}
}