OpenApi OpenApiResponseWithBody throws error when using typeof

Viewed 419

I have the following OpenApi annotations for my azure function:

        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)
        { }

In [OpenApiResponseWithBody] if I use typeof with the Model that is in the project itself, swagger UI shows up without any issues. But when I use a different model which is imported at the top using the using statement using Hl7.Fhir.Model, the app just crashes. Any ideas why that is happening? Any help would be appreciated.

There are no exception details, the app simply crashes.

1 Answers

I am following this Document.

I am adding Hl7.Fhir.STU3 & Hl7.Fhir.R4 packages in azure function and am using FHIR version STU3 and R4 simultaneously. So adding aliases of STU3 & R4 packages. So that we can differentiate which package can use Patient.

Eg: STU3 using Patient as well as R4 using 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>

enter image description here

I am able to run and get the information of azure function enter image description here

Related