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

ActionMethodSelectorAttribute causes swagger file not to show up with 2 end points same name #1363

Open
zoinkydoink opened this issue Mar 17, 2020 · 3 comments

Comments

@zoinkydoink
Copy link

What I am trying to do is have one endpoint name/route with multiple parameters.
I have got the endpoints working but when viewing swagger file, I get the error

'Fetch error undefined ./v1/swagger.json'
Below is complete code that causes the issue.
If i remove one of the end points and just leave one (still with [PostFor], it works and swagger file/doc shows, as soon as I add the second, swagger file stops working.

VERSION:

5.0

STEPS TO REPRODUCE:

    public class PostForAttribute: ActionMethodSelectorAttribute
    {

        public Type Type { get; }

        public PostForAttribute(Type type)
        {
            Type = type;
        }

        public override bool IsValidForRequest(RouteContext routeContext, ActionDescriptor action)
        {
            routeContext.HttpContext.Request.EnableBuffering();
            var body = new StreamReader(routeContext.HttpContext.Request.Body).ReadToEndAsync().Result;
            try
            {
                JsonConvert.DeserializeObject(body, Type, new JsonSerializerSettings { MissingMemberHandling = MissingMemberHandling.Error });
                return true;
            }
            catch (Exception)
            {
                return false;
            }
            finally
            {
                routeContext.HttpContext.Request.Body.Position = 0;
            }
        }
    }
    public class TestController : ControllerBase
    {
        private readonly IMediator _mediator;

        public TestController(IMediator mediator)
        {
            _mediator = mediator;
        }


        [HttpPost("/send")]
        [PostFor(typeof(Class2))]

        public async Task<IActionResult> Class2Method(Class2 cmd)
        {
            var user = await _mediator.Send(cmd);
            return Ok(user);
        }

        [HttpPost("/send")]
        [PostFor(typeof(Class1))]

        public async Task<IActionResult> Class1Method(Class1 cmd)
        {
            var user = await _mediator.Send(cmd);
            return Ok(user);
        }

        public class Class1
        {
            public string ClassOne { get; set; }
        }
        public class Class2
        {
            public string ClassTwo { get; set; }
        }
    }

EXPECTED RESULT:

Multiple end points with same name and different parameters

ACTUAL RESULT:

Fetch error undefined ./v1/swagger.json

@icnocop
Copy link

icnocop commented Feb 17, 2021

Does the debug output indicate a more detailed error?

@abhiphirke
Copy link

ActionMethodSelectorAttribute

Swashbuckle.AspNetCore.SwaggerGen.SwaggerGeneratorException: Conflicting method/path combination "GET WeatherForecast/mypath/{id}" for actions - ActSel.Controllers.WeatherForecastController.Get1 (ActSel),ActSel.Controllers.WeatherForecastController.Get2 (ActSel). Actions require a unique method/path combination for Swagger/OpenAPI 3.0. Use ConflictingActionsResolver as a workaround at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GenerateOperations(IEnumerable1 apiDescriptions, SchemaRepository schemaRepository)
at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GeneratePaths(IEnumerable1 apiDescriptions, SchemaRepository schemaRepository) at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GetSwagger(String documentName, String host, String basePath) at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider) at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

@tituszban
Copy link

I ran into the same issue when trying to use feature flags to switch between endpoints.

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

4 participants