Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An idea for filtering request method #78

Open
Manweill opened this issue Jan 27, 2020 · 3 comments
Open

An idea for filtering request method #78

Manweill opened this issue Jan 27, 2020 · 3 comments

Comments

@Manweill
Copy link
Owner

Manweill commented Jan 27, 2020

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 Manweill changed the title An idea for filtering build methods. that filter requests by simply using app or web pages or other specific clients An idea for filtering request method Jan 27, 2020
@Manweill
Copy link
Owner Author

@fairking

@fairking
Copy link
Collaborator

fairking commented Jan 27, 2020

@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
Copy link
Collaborator

fairking commented Oct 7, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants