Azure / Azure/azure-functions-openapi-extension
OpenApi Document generated does not include the definition for nested class
- Dominant language
- C#
- Stars
- 388
- Forks
- 202
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the issue**
OpenApi Document generation is not including the schema definition of the type of Array.
**To Reproduce**
Steps to reproduce the behavior:
1. With Visual Studio 2022, Create New Function App with HttpTrigger and OpenAPI template.
2. Create a request entity which has basic fields and array fields.
3. Add the required OpenAPI declarators to method and entities.
4. Run the Function and Access OpenAPI document
Request Class -
```
[OpenApiExample(typeof(ParametersExample))]
public class FunctionRequest
{
/// The body contains the array of html content to convert
[OpenApiPropertyDescription("The body contains the array of html content to convert")]
public List body { get; set; }
}
[OpenApiExample(typeof(BodyExample))]
public class Body
{
/// The Content accepts the html string to convert to WML
[OpenApiPropertyDescription("Content Field accepts string in html format")]
public string Content { get; set; }
}
public class ParametersExample : OpenApiExample
{
public override IOpenApiExample Build(NamingStrategy namingStrategy = null)
{
Body bodyExample = new Body();
bodyExample.Content = "
This is a test
";Body bodyExample2 = new Body();
bodyExample2.Content = "
This is a test
";this.Examples.Add(
OpenApiExampleResolver.Resolve(
"ParametersExample",
new FunctionRequest()
{
body = new List { bodyExample, bodyExample2 }
},
namingStrategy
));
return this;
}
}
public class BodyExample : OpenApiExample
{
public override IOpenApiExample Build(NamingStrategy namingStrategy = null)
{
Body bodyExample = new Body();
bodyExample.Content = "
This is a test
";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 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.
Contributor guide
Research direction
Reproduce the issue with the Visual Studio 2022 Azure Functions OpenAPI template, using the shown FunctionRequest with List and the corresponding response type. Start by tracing OpenAPI document generation for array item types; done means the generated components.schemas includes definitions for body and convertedPayload referenced by the array properties.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure, csharp, openapi
- Domain
- api, backend-api-design
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100