Wednesday, 3 February 2016

Ignoring parameters in Swashbuckle

I’m working with a WebApi that is passed the HttpRequestMessage class which is always available in the ASP.NET WebApi pipeline. However, when the documentation is exposed in Swashbuckle, I get a textbox that shows up where it expects me to enter a value for this parameter.

The operation is defined as follows…

  public async Task Get(HttpRequestMessage request)

The problem is, when the documentation is emitted I end up with this ugly mess...

image

I set about finding a way to instruct Seashbuckle to ignore this parameter, and finding there isn’t anything in the box I set about writing a filter that would do this for me.

In Swashbuckle you can plug-in operation “filters” that can be used to alter the emitted data – the filter is passed the context of the operation being emitted, and you can monkey around with the data that pops out. All I had to do then was create a filter that would look for this datatype, and remove the corresponding data from the results. I ended up with this…

  public class IgnoreHttpRequestMessageOperationFilter : IOperationFilter
  {
    public void Apply(Operation operation, SchemaRegistry schemaRegistry, 
                      ApiDescription apiDescription)
    {
      apiDescription.ParameterDescriptions
        .Where(desc => desc.ParameterDescriptor.ParameterType 
            == typeof(HttpRequestMessage))
        .ToList()
        .ForEach(param =>
        {
          var toRemove = operation.parameters
            .SingleOrDefault(p => p.name == param.Name);

          if (null != toRemove)
            operation.parameters.Remove(toRemove);
        });
    }
  }

With that class in place, I just needed to plug this in to the swagger config file as follows...

  c.OperationFilter();

And Bob's you're uncle...

image

82 comments:

Unknown said...

Cool! thanks for pointing this out! On stackowerflow they suggest to rewrite controllers not to use request as a parameter, which is not suitable for us.

Brave Technologies said...
This comment has been removed by a blog administrator.
Akshay Bheda said...

I was searching solution for the same problem, Thanks to you :)

ZeroTolerance said...

Good job mate. Exactly what I was looking for

Harry said...

Worked like charm. Thank you.

Tarek Mohamed El-Mallah said...
This comment has been removed by the author.
Tarek Mohamed El-Mallah said...
This comment has been removed by the author.
Prachetan Anubhuti - Pragna Prachetas said...

works like a magic ... thanks a ton

Richard Majece said...

I have a huge amount of applications in my phone so I was scared when I lost it. https://cellspyapps.org/track-phone-number/ helped me to track my phone number and find it)

HomeWorkFor.me said...

Be sure to check out the new persuasive essay topics.

Unknown said...

Blog Commenting: An unmatched and nonpareil post i have ever seen. The content is so appealing that it has created an impulse to avail Assignment Help Singapore services.

Praylin S said...

Remarkable post! That's a lot of information. Thanks for taking your time and effort to share this with us. Keep us updated.
Tally Course in Chennai
Tally Classes in Chennai
JavaScript Training in Chennai
JavaScript Course in Chennai
C C++ Training in Chennai
C Training in Chennai
Tally Course in Anna Nagar
Tally Course in T Nagar

Additri Kapoor said...

Having an assignment due tomorrow and understand you can’t do it yourself? But you’re afraid of delegating your paper to some scam services as well? Why not check https://scamfighter.net/review/unemployedprofessors.com on Scamfighter.net

Elan Progret said...

There are so many types of essays; it can be hard to know where to start. History papers aren’t just limited to history classes. These tasks can be assigned to examine any important historical event or a person. While they’re more common in history classes, you can find this type of assignment in sociology or political science course syllabus, or just get a history essay task for your scholarship.

What is a political essay? A political is just as the name suggests an essay based on politics or a political situation. Completing a political essay is impossible without the proper research to fully understand your subject. First, you should study the primary texts, to analyze its contents. You may take advantage of using reliable Internet sources, with available government reports and political parties' news. Scan through reputable newspapers and magazines to compile relevant data for your political essay. Find more political essay at http://writing-a-thesis.net/

