azure-functions-openapi-extension
azure-functions-openapi-extension copied to clipboard
OpenApi Document generated does not include the definition for nested class
Describe the issue OpenApi Document generation is not including the schema definition of the type of Array.
To Reproduce Steps to reproduce the behavior:
- With Visual Studio 2022, Create New Function App with HttpTrigger and OpenAPI template.
- Create a request entity which has basic fields and array fields.
- Add the required OpenAPI declarators to method and entities.
- Run the Function and Access OpenAPI document
Request Class -
[OpenApiExample(typeof(ParametersExample))]
public class FunctionRequest
{
/// <summary>The body contains the array of html content to convert</summary>
[OpenApiPropertyDescription("The body contains the array of html content to convert")]
public List<Body> body { get; set; }
}
[OpenApiExample(typeof(BodyExample))]
public class Body
{
/// <summary>The Content accepts the html string to convert to WML</summary>
[OpenApiPropertyDescription("Content Field accepts string in html format")]
public string Content { get; set; }
}
public class ParametersExample : OpenApiExample<FunctionRequest>
{
public override IOpenApiExample<FunctionRequest> Build(NamingStrategy namingStrategy = null)
{
Body bodyExample = new Body();
bodyExample.Content = "<html><body><p>This is a test</p></body></html>";
Body bodyExample2 = new Body();
bodyExample2.Content = "<html><body><p>This is a test</p></body></html>";
this.Examples.Add(
OpenApiExampleResolver.Resolve(
"ParametersExample",
new FunctionRequest()
{
body = new List<Body> { bodyExample, bodyExample2 }
},
namingStrategy
));
return this;
}
}
public class BodyExample : OpenApiExample<Body>
{
public override IOpenApiExample<Body> Build(NamingStrategy namingStrategy = null)
{
Body bodyExample = new Body();
bodyExample.Content = "<html><body><p>This is a test</p></body></html>";
this.Examples.Add(
OpenApiExampleResolver.Resolve(
"BodyExample",
new Body()
{
Content = bodyExample.Content
},
namingStrategy
));
return this;
}
}
[OpenApiOperation(operationId: "Run")]
[OpenApiSecurity("function_key", SecuritySchemeType.ApiKey, Name = "code", In = OpenApiSecurityLocationType.Query)]
[OpenApiRequestBody(contentType: "application/json; charset=utf-8", bodyType: typeof(FunctionRequest), Description ="Sample Request",Required =true)]
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json; charset=utf-8", bodyType: typeof(FunctionResponse), Description = "The OK response")]
public async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req)
{
Expected behavior
Schemas should have body and convertedPayload "components": { "schemas": { "functionRequest": { "type": "object", "properties": { "body": { "type": "array", "items": { "$ref": "#/components/schemas/body" }, "description": "The body contains the array of html content to convert" } }, "example": "{"body":[{"content":"
This is a test
"},{"content":"This is a test
"}]}" }, "functionResponse": { "type": "object", "properties": { "convertedPayload": { "type": "array", "items": { "$ref": "#/components/schemas/convertedPayload" } }, "errorCode": { "type": "string" }, "errorDescription": { "type": "string" } } } },Environment (please complete the following information, if applicable):
- Microsoft Visual Studio Community 2022 (64-bit) - Current
- Version 17.1.2

Additional context It would be a great to add an example using nested class example.
I was wondering if the same is case with inherited classes. I am inheriting a child class from base and using the typeof(childclass) in OpenApiRequestBody but getting empty object in swagger ui
I have not tested this with inherited classes but might be a related issue @rdhaundiyal . Looking forward to hear from the team.
I'm curious on this item as well.