vaclavnovotny / NSwag.Examples

NSwag processor to programmatically define strongly-typed examples for response and request parameters.
MIT License
13 stars 11 forks source link

EndpointSpecificExample filtering is not working #16

Closed redshmi closed 1 year ago

redshmi commented 1 year ago

EndpointSpecificExample example is not working. I have 2 example responses for the string datatype. It shows both examples even after filtering with EndpointSepcificExample.

[ExampleAnnotation(Name = "RoadId", ExampleType = ExampleType.Response)]
public class StringResponseRoadIdExample : IExampleProvider<string>
{
    public string GetExample() => "acf3e9de-h32e-468c-9xe3-f6477wtke2bd";
}

[ExampleAnnotation(Name = "BadRequest", ExampleType = ExampleType.Response)]
public class StringResponseBadRequestExample : IExampleProvider<string>
{
    public string GetExample() => "BadRequest";
}

and in the controller i have the attribute as specified in the document.

[ProducesResponseType(StatusCodes.Status201Created, Type = typeof(string))]
[ProducesResponseType(StatusCodes.Status400BadRequest, Type = typeof(string))]
[EndpointSpecificExample(typeof(StringResponseRoadIdExample ), ExampleType = ExampleType.Response, ResponseStatusCode = StatusCodes.Status201Created)]
[EndpointSpecificExample(typeof(StringResponseBadRequestExample ), ExampleType = ExampleType.Response, ResponseStatusCode = StatusCodes.Status400BadRequest)]
public async Task<IActionResult> CreateRoadAsync()

image

vaclavnovotny commented 1 year ago

Hi @navikannur, thank you for fixing this. I have merged the PR and will release this as v1.0.11. Cheers.