我正在将我的.NET核心项目从2.2升级到3.1...
在此基础上,我还更新了Swagger版本,该版本现在基于OpenApi。我从Swagger得到的API的.json模式已经更改了自定义泛型类型的$ref名称。我在很多响应中都使用了这些类型。
我不确定是因为OpenApi规范,还是我没有配置正确的东西。
这是我的控制器方法的一个示例:
/// <summary>
/// Gets recording sets by search settings.
/// </summary>
/// <response code="200">The recording sets were returned correctly.</response>
/// <response code="401">The unauthorized access.</response>
/// <response code="406">The not acceptable format.</response>
/// <response code="415">The unsupported media type.</response>
/// <response code="500">The unexpected error.</response>
/// <param name="recordingSetSearchSettings">The search settings of the recording set.</param>
/// <returns>The found recording sets.</returns>
[HttpGet]
[ProducesResponseType(typeof(IDataPage<RecordingSet>), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)]
[ProducesResponseType(typeof(void), StatusCodes.Status406NotAcceptable)]
[ProducesResponseType(typeof(void), StatusCodes.Status415UnsupportedMediaType)]
[ProducesResponseType(typeof(ApiErrorSummary), StatusCodes.Status500InternalServerError)]
[SwaggerOperation(OperationId = "SearchRecordingSets")]
public IDataPage<RecordingSet> Get([FromQuery(Name = "")] RecordingSetSearchSettings recordingSetSearchSettings)
{
return recordingSetService.Search(recordingSetSearchSettings);
}请注意ProducesResponseType中的IDataPage<RecordingSet>
这是我在.json中的$ref名称过去的样子:IDataPage[RecordingSet] (我想保持这个名称,因为我使用自定义的NSwag .exe为FrontEnd生成客户端方法)
.json中的$ref名称现在看起来是这样的:RecordingSetIDataPage
这是一个配置问题,还是规范改变了,所以我必须实现一些自定义的方法来支持它?
发布于 2020-11-03 17:38:27
我已经在Swashbuckle上找到了相应的答案- https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/1803
约定已经改变,您可以使用旧方法,即定义TypeExtension - FriendlyId并在CustomSchemaIds中使用它
services.AddSwaggerGen(c =>
{
// ... your definitions ...
c.CustomSchemaIds(i => i.FriendlyId());
});https://stackoverflow.com/questions/64646665
复制相似问题