question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Example not added to swagger output in case of string, byte and timespan

See original GitHub issue

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

public class EmployeeExample: IExamplesProvider
{
    public object GetExamples()
    {
      return "Sample Value"; //  doing same this for timespan, byte , It's working fine for integer.
    }

Please let me how can i resolve this issue ?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
mattfrearcommented, Jul 11, 2018

@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";
            }
        }

and I think it’s working image

This is using Swashbuckle.AspNetCore 3.0 and my new Swashbuckle.AspNetCore.Filters package (to be released soon)

0reactions
diaznicolasandres1commented, Sep 13, 2020

@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";
            }
        }

and I think it’s working image

This is using Swashbuckle.AspNetCore 3.0 and my new Swashbuckle.AspNetCore.Filters package (to be released soon)

This works, you saved me

Read more comments on GitHub >

github_iconTop Results From Across the Web

Generating Swagger example responses with Swashbuckle
The Swagger 2.0 spec allows for examples to be added to the Response. ... Hi not able to show example value of string,...
Read more >
OpenAPI Specification - Version 2.0
Version 2.0 specification defines a set of files required to describe an API. These files can then be used by the Swagger-UI project...
Read more >
c# - How to define default values for parameters for the ...
This answer suggested placing [DefaultValue("value here")] attribute each property of the SomeRequest class. It may have worked for the regular ...
Read more >
Specify an Array of Strings as Body Parameters in Swagger
In this tutorial, we'll show how to produce a default example value for String arrays, as this behaviour is not enabled by default....
Read more >
DateTime and DateTimeOffset support in System.Text.Json
An overview of how DateTime and DateTimeOffset types are supported in the System.Text.Json library.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found