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

PreSerialize filter for filtering of swagger JSON per operation tags by query params #92

Closed
wants to merge 2 commits into from

Conversation

duki994
Copy link

@duki994 duki994 commented Apr 24, 2019

PreSerialize filter to be filtering swagger document per operation tags

If you ever build large microservices and have multiple swaggers distributed throughout services, you may want to filter multiple swagger documents by tags.

For example both if several services serve single business domain, and concrete requirements are to aggregate swagger documents from mutiple services and show them to end user grouped as a single swagger, this filter becomes very usable.

I used this in 4 projects already. I send /swagger.json?tags=param1%2Cparam2 etc. and Swashbuckle returns me only those that have these respective tags.

Then I used a single aggregator service to create new swagger json (not connected to Swashbuckle or any other swagger generating library or service).

Dusan Knezevic added 2 commits April 24, 2019 14:42
Useful for querying operations by tags
@mattfrear
Copy link
Owner

Hi Dusan

Thanks for the PR. Could you also update the Readme with instructions on how to install it and how to use it (and what it does - I have no idea about tags in Swagger - how do you add a tag to a swagger doc? Is it via Swashbuckle?)

This would be the first filter in the package which wasn't written by me.

@duki994
Copy link
Author

duki994 commented May 4, 2019

@mattfrear

Yes. You can add tag by using Swashbuckle Annotations with SwaggerOperation attribute.

Tags are defined in OpenAPI specifications
https://swagger.io/docs/specification/2-0/grouping-operations-with-tags/

Swagger UI uses tags to group operations. Swashbuckle by default uses controller name as tag for all actions in that controller.
Simply said all actions in UserController will have User tag and be grouped under it in Swagger UI.

This filter allows retrieving only swagger operations included in query parameter search param.

I will add documentation and How To use section :)


private static string[] GetQueryParamsByKey(HttpRequest req, string key, char separator)
{
return req.Query[key].ToString().Split(separator);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This always assumes that queryparams are provided in the syntax of key=value1,value2 however, it is also legitimate to provide a query string syntax of key=value1&key=value2.

Should the syntax you are proposing for the query string be required?

  • In the case that the currently coded, you need to split the values, resulting in an array of strings.
  • In the alternate case, the req.Query[key] returns the same expected outcome. Resulting in an array of strings.

image

@mattfrear
Copy link
Owner

Closing this as it is 3 years old.

@mattfrear mattfrear closed this May 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants