Azure / azure-functions-openapi-extension

This extension provides an Azure Functions app with Open API capability for better discoverability to consuming parties
https://www.nuget.org/packages/Microsoft.Azure.WebJobs.Extensions.OpenApi/
MIT License
374 stars 195 forks source link

How to add title to requestBody and responses in generated OpenApi? #452

Open macux opened 2 years ago

macux commented 2 years ago

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<IActionResult> 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):

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

justinyoo commented 2 years ago

@macux Thanks for addressing this issue. The `title attribute is not supported yet.