Azure / Azure/azure-functions-openapi-extension
OpenApiResponseWithBody - default response
- Dominant language
- C#
- Stars
- 388
- Forks
- 202
- PR merge metrics
- No merged PRs in 30d
Description
OpenApiResponseWithBody annotation works great. For example:
`[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(StatusModel), Description = "Returns Status of Api")]`
This renders in swagger.json as:
```
"200": {
"description": "Returns Status of Api",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/statusModel"
}
}
}
},
```
I've recently put my API through a security / audit check, and one of the requirements to get an acceptable score is for there to be a `default` response. It needs to render like this:
```
"default": {
"description": "Returns Status of Api",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/statusModel"
}
}
}
},
```
So, we need a way to write "default" to the swagger.json file as an option. One way it could be implemented would be to make an overloaded version of the attribute where the first parameter not required. If it's not specified, it becomes 'default':
`[OpenApiResponseWithBody(contentType: "application/json", bodyType: typeof(StatusModel), Description = "Returns Status of Api")]`
Wondering if there's a way to overload the attribute to support this.
Contributor guide
Research direction
Start by locating the OpenApiResponseWithBody attribute and the code that renders its response into swagger.json. Check how the status code is currently selected, then verify that an omitted status code produces a default response with the requested description, content type, and schema.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, openapi
- Domain
- api
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100