-
Notifications
You must be signed in to change notification settings - Fork 80
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
Facility to disable automatic annotation for examples #120
Comments
Hmm, you've come up with a use case I hadn't considered. I would say that in general it's a bad practice to return a plain old string in an API response. I usually have unique DTOs for each of my requests and responses. e.g. instead of returning
The reason I say this is, if you ever needed to extend the response by adding a new property, e.g.
Then it is not a breaking change - consumers of your API that know about "message" can keep reading it and don't need to change. |
I don't know if this is related for request examples as well, but I just came across a problem where I have, say, an HTTP POST controller action with the following signature:
Expected behaviour would be that it activates the MyCustomInputExample implementation, which it actually does. But, if I have an implementation of IExamplesProvider that uses type string, it will activate that one afterwards, and override the examples return value from the IExamplesProvider I expected to be used. I can agree it's probably bad practice to return a string, which is an easy fix for me. However, it's still quite confusing behaviour that can take quite a bit of time to debug. |
Hmm, there is logic in place such that if a @CodingBeagle which version of Swashbuckle.AspNetCore.Filters are you using? |
@mattfrear I am using version 5.0.0-rc8 :) |
@mattfrear I realise this issue is quite old but I am having a related problem.
and the other decorated with:
In 4.3.1, the former comes with an example, the latter does not as expected, but now I get the same example (GetResponseExample) for both. As an experiment I tried adding an example to the second case that simply returned null and that worked but it seems counter-intuitive to add an example to not add an example if you see what I mean. thanks |
Hi @freeranger . You've found the workaround I was going to suggest, so well done :-) I've added a new extension method for you to register the required services for examples but without automatic annotations. Instead of call This will be in the next release, possibly quite soon. |
Wow, great service - thanks @mattfrear ! |
Doesn't work for me. |
It's been a while since I looked at this, but I think if you use |
@mattfrear I've created a simple project: https://github.com/tyskodima/TestResponseExamples if I use if I use |
Thanks for providing a simple project to reproduce the error. It looks like it's not working any more. |
I have come across a case where I created a custom response example which is derived from
MyExample : IExamplesProvider and then GetExamples have a specific message returned.
Now I want this to be applied to only specific response code, but because of automatic annotation, it gets applied to all actions that have return type set to string.
The text was updated successfully, but these errors were encountered: