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

Unable to setup example for a query parameter of type List<string> #152

Closed
sturlath opened this issue May 22, 2020 · 3 comments
Closed

Unable to setup example for a query parameter of type List<string> #152

sturlath opened this issue May 22, 2020 · 3 comments

Comments

@sturlath
Copy link

I started with an issue at Swashbuckle.Examples that evolved into using this filter so I'm recreating it here in the correct place.

So my issue is basically that I can't show an example values for a List in Swagger UI. My last attempt was to use the List Request example like this here below but that doesn't change anything in the UI.

/// <summary>
/// GetById
/// </summary>
[HttpGet]
[SwaggerRequestExample(typeof(string), 
                       typeof(RequestListExample), 
                       jsonConverter: typeof(StringEnumConverter))]
[ProducesResponseType(typeof(ResponseDTO), 200)]
public ResponseDTO GetById([FromQuery] List<string> ids)
{
    return new ResponseDTO() { };
}

// where this is the example 

public class RequestListExample: IExamplesProvider<string>
{
    public string GetExamples()
    {
        return "some id's"; 
    }
}

What am I doing wrong here? Must be something tiny I'm missing...

@mattfrear
Copy link
Owner

Hi Sturla

Thanks for opening this issue in the correct repo.
What you are missing is that this package doesn't support examples on the query string at all. It only supports response body examples or request body examples.

I'm sorry that I didn't spot it sooner when you first opened your issue, as you may have noticed I was looking at it on my phone.

@mattfrear
Copy link
Owner

I recently added support for querystring examples to Swashbuckle.AspNetCore in this PR domaindrivendev/Swashbuckle.AspNetCore#1629.

I didn't explicitly add support for lists to that, so if you want Lists to work then you'd need to add it to Swashbuckle.AspNetCore yourself (and submit a PR).

@sturlath
Copy link
Author

sturlath commented May 22, 2020

Ok @mattfrear I have nothing better to do over the weekend so how would we represent the example of List ?

Something like this here?

/// <summary>
/// GetById
/// </summary>
// <param name="Ids" example="first|second|third"></param>
public void GetByIds([FromQuery] List<string> ids)
{}

I'll post a comment on Swashbuckle.AspNetCore and ask for a design and reference this one

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

No branches or pull requests

2 participants