jacklinemelda said...

Our non plagiarized custom term papers are reputable and known for offering high quality custom term papers. We normally write academic papers in all disciplines of study including those seeking for write my nursing paper services.

meldaresearch said...

We are prepared to deliver reliable and trusted Custom Research Paper Writing Services in all the outlined levels of study due to the many experts that we have in our company.Our Affordable Writing Services are affordable and cheap as well. Students have very limited cash flows, and their budgets are usually constrained.

Lisa Sequeira said...

Is myassignmenthelp fake? Find out the complete truth behind the services MyAssignmentHelp provides.

meldaresearch said...

We are the best writing company providing Essay Writer Servicesof the highest quality. We guarantee our customers of nothing but the highest quality document. Our Custom Term Paper Writing Services are well referenced, formatted and edited to ensure that the article is rid of unnecessary details.

Shop Sous Vide said...

A nice post shared.
tree trimmers loxahatchee

Clark said...

Nice post.
tile resurfacing minneapolis

Shop Sous Vide said...

Amaizng.
emergency restoration services fort lauderdale

Clark said...

Great post.
bathroom remodelers clearfield ut

Clark said...

Nice post.
bathroom remodeling clearfield county

Shop Sous Vide said...

A nice post shared.
concrete driveway contractors fort pierce

Shop Sous Vide said...

I really appreciate such a post.
kitchen remodel contractor ogden ut

Shop Sous Vide said...

Good thoughts and well wishes to you and your family. Stay strong!


kitchen remodel contractor fort lauderdale fl

Puremelda said...

It is understood that you do not have adequate time to write. Buy Custom College Papers and submit the Pre Written Research Papers. Make a decision to order Term Paper Writing Help today.

Petersons said...

Worked like charm. Thank you.
express hotel lahore

Unknown said...

interesting and attractive post.
free airdrops

Unknown said...

Remarkable post.
finecoin

Unknown said...

great post.
123movies

maya said...

You have a good point here!I totally agree with what you have said!!Thanks.
airdrop crypto

maya said...

Very nice!!! This is really good blog information thanks for sharing.
123 movie

meldaresearch said...

Research Papers Writing Services should strive to ensure that all essays meets the pukka standards of the examining bodies. Consider hiring quality but also Qualified Research Paper Writers which are advantageous in terms of ensuring you get only top-quality grades on your Online Research Paper Writing Service.

meldaresearch said...

Are you a student and searching for Write My Research Paper Online Services? Do you wish to acquire high-quality services from Legitimate Custom Research Paper Services? As Custom Research Writing Services can always bring a headache to scholars.

The Gabay Group said...

תמשיכו בפרסום פוסטים מעניינים כמו זה. תודה.
gabaygroup.com

Cinema furniture said...
This comment has been removed by the author.
Cinema furniture said...
This comment has been removed by the author.
Unknown said...

very great content share.

שערים לבית מאלומיניום

Unknown said...

Very Great Article.
סילברגייט

Sankar said...

I have read your blog its very attractive and impressive. I like it your blog.
Final Year Projects for CSE in Dot Net

.Net Training in Chennai

Final Year Project Centers in Chennai

Dot Net Training in Chennai

Aleena said...

בדיוק מה שחיפשתי. תודה רבה.
טבעת יהלום

Dafmatok Hosting Trays said...

כל מילה. תודה על השיתוף, מחכה לעוד פוסטים בנושא
מגשי אירוח טבעוניים

Cinema furniture said...

פוסט מעניין, משתף עם העוקבים שלי. תודה
פינות אוכל מעוצבות

Amediciercosmetic said...

תודה על השיתוף. מחכה לכתבות חדשות.
טיפולים קוסמטיים

Comfi furniture said...

פוסט נחמד. חייב לשתף עם העוקבים שלי.
שולחן פינת אוכל

Unknown said...

great work.

רמקולים שקועים

Planner Productions said...

תודה על השיתוף. מחכה לכתבות חדשות.
הפקת אירועים לחברות

