Git Product home page Git Product logo

Comments (7)

mattfrear avatar mattfrear commented on June 15, 2024 1

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.

from swashbuckle.aspnetcore.filters.

freeranger avatar freeranger commented on June 15, 2024 1

@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

from swashbuckle.aspnetcore.filters.

Stefan-Z-Camilleri avatar Stefan-Z-Camilleri commented on June 15, 2024

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.

from swashbuckle.aspnetcore.filters.

Stefan-Z-Camilleri avatar Stefan-Z-Camilleri commented on June 15, 2024

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.

from swashbuckle.aspnetcore.filters.

mattfrear avatar mattfrear commented on June 15, 2024

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.

from swashbuckle.aspnetcore.filters.

Stefan-Z-Camilleri avatar Stefan-Z-Camilleri commented on June 15, 2024

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.

from swashbuckle.aspnetcore.filters.

mattfrear avatar mattfrear commented on June 15, 2024

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

from swashbuckle.aspnetcore.filters.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.