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

230 comments:

«Oldest   ‹Older   201 – 230 of 230
Angel17 said...

This is really helpful. Thanks for sharing your insights! ventshades

Clark said...

Thanks for sharing this information. Good luck with the site.
Tampa home buyers

Clark said...

Thanks for sharing this information. Good luck with the site.
www.concretecontractortampafl.com/concrete-repair-and-maintenance-tampa

Clark said...

nice post.CSTechbook

James said...

This is great, should have seen this sooner.

www.webuyhousesportstluciefl.com/how-to-sell-a-house-as-is-when-it-needs-repairs

Angel17 said...
This comment has been removed by the author.
Nishan Singh said...

I have been reading your posts frequently. I need to say that you are doing a fantastic work. Please keep up the great work.

Pharmacy Dropshipper said...

สล็อตออนไลน์โจ๊กเกอร์ เพื่อให้ลูกค้าได้รับบริการ เว็บตรง จากค่าย Joker123 ไม่ผ่านเอเย่น ผู้เล่นจึงมั่นใจได้ว่า จะได้รับการบริการอย่างตรงไปตรงมา

dbcity said...

Choosing DB City was one of the best decisions I've made. From its prime location to its top-notch amenities, every aspect surpasses expectations. Living here truly feels like a dream come true. apartments for sale in Gwalior

Anonymous said...

The blog is simply superb. houses in gwalior

Anonymous said...

Fantastic piece of content! flats in gwalior

Anonymous said...

Thank you for providing such valuable content and insightful information. social media promotion agency gwalior

Farmlands for sale in shankarpally @Hyderabad. said...

I just wanted to drop a quick note to express my appreciation for your blog. Your content consistently brightens my day and provides valuable insights. Thank you for sharing your expertise and passion with us. Keep up the fantastic work!

farm land for sale near shankarpally.

EUMAXINDIA said...

Looking for a reliable kraft paper burger box supplier? We offer high quality kraft paper burger boxes at best prices.

Are you in search of high-quality Kraft boxes suppliers in Dubai? Look no further than Yashtech! With our expertise and commitment to excellence, we provide the finest Kraft boxes that meet all your packaging needs. Whether you're a small business or a large corporation, our customizable solutions are designed to impress. In this blog post, we will explore the benefits of Kraft boxes and how Yashtech can help elevate your brand. Get ready to discover the perfect packaging solution that combines functionality and aesthetics seamlessly. Let's dive in!

Kraft boxes Dubai

EUMAXINDIA said...

Zealcon, a leading glass and aluminum company in Dubai, UAE, offers a stunning selection of folding doors that can transform your living space. Their doors are perfect for those seeking to:
Maximize light and openness: Folding doors seamlessly connect indoor and outdoor areas, creating a sense of spaciousness and allowing natural light to flood your home.
Enhance versatility: Open the doors fully to create a breezy open plan or partially fold them for a more defined space.
Achieve a modern aesthetic: Zealcon's folding doors boast sleek and contemporary designs that complement any architectural style.
Why Choose Zealcon Folding Doors?
Extensive Variety: Zealcon boasts a comprehensive range of folding door options, including bifolding doors, telescopic glass doors, and more.
Unmatched Customization: They offer a vast selection of colors and finishes, allowing you to personalize your doors to perfectly match your taste and décor.
Superior Quality: Zealcon utilizes high-grade aluminum profiles and advanced glazing technologies to ensure durability and energy efficiency.
Expert Service: Their team of professionals provides exceptional service, from design consultation and measurement to installation and after-sales support.
Zealcon Folding Doors - The Perfect Fit for Your Dubai Home
Whether you're looking to create a seamless indoor-outdoor living area, section off a room, or add a touch of modern elegance to your space, Zealcon's folding doors provide the ideal solution.


Folding doors in UAE

Aditya Sachdeva Men said...

Experience the ultimate in luxury fashion with ASM Luxe Shirt Collection. Discover our range of premium shirts, tailored to perfection, for men and women who demand the finest quality.
Book your Appointment - 93199 39500 / https://www.adityasachdevamen.in/collections/shirts
Content Writer & SEO - Jai
All right reserved – Aditya Sachdeva Men

Tyler Adams said...

This was a fantastic read! Thank you for offering such practical advice. Your posts are always full of useful information. disneyplus.com/begin

thomaskeylee5 said...

Thank you for your time and effort in creating this post. It was very informative and helpful
kroger.com/feedback

portal-office-com said...

"This post provided exactly the clarity I needed. Thanks for sharing your expertise!"
portal.office.com

123-hp-com-setup said...

This post is just what I needed. Your tips combined with 123.hp.com/setup made the entire process of configuring my new printer hassle-free. Thank you!

tomburke said...

Ignoring parameters in Swashbuckle can simplify API documentation by excluding unnecessary or redundant parameters, ensuring clarity for developers. It’s particularly helpful when dealing with endpoints that include dynamically generated or optional parameters that don’t need detailed documentation. By customizing the Swagger setup, you can focus on key aspects of your API while maintaining a clean and professional interface. For example, just like in cheap digitizing embroidery services, focusing on essential details ensures efficiency and quality. Similarly, tailoring Swashbuckle to ignore irrelevant parameters enhances user experience by highlighting what truly matters in your API documentation.

Selena Gomez said...

I appreciate the effort you’ve put into creating such detailed and informative content. Thank you! www.homedepot.com survey

adalinemarie said...

Great advice! I’m definitely going to share this with my friends. tv.youtube.com/start

adalinemarie said...

Thanks for the great tips! Definitely going to implement them. tv.youtube.com/start

adalinemarie said...

Thank you for such a detailed and thorough post! It’s clear that you’ve invested time into making this content valuable for your readers.tv.youtube.com/start

Selena Gomez said...

The way you present your ideas is nothing short of brilliant.
www.homedepot.com survey

tellculvers-com-survey said...

Thanks for providing such useful insights in your posts! Speaking of excellent service, Culver’s customers can head to tellculvers.com/survey to share their experiences.

Aditya Sachdeva Men said...

Discover the Premium Sky Blue Cotton Shirt by Aditya Sachdeva, crafted from high-quality cotton fabric with unique black and white line detailing. Perfect for any occasion!
Book your Appointment - 93199 39500 / https://www.adityasachdevamen.in/products/luxury-party-attire
Content Writer & SEO - Jai
All right reserved – Aditya Sachdeva Men https://www.adityasachdevamen.in

taylorswift14311 said...

This really resonated with me.
rumble pair

Aditya Sachdeva Men said...

Discover the handcrafted Black Cloud Party Shirt featuring eye-catching embroidery. Made from 98% cotton and 2% elastane, this versatile shirt is perfect for New Year’s Eve parties or casual gatherings. Pair it with jeans or chinos for a stylish look!
Book your Appointment - 93199 39500 / https://www.adityasachdevamen.in/products/party-shirt
Content Writer & SEO - Jai
All right reserved – Aditya Sachdeva Men https://www.adityasachdevamen.in

«Oldest ‹Older   201 – 230 of 230   Newer› Newest»