Babiesmall said...

מעולה. תודה על הכתיבה היצירתית.
מגדל למידה

brokertome said...

מזל שנתקלתי בכתבה הזאת. בדיוק בזמן
ברוקרים

Unknown said...

thank you for sharing.

קידום עסקים באינטרנט

gemcreature said...

Excellent information Providing by your Article. Thanks.
playboy bunny necklace silver

Bloxi said...

סופסוף מישהו שתואם לדעותיי בנושא. תודה.
בלוק תמונה

alasksecurity said...


תמשיכו בפרסום פוסטים מעניינים כמו זה. תודה.
אלסק מערכות אבטחה

Reputation management said...

כתיבה מעולה, אהבתי. אשתף עם העוקבים שלי.
ניהול מוניטין ברשת

Sam said...

The application of GM crops has raised various social issues not only locally but internationally as well. Food choices are very much influenced by a large number of factors, including social and cultural factor. Avail Assignment Help on Modified GM Crops by expert writers based in Australia.

Ravi said...


You write this post very carefully I think, which is easily understandable to me. Not only this, but another post is also good. As a newbie, this info is really helpful for me. Thanks to you.
Tally ERP 9 Training
tally classes
Tally Training institute in Chennai
Tally course in Chennai

Ravi said...


This content of information has
helped me a lot. It is very well explained and easy to understand.
seo training classes
seo training course
seo training institute in chennai
seo training institutes
seo courses in chennai
seo institutes in chennai
seo classes in chennai
seo training center in chennai

noor said...


نقل عفش من الرياض الى جدة نقل عفش من الرياض الى مكة

Unknown said...

Wow...! Nice post
global asset management seoul

Sitelinx said...

תודה על השיתוף. מחכה לכתבות חדשות.
מומחה קידום אתרים בגוגל

Unknown said...

כל מילה. תודה על השיתוף, מחכה לעוד פוסטים בנושא.
מיטת מעבר

Unknown said...

מזל שנתקלתי בכתבה הזאת. בדיוק בזמן
גיוס כסף לסטארט אפ

Dogma said...

פוסט נחמד. חייב לשתף עם העוקבים שלי.
חברת פיתוח תוכנה

How To Asset Manage said...

I really enjoyed very much with this article here.
global asset management seoul

Global Asset Management Udemy said...

I appreciate you for this blog.
global asset management

meldaresearch said...

Online logistics management writing services are very difficult to complete and many students are always searching for Logistics Writing Services Online to help them complete their logistics coursework writing services and logistic research paper services.

사설토토 said...

פוסט מעניין, משתף עם העוקבים שלי. תודה.
https://canvi.co.il

Clark said...

great post.
מצלמה לבית

intercom4u said...

Good job
אינטרקום לדלת כניסה

Clark said...

great.
global asset management

Fixadoor said...

Good job
Garage door repair Vaughan

Clark said...

thanks for sharing.
Global asset management Seoul

http://powerbitrainings.in/powerbi-training-institute-in-hyderabad/ said...

Hey Loved the post! Great article and congrats on Reaching the To 50! I will be back to visit often


Stratford Management said...

this info is really helpful for me.
stratford management Tokyo

Petersons said...

Bastion Balance Seoul

Bastion Balance Korea

American Male Wellness said...

Well written Blog
Hormone replacement Las Vegas

Petersons said...

Spot on with this article, I really think this website needs more attention. I'll probably be back to read more, thanks for the info.


Bastion Balance Korea

Garage Door Pros Ontario said...

Great article
garage door repair

a1garagedoors said...

Excellent Blog.
garage door repair

riya said...

Help full post, lots of information
gazetted officer
z or r twice
what is isp
space complexity
ng-focus
unexpected token o in json at position 1
do a barrel roll 20 times
cannot set headers after they are sent to the client
how to hack any instagram account 100% working
blink html google trick

Petersons said...

אני לא מסכים עם כל מה שכתוב, אבל מאמר מעניין מאוד

בניית בריכה ביתית