-
Notifications
You must be signed in to change notification settings - Fork 36
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
Example not added to swagger output in case of string, byte and timespan #25
Comments
I've never seen that error before. Can you show me what your controller looks like? |
In StringResponseExample.cs
In PersonController.cs
|
The jsyaml undefined thing looks like a known issue of swagger-ui which was fixed in 2016. swagger-api/swagger-ui#2369 Aside from that, you're missing the I am able to get the Swagger page loading for you with this:
The page loads, and the underlying Swagger document contains the correct example:
However, unfortunately the Swagger-UI page doesn't display the example: This seems like another bug in swagger-ui; there's nothing I can do to fix it, but you may want to raise a bug against swagger-ui. |
This works:
|
Hello- I am a bit confused on this issue. As I understand the Open API v2.0 spec for examples, the examples should include the mime-type. Per ExamplesOperationFilter the mime type is being given as This works for JSON responses; however, what if you have a response mime type of I tried adding Specifically, this is the swagger YAML: This is how swagger-ui renders it: And this is what I would expect/want based off the Is it possible to use a mime-type other than JSON? |
Hi Bels,
Currently my library only supports json.
Thank you for your detailed report of what you have tried to do. However you've posted it in the wrong place - this issue is already closed.
Please raise a new issue and I will look at it when I get a chance. I am on holiday right now so it won't be for a while.
Matt
…Sent from my iPhone
On 2 May 2018, at 22:36, TheBels ***@***.***> wrote:
Hello- I am a bit confused on this issue. As I understand the Open API v2.0 spec for examples, the examples should include the mime-type. Per ExamplesOperationFilter the mime type is being given as application/json.
This works for JSON responses; however, what if you have a response mime type of text/csv? The Open API spec link above has an example with two mime types: JSON and text.
I tried adding [Produces("text/csv")] to my action, as well as the attribute [SwaggerResponse(200, typeof(string))]. However it doesn't seem to pick up that mime type for the example.
Specifically, this is the swagger YAML:
This is how swagger-ui renders it:
And this is what I would expect/want based off the Produces attribute:
Is it possible to use a mime-type other than JSON?
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Thanks for the reply, Matt, and understood. I actually meant to log this against |
@jitsingh89 I'm sure this is probably too late for you, but I have just tested this locally like this: [HttpPost]
[Route("api/Person/save")]
[SwaggerResponse(200, "The person was saved", typeof(string))]
[SwaggerResponseExample(200, typeof(StringResponseExample))]
public IActionResult PostenericPerson(PersonRequest personRequest)
{
string result = "Created";
return Ok(result);
}
public class StringResponseExample : IExamplesProvider
{
public object GetExamples()
{
return "Sample String 1";
}
} This is using Swashbuckle.AspNetCore 3.0 and my new Swashbuckle.AspNetCore.Filters package (to be released soon) |
Thanks @mattfrear |
This works, you saved me |
I not able to show example value of string, timespan, byte in swagger ui page. Error: 0x800a1391- Javascript runtime error: ‘jsyaml’ is undifned. To show example value i have created a class liker this
Please let me how can i resolve this issue ?
The text was updated successfully, but these errors were encountered: