简体   繁体   中英

Swagger/Swashbuckle Example limited to one example pr request object?

I've been struggling with making swagger request examples using Swashbuckle, because I have several endpoints that uses the same request model. I make multiple examples, applying the correct ones to each endpoint, but only one of the examples will be applied to all endpoints, and this has confused me a lot. Then I read this on github ( https://github.com/mattfrear/Swashbuckle.Examples ):

For requests, in the Swagger 2.0 spec there is only one schema for each request object defined across all the API endpoints. So if you are using the same request object in multiple API endpoints, ie on multiple controller actions like this:

public async Task<IHttpActionResult> DeliveryOptionsForAddress(DeliveryOptionsSearchModel search)
...
// maybe in some other controller, e.g. Search.cs
public async Task<IHttpActionResult> Search(DeliveryOptionsSearchModel search)

That DeliveryOptionsSearchModel object is only defined once in the entire Swagger document and it can only have one request example defined.

So my question is, is there a way around this? I see someone have used an Example tag, but it does not display anything. Remark tag does work, but I would rather have a proper example that can be used directly if possible.

Ok, I reached out to the creator Matt Frear who explained to me that if I wanted multiple request examples for the same type, I would have to move from Swashbuckle.Examples to Swashbuckle.AspNetCore.Filters. Unfortunately, my current project is running framework 4.6, so I am unable to test it, but it should be simple enough if your project is running core.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM