swagger-axios-codegen
swagger-axios-codegen copied to clipboard
An idea for filtering request method
An idea for filtering build methods, that filter requests by simply using app or web pages or other specific clients. In .NET Server like this, add a new attribute
.NET
Controller
[AttrName]
public async Task Post(string url)
{
...
}
SwaggerFilter
public class SwaggerFilterHelper : IOperationFilter
{
public void Apply(OpenApiOperation operation, OperationFilterContext context)
{
var action = context.ApiDescription.ActionDescriptor as ControllerActionDescriptor;
operation.OperationId = action.ActionName;
var attr = context.ApiDescription.CustomAttributes()
.OfType<YourAttrName>()
.FirstOrDefault();
if (attr != null)
{
operation.Extensions.Add("x-tag","YourAttrName");
}
}
Swagger Spec
"/api/abp/api-definition": {
"Post": {
"tags": [
"api-definition"
],
"responses": {
"200": {
"description": "Success",
"content": {
"text/plain": {
"schema": {
"$ref": "#/components/schemas/ApplicationApiDescriptionModel"
}
},
"application/json": {
"schema": {
"$ref": "#/components/schemas/ApplicationApiDescriptionModel"
}
},
"text/json": {
"schema": {
"$ref": "#/components/schemas/ApplicationApiDescriptionModel"
}
}
}
}
}
},
"x-tag":"YourAttrName"
}
@fairking
@Manweill Good idea. So you can filter out the operations which you don't need in your client app. It could be very useful.
The include
option is ok for me. I am not sure if we need to do something extra. I have only one Tag in my API which is the service name.
I know some people might have more tags and they want to filter by them. I think we can think about it if there are really some requests from users.