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

NSwagStudio generating wrong method signature #842

Closed
andrecarlucci opened this issue Jul 12, 2017 · 9 comments
Closed

NSwagStudio generating wrong method signature #842

andrecarlucci opened this issue Jul 12, 2017 · 9 comments

Comments

@andrecarlucci
Copy link

andrecarlucci commented Jul 12, 2017

Hi guys,

I have these routes in my asp.net core:

/api/{subscriptionId}/sites 
public IActionResult List(string searchString);  
/api/sites 
public IActionResult ListAll(string subscriptionIdFilter = null, string searchString = null);

NSwagStudio is generates the first method just fine, but it is adding a phantom parameter called subscriptionId to the second one:

public async Task<ListViewModelOfSiteItem> ListAllAsync(string subscriptionId, string subscriptionIdFilter = null, string searchString = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))

This method is calling the first's method endpoint, nswagstudio is somehow mixing them two. Or maybe I'm doing something wrong...?

Any thoughts?

@RicoSuter
Copy link
Owner

Theres an option to ignore unused path parameters...

@andrecarlucci
Copy link
Author

Hi @RSuter,

But I don't want to ignore anything, I need both methods and their optional parameters.
What do you mean exactly?
Tks!

@RicoSuter
Copy link
Owner

The problem is that you have this signature

/api/{subscriptionId}/sites 
public IActionResult List(string searchString);  

ie there is a subscriptionId path parameter which is not available as parameter in the method. By default NSwag generates and adds this parameter even if it is not a method parameter. You can disable this behavior with by setting AddMissingPathParameters to false

@andrecarlucci
Copy link
Author

andrecarlucci commented Jul 12, 2017

This parameter is set on the controller via an action filter.
NSawg adds it to every call as you said, which is perfectly fine and useful for me: the caller has to inform the subscription.
So far so good.

My problem is in the second method, not in the first one. There is no subscriptionId in the route and NSwag adds it anyway :(

@RicoSuter
Copy link
Owner

Ah ok, this is strange. Can you provide a sample controller class where i can reproduce this?

@andrecarlucci
Copy link
Author

The code on #843 also generates the parameter problem.

I guess that as the URL is appended, the "{subscriptionId}" appears there and then the required parameter is generated.

@RicoSuter
Copy link
Owner

Yes this is the problem... For now remove the route on the controller and specify all routes manually on the action - or dont use absolute routes on the actions when a ctrl route is set

@RicoSuter
Copy link
Owner

Can we close this and fix the other one?

@andrecarlucci
Copy link
Author

Yeap, sounds good.

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