Giter Site home page Giter Site logo

Response and Schema Examples about swagger-ui HOT 8 OPEN

jensoleg avatar jensoleg commented on July 2, 2024 3
Response and Schema Examples

from swagger-ui.

Comments (8)

voycey avatar voycey commented on July 2, 2024

This would be useful, they are included in the standard swagger-ui - any hints on where to enabled these in this awesome theme?

from swagger-ui.

davidkeaveny avatar davidkeaveny commented on July 2, 2024

If example responses and schemas are defined in your Swagger definition file, then it should just work out of the box for you. (Nice touch: if you shrink the width of your screen to tablet-or-lower resolutions, the responsive design that @jensoleg has put together hides the sample/schema column, and adds a Show Sample button to display them in a pop-up instead).

In the Swagger definition for an API endpoint, it would look something like this:

"responses": {
    "200" : {
        "description": "The operation completed successfully",
        "schema": {
           "$ref": "#/Namespace.To.Your.Model"
        },
        "examples": {
            "application/json": {
                id: 12345,
                name: "Sample value",
                created: "2016-02-14T06:02:03"
            }
        }
    }
}

I'm using Swashbuckle to generate the Swagger definition from my ASP.NET WebAPI.

from swagger-ui.

voycey avatar voycey commented on July 2, 2024

It works for the responses but I dont have any that describe the exceptions, the examples are defined in my definition block - not sure if that makes a difference?

from swagger-ui.

davidkeaveny avatar davidkeaveny commented on July 2, 2024

As in a model/schema and sample when the response is e.g. a 400 Bad Request?

from swagger-ui.

voycey avatar voycey commented on July 2, 2024

Yep - e.g:

"NoCampaignFoundError [data]": {
            "type": "object",
            "properties": {
                "code": {
                    "description": "HTTP Error Code",
                    "type": "integer",
                    "format": "int32"
                },
                "message": {
                    "description": "Description of Error",
                    "type": "string"
                },
                "exception": {
                    "description": "Exception Details",
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/ExceptionObject"
                    }
                }
            },
            "example": {
                "success": false,
                "data": {
                    "message": "No campaign found",
                    "url": "/impressions/beacon.json",
                    "code": 404,
                    "exception": {
                        "class": "Cake\\Network\\Exception\\NotFoundException",
                        "code": 404,
                        "message": "No campaign found"
                    }
                }
            }
        },

from swagger-ui.

davidkeaveny avatar davidkeaveny commented on July 2, 2024

And that renders successfully in this fork? I can't even get Swashbuckle to generate that part of the definition, so I can't try it out in my API.

from swagger-ui.

voycey avatar voycey commented on July 2, 2024

No sorry that was my point, the error examples dont render in this but they work fine in the vanilla swagger-ui, I assume that those template sections have been removed but not sure where to look?

from swagger-ui.

wazodevs avatar wazodevs commented on July 2, 2024

Nowadays, we're having the same issue. It's only happens with array/list models. If we use a simple model (object, string...) it works.

Wrong Rendered:

`HTTP Status Code Reason Response Model Headers
400 BadRequest Array[object] `

Expected Rendered:

`HTTP Status Code Reason Response Model Headers
400 BadRequest [{"codigo": 0,"mensaje": "string"}] `

This wrong rendered only happens with all request that aren't 200 (404,500...) and the reponse model is an array/list.

¿Any idea what's happening?

from swagger-ui.

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.