Skip to content

How to define two response examples for the same class #188

Open
@scrapstation

Description

@scrapstation

The response model of 400 and 500 is the same class: RemoteServiceErrorInfo
But the example is different .
so, I defind two ExamplesProvider are as fallows

    [SwaggerResponse(200)]
    [SwaggerResponse(400, Type = typeof(RemoteServiceErrorInfo))]
    [SwaggerResponseExample(400, typeof(ClentErrorExamples))]
    [SwaggerResponse(500, Type = typeof(RemoteServiceErrorInfo))]
    [SwaggerResponseExample(500, typeof(ServerErrorExamples))]
    public class BaseApiController : ControllerBase
    {
    }
    public class ServerErrorExamples : IExamplesProvider<RemoteServiceErrorInfo>
    {
        public RemoteServiceErrorInfo GetExamples()
        {
            return new RemoteServiceErrorInfo
            {
                Code = "ServerErrorExamples"
            };
        }
    }
    public class ClentErrorExamples : IExamplesProvider<RemoteServiceErrorInfo>
    {
        public RemoteServiceErrorInfo GetExamples()
        {
            return new RemoteServiceErrorInfo
            {
                Code = "ClentErrorExamples"
            };
        }
    }

but the swagger shows the same example in 400 and 500
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions