scottie1984 / swagger-ui-express

Adds middleware to your express app to serve the Swagger UI bound to your Swagger document. This acts as living documentation for your API hosted from within your app.
MIT License
1.43k stars 226 forks source link

Response with multiple examples does not change example values #232

Closed elielr01 closed 3 years ago

elielr01 commented 3 years ago

Hello guys, thanks for this great library. Really enjoying it so far!

I have found that for responses that have multiple examples, the select with all the examples appear correctly, but when selecting another option it does not changes the example shown.

Example 1: Bad Request image

Change to example 2: Invalid Payload image

This is the extract of the OpenAPI definition of my response in JSON format:

{
  "400": {
    "description": "Bad request. Also sent when payload is invalid.",
    "content": {
      "application/json": {
        "schema": {
          "$ref": "#/components/schemas/HTTPError"
        },
        "examples": {
          "BadRequest": {
            "errorType": "BadRequest",
            "code": 400,
            "message": "Bad request"
          },
          "InvalidPayload": {
            "errorType": "InvalidPayload",
            "code": 400,
            "message": "Invalid payload"
          }
        }
      }
    }
  }
}

I checked using the redux inspector and it is correctly dispatching the action oas3_set_active_examples_member, so Idk if that could be a hint?

image

If I'm doing something wrong, I would appreciate it if someone could point out to me what's my error 😅

scottie1984 commented 3 years ago

I would open this issue with swagger-ui project directly.

elielr01 commented 3 years ago

Oh okok. Then I'll close this and check with swagger-ui. Thanks for the info!

petey9891 commented 3 years ago

You need to add a value to your response example:

BadRequest: {
   value: {
       /* example code */
   }
}

I ran into the same issue and found it that this was barely documented