【问题标题】:OpenApi OpenApiResponseWithBody throws error when using typeofOpenApi OpenApiResponseWithBody 使用 typeof 时抛出错误
【发布时间】:2021-12-30 16:17:59
【问题描述】:

我的天蓝色函数有以下 OpenApi 注释:

        using Hl7.Fhir.Model;

        [FunctionName("FunctionName")]
        [OpenApiOperation(operationId: "OpId", tags: new[] { "Tag" }, Description = "Description to be filled.")]
        [OpenApiSecurity("function_key", SecuritySchemeType.ApiKey, Name = "code", In = OpenApiSecurityLocationType.Query)]
        [OpenApiRequestBody("text/json", typeof(ProjectModel), Required = true)]
        [ApiExplorerSettings(GroupName = "GpName")]
        [OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, bodyType: typeof(ClassLibraryModel), contentType: "application/json", Description = "The OK response")]

public static async Task<IActionResult> Run(
           [HttpTrigger(AuthorizationLevel.Function, "post", Route = "v1.1/apiendpoint")] HttpRequest req,
           ILogger log)
        { }

[OpenApiResponseWithBody] 中,如果我将typeof 与项目本身中的模型一起使用,则会毫无问题地显示出招摇的用户界面。但是,当我使用在顶部使用 using 语句 using Hl7.Fhir.Model 导入的不同模型时,应用程序就会崩溃。任何想法为什么会这样?任何帮助将不胜感激。

没有异常细节,应用程序只是崩溃了。

【问题讨论】:

  • 您是否尝试过使用application/json 而不是text/json。另外,您的模型中是否有任何循环引用?你能提供你的模型吗?

标签: c# asp.net-core azure-functions swagger-ui openapi


【解决方案1】:

我正在关注这个Document

我在 azure 函数中添加 Hl7.Fhir.STU3Hl7.Fhir.R4 包,并同时使用 FHIR 版本 STU3R4。所以添加 STU3R4 包的别名。这样我们就可以区分哪个包可以使用Patient。

例如:STU3 使用 Patient 以及 R4 使用 Patient

< ItemGroup>
    < PackageReference Include="Hl7.Fhir.STU3" Version="3.0.0" />
    < PackageReference Include="Hl7.Fhir.R4" Version="3.0.0" />
< /ItemGroup>

< Target Name="AddPackageAliases" BeforeTargets="ResolveReferences" Outputs="%(PackageReference.Identity)">
    < ItemGroup>
    < ReferencePath Condition="'%(FileName)'=='Hl7.Fhir.STU3.Core'">
        < Aliases>stu3< /Aliases>
    < /ReferencePath>
    < ReferencePath Condition="'%(FileName)'=='Hl7.Fhir.R4.Core'">
        < Aliases>r4< /Aliases>
    < /ReferencePath>
    < /ItemGroup>
< /Target>

我能够运行并获取 azure 函数的信息

【讨论】:

  • 如果回答对您有帮助,请Accept it as an Answer,以便遇到相同问题的其他人可以找到此解决方案并解决他们的问题。
猜你喜欢
  • 2017-01-18
  • 1970-01-01
  • 2020-06-04
  • 2022-11-03
  • 2015-11-02
  • 2023-03-16
  • 2014-07-31
  • 2011-01-07
  • 1970-01-01
相关资源
最近更新 更多