Azure / Azure/azure-functions-openapi-extension
How to add title to requestBody and responses in generated OpenApi?
- Dominant language
- C#
- Stars
- 388
- Forks
- 202
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the issue**
I want to set the title of a requestBody and for responses in my OpenApi yaml but can't see a way to do this. Showing an example just for requestBody below.
**To Reproduce**
Steps to reproduce the behavior:
Add an `OpenApiRequestBody` attribute to a POST Azure function, e.g.:
```
[FunctionName("MyFunction")]
[OpenApiOperation(operationId: "my-operation-id")]
[OpenApiRequestBody(
contentType: "application/json",
bodyType: typeof(MyFunctionInputModel))]
[OpenApiResponseWithBody(
statusCode: HttpStatusCode.OK,
contentType: "application/json",
bodyType: typeof(MyFunctionResponseDto))]
public async Task Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "my-path")] MyFunctionInputModel inputModel)
{
...
}
```
**Expected behavior**
That the above generates a spec something like:
```
...
paths:
/my-path:
post:
summary: my-operation-id
operationId: my-operation-id
requestBody:
content:
application/json:
schema:
type: object
title: MyFunctionInputModel
properties:
someProperty:
type: string
someOtherProperty:
type: boolean
...
```
Instead the above is generated without:
```
title: MyFunctionInputModel
```
**Environment (please complete the following information, if applicable):**
- OS: Windows 10 locally (also generating spec on a win-2019 DevOps build agent
- Browser: Chrome locally (running functions using Azure Function core tools v3 in DevOps followed by a curl request to generate the OpenApi)
- Version: Microsoft.Azure.WebJobs.Extensions.OpenApi v1.2 (in process model)
**Additional context**
I'm using the generated spec in a client code generator and this code generator needs the title in order to name generated classes correctly.
Am I correct in thinking this should be done
Contributor guide
Research direction
Start by tracing how the v1.2 extension handles the OpenApiRequestBody and OpenApiResponseWithBody attributes when generating schemas. Compare the generated requestBody and response schemas with the expected OpenAPI YAML, and confirm that titles are emitted for both before checking the client generator output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure, csharp, openapi
- Domain
- api
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100