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

SwaggerResponseExample is not working in version 2.2.0 #16

Closed
thaynaracsantos opened this issue Sep 8, 2017 · 14 comments
Closed

SwaggerResponseExample is not working in version 2.2.0 #16

thaynaracsantos opened this issue Sep 8, 2017 · 14 comments

Comments

@thaynaracsantos
Copy link

To work I had to downgrade to version 2.1.1

@mattfrear
Copy link
Owner

It's working for me. Can you try 2.2.1, which I just released a minute ago? If it's not working please post your code.

@thaynaracsantos
Copy link
Author

I tested and it's not working in version 2.2.1 too. I am using .net core 2.0 and bogus nuget, but even without bogus it's still not working in these versions (2.2.0/2.2.1).

My repository https://github.com/ThaynaraSantos/api-doc

@mattfrear
Copy link
Owner

Hmm I don't have .NET Core 2.0 installed on my dev box as it has issues with some of my existing .NET Core 1.1 solutions at work. I will try run your code under Core 1.1 and see if I can reproduce your issue.

@thaynaracsantos
Copy link
Author

Great, thanks!

@mattfrear
Copy link
Owner

mattfrear commented Sep 11, 2017

What exactly is not working? I've moved your code to my Core 1.1 sample app:

        [HttpGet]
        [Produces("application/json")]
        [SwaggerResponse((int)HttpStatusCode.OK, Type = typeof(IEnumerable<House>))]
        [SwaggerResponseExample((int)HttpStatusCode.OK, typeof(HouseGetExamples))]
        public IEnumerable<House> Get()
        ...

    public class HouseGetExamples : IExamplesProvider
    {
        public object GetExamples()
        {
            HouseGetExample houseGetExample = new HouseGetExample();

            return new List<House>()
            {
                houseGetExample.GetExamples() as House,
                houseGetExample.GetExamples() as House
            };
        }
    }

    public class HouseGetExample : IExamplesProvider
    {
        public object GetExamples()
        {
            House house = new House {Address = "456 Bridge Street", Color = "Blue", Id = 1};
            return house;
        }
    }

And as you can see, it's working fine:

capture

@thaynaracsantos
Copy link
Author

docs

Run the project and go to http://localhost:25111/docs

The same response example, in version 2.1.1, is working.

@mattfrear
Copy link
Owner

I have reluctantly installed .NET 2.0 SDK on my dev machine just to try reproduce your issue.

I ran your repo - it works fine for me locally. Your repo was using 2.1.1 of my package. I updated your repo to use the latest version of my package - 2.2.1, and it still works fine.

I am testing this by going to /swagger:
capture

I didn't know about the /docs page until you told me about it - what generates that? Is that part of Swashbuckle.AspNetCore? Ah, I see, it's a Redoc page. I've never heard of that. Anyway, that's working fine for me here too:

capture2

Hmm. I can't fix it for you if I can't reproduce it.

@thaynaracsantos
Copy link
Author

swagger.json generated in:

Version 2.1.1 (working)

working

Version 2.2.1 (not_working)

not_working

Maybe, the ReDoc script can't read the example in swagger.json after that change.


For your knowledge. (https://github.com/Rebilly/ReDoc)

@mattfrear
Copy link
Owner

OK, so it IS working in Swagger-UI, which is where I test it, but not working in ReDoc.

I removed the application/json stuff by request as part of Issue #12.
There is a PR on my .NET Framework version of this project to optionally add it back in again mattfrear/Swashbuckle.Examples#13

When I get a chance to do that I will port that PR to this project and then it should work again for ReDoc.

I have no idea why redoc needs application/json to work and that seems stupid, but I haven't been through their spec to make sense of it, as I only just heard of them.

@RomanHotsiy
Copy link

ReDoc author here.
Just to clarify, ReDoc behaves correctly here according to Swagger 2.0 spec: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#exampleObject
Example object should be a map from {mime type} to example. So, technically, the output produced by 2.2.1 is invalid Swagger.

@mattfrear
Copy link
Owner

Thanks @RomanGotsiy for clarifying. I will revert the change so that my package produces valid Swagger as soon as I get a chance.

mattfrear added a commit that referenced this issue Sep 14, 2017
…erty, as that is what the swagger spec requires.
@mattfrear
Copy link
Owner

@thaynaracsantos
Copy link
Author

Thank you! It's working fine now.

@mattfrear
Copy link
Owner

This seems to be fixed now with Swashbuckle 3.0

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

3 participants