swagger-axios-codegen icon indicating copy to clipboard operation
swagger-axios-codegen copied to clipboard

An idea for filtering request method

Open Manweill opened this issue 4 years ago • 3 comments

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"
    }

Manweill avatar Jan 27 '20 05:01 Manweill

@fairking

Manweill avatar Jan 27 '20 05:01 Manweill

@Manweill Good idea. So you can filter out the operations which you don't need in your client app. It could be very useful.

fairking avatar Jan 27 '20 12:01 fairking

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.

fairking avatar Oct 07 '20 18:10 fairking