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 TaskGet(HttpRequestMessage request)
The problem is, when the documentation is emitted I end up with this ugly mess...
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...
213 comments:
«Oldest ‹Older 201 – 213 of 213I was exactly searching for. Thanks for such a post and please keep it up.
lean six sigma new hampshire
This is really helpful. Thanks for sharing your insights! ventshades
Thanks for sharing this information. Good luck with the site.
Tampa home buyers
Thanks for sharing this information. Good luck with the site.
www.concretecontractortampafl.com/concrete-repair-and-maintenance-tampa
nice post.CSTechbook
This is great, should have seen this sooner.
www.webuyhousesportstluciefl.com/how-to-sell-a-house-as-is-when-it-needs-repairs
I have been reading your posts frequently. I need to say that you are doing a fantastic work. Please keep up the great work.
สล็อตออนไลน์โจ๊กเกอร์ เพื่อให้ลูกค้าได้รับบริการ เว็บตรง จากค่าย Joker123 ไม่ผ่านเอเย่น ผู้เล่นจึงมั่นใจได้ว่า จะได้รับการบริการอย่างตรงไปตรงมา
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
The blog is simply superb. houses in gwalior
Fantastic piece of content! flats in gwalior
Thank you for providing such valuable content and insightful information. social media promotion agency gwalior
Post a Comment