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

ExamplesProvider does not apply to sub objects #138

Open
JonnyBooker opened this issue Feb 3, 2020 · 1 comment
Open

ExamplesProvider does not apply to sub objects #138

JonnyBooker opened this issue Feb 3, 2020 · 1 comment

Comments

@JonnyBooker
Copy link

The examples provider doesn't seem to respect if the example provided is a sub class of another object.

If I have a nested object within the request object, the example is not picked up in Swagger. For example:

public class ControllerExample
{
    public IActionResult Post(TestClass testClass)
    {
        //... Etc
    }

    public class TestClass
    {
        public TestSubClass TestSubClass { get; set; }
    }

    public class TestSubClass
    {
        public string Id { get; set; }
    }
}

public class TestSubClassExamplesProvider : IExamplesProvider<ControllerExample.TestSubClass>
{
    public ControllerExample.TestSubClass GetExamples()
    {
        return new ControllerExample.TestSubClass
        {
            Id = "Hello"
        };
    }
}

In this example, I'd expect that the TestSubClass in the swagger example would have a value of "Hello" in swagger, however it is not picked up and falls back to the default value for a string.

@mattfrear
Copy link
Owner

I'm going to copy/paste this advisory to any open issues that are for ExamplesOperationFilter.

https://github.com/mattfrear/Swashbuckle.AspNetCore.Filters#do-not-use-this-filter-unless-you-have-to

Swashbuckle.AspNetCore supports adding examples from XML documentation, which might already cover your use case, in which case you can stop using this package and close your issue.

If examples from XML documentation doesn't work for you, then feel free to leave your issue open.

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