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

Additional response examples are not honoured #9

Closed
Stefan-Z-Camilleri opened this issue Aug 13, 2017 · 7 comments
Closed

Additional response examples are not honoured #9

Stefan-Z-Camilleri opened this issue Aug 13, 2017 · 7 comments

Comments

@Stefan-Z-Camilleri
Copy link
Contributor

Hi

First of all, thank you for your great library.

In my case, I've been working with this and even modified it a bit. Yet either I am doing something wrong, or I don't know, but examples for additional responses are not being generated for me.

I am using v2.1.1

screen shot 2017-08-13 at 09 13 42

To the left is the minor modification I made to your library, which simply swaps out the StatusCode with a version that has a descriptive version (ex. (200) OK).

As you can see from the screenshot, the examples are being provided using default values... yet whilst debugging the IOperationFilter I can clearly see the example set correctly on the Response.Examples object.

p.s. this works fine for the request body.

Additional info

The action
screen shot 2017-08-13 at 09 16 08

One of the examples that is not output
screen shot 2017-08-13 at 09 18 18

The example is clearly there during debug
screen shot 2017-08-13 at 09 22 05

What am I missing?

@Stefan-Z-Camilleri
Copy link
Contributor Author

Stefan-Z-Camilleri commented Aug 13, 2017

Ok... so some debugging later, I realize the error is apparently in Swagger-UI or I believe SwashBuckle itself (//TODO: I'll have to check the swagger spec to see who is actually wrong here)

The examples for responses are generated as an examples property on the response (in line with the actual Response model that SwashBuckle uses.

screen shot 2017-08-13 at 09 55 28

If we move this example to the actual schema definition (and rename it from examples to example, then everyone is happy:
screen shot 2017-08-13 at 09 58 13

Giving (pardon the styling... will clean that up later)
screen shot 2017-08-13 at 09 58 52

I'm working on a fix on the same lines as you use the ISchemaRegistry in the Request part of the filter.

@Stefan-Z-Camilleri
Copy link
Contributor Author

This is a swagger-ui bug:

swagger-api/swagger-ui#1213
swagger-api/swagger-ui#1248
swagger-api/swagger-ui#1213

This was fixed in 3.x ... alas SwashBuckle has not upgraded to 3.x yet, bar one fork on myget by another developer.

The temporary workaround for this is to add an example schema on the fly, using an IOperationFilter which is just for the example and modifying the schema ref on the response.

@mattfrear
Copy link
Owner

Hi Stefan,

Yes I noticed the bug you're describing a few months ago, and also found the same related swagger-ui bugs as you have found. However, I didn't find a workaround as you have done - nice work.

If you want to submit a PR for your workaround then I will accept it - but for me, personally, it's not a big issue and I'm happy to wait for the swagger-ui fix to be imported into Swashbuckle.

@Stefan-Z-Camilleri
Copy link
Contributor Author

Stefan-Z-Camilleri commented Aug 14, 2017

I'm not sure if I should submit a PR here @mattfrear as it is more of a hack than a fix. What I am doing is the following:

1- I fetch the schema for the type
2- I clone the schema and rename the ref to a guid
3- I inject the examples into the new schema and add it to the collection using the new guid as key
4- I set the response schema ref to the ref the new schema

I also added a little hack for Swagger's limitation in rendering arrays, I create an ExpandoObject on the fly and add that as a schema... this is handy for example validation responses.

If you want this PR, I'll create it.. it's your call sir.

@mattfrear
Copy link
Owner

Ah ok, thanks - I'll leave it as-is then. Hopefully Swashbuckle will get the swagger-ui fix soon and then it'll all work correctly.

@freeranger
Copy link

freeranger commented Sep 2, 2017

@Stefan-Z-Camilleri could you post your hack here or a link to a fork so others can benefit from it while we wait for swashbuckle to catch up? Thanks

@mattfrear
Copy link
Owner

I think this is fixed as of Swashbuckle 2.0 which shipped with the new swagger-ui.

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