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

UI Shows Single Example Response Model Only #767

Closed
avishaan opened this issue Dec 6, 2014 · 16 comments
Closed

UI Shows Single Example Response Model Only #767

avishaan opened this issue Dec 6, 2014 · 16 comments

Comments

@avishaan
Copy link

avishaan commented Dec 6, 2014

For code such as this

        "responses": {
          "default": {
            "description": "Invalid request.",
            "schema": {
              "$ref": "Error"
            }
          },
          "200": {
            "description": "Successful request.",
            "schema": {
              "$ref": "Error"
            }
          }
        }

Only the default is shown but not for "200". See screenshot below.
image

@avishaan
Copy link
Author

avishaan commented Dec 6, 2014

This may be related to #671

@avishaan
Copy link
Author

avishaan commented Dec 6, 2014

This seems to be something else. When I do this
image
I get this, which is to say nothing.
image

@avishaan
Copy link
Author

@webron, any idea on this one?

@webron
Copy link
Contributor

webron commented Dec 23, 2014

@codehatcher - any chance you can share your full spec?

@avishaan
Copy link
Author

Here is an example, I tried to truncate some of it.

{
  "swagger": "2.0",
  "info": {
    "title": "title",
    "description": "descriptor",
    "version": "0.1"
  },
  "host": "localhost:3000",
  "consumes": [
    "application/json",
    "application/x-www-form-urlencoded"
  ],
  "produces": [
    "application/json"
  ],
  "basePath": "/api",
  "paths": {
    "/v1/auths/facebook": {
      "post": {
        "x-swagger-router-controller": "auths",
        "operationId": "facebook",
        "tags": ["auths"],
        "description": "Facebook authentication",
        "parameters": [
          {
            "in": "body",
            "name": "body",
            "description": "Facebook Token",
            "required": true,
            "schema": {
              "$ref": "#/definitions/FacebookToken"
            }
          }
        ],
        "security": [
          {
            "facebookAuth": []
          }
        ],
        "responses": {
          "default": {
            "description": "Invalid request.",
            "schema": {
              "$ref": "#/definitions/Error"
            }
          },
          "200": {
            "description": "Successful request.",
            "schema": {
              "uid": "string",
              "token": "string",
              "username": "string"
            }
          }
        }
      }
    }
  },
  "securityDefinitions": {
    "basicAuth": {
      "type": "basic"
    },
    "tokenAuth": {
      "type": "apiKey",
      "description": "Built in token auth",
      "name": "access_token",
      "in": "query"
    },
    "facebookAuth": {
      "type": "apiKey",
      "description": "Facebook token auth using passport-facebook-token",
      "name": "access_token",
      "in": "query"
    }
  },
  "definitions": {
    "Review": {
      "properties": {
        "company": {
          "type": "string"
        },
        "description": {
          "type": "string"
        },
        "rating": {
          "type": "number"
        },
        "images": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "datetime": {
          "type": "number"
        },
        "location": {
          "type": "string"
        },
        "_id": {
          "type": "string"
        },
        "submitter": {
          "type": "string"
        }
      },
      "required": ["company", "description"]
    },
    "FacebookToken": {
      "properties": {
        "access_token": {
          "type": "string"
        }
      }
    },
    "UserRegistration": {
      "properties": {
        "username": {
          "type": "string"
        },
        "password": {
          "type": "string"
        }
      }
    },
    "Ok": {
      "properties": {
        "message": {
          "type": "string"
        }
      },
      "required": ["message"]
    },
    "Error": {
      "properties": {
        "message": {
          "type": "string"
        }
      },
      "required": ["message"]
    }
  }
}

which looks like the following:
image

@webron
Copy link
Contributor

webron commented Dec 23, 2014

For the "200" response, the value is not a valid schema.

@avishaan
Copy link
Author

If I change it to the following for the sake of a valid schema

        "responses": {
          "default": {
            "description": "Invalid request.",
            "schema": {
              "$ref": "#/definitions/Error"
            }
          },
          "200": {
            "description": "Successful request.",
            "schema": {
              "$ref": "#/definitions/Error"
            }
          }
        }

Then 200 doesn't show up at all.
image

@webron
Copy link
Contributor

webron commented Dec 23, 2014

Actually, it appears above the operation as the response. See #674 for more details.

@avishaan
Copy link
Author

This was due to an invalid schema and not an issue.

@webron
Copy link
Contributor

webron commented Dec 23, 2014

No problem, thank you for the update.

@avishaan
Copy link
Author

@webron, I'm nervous about being back here because chances are something is wrong with my response body, but here goes. I am having the same problem as above but I believe my response object is correct. I verified it with the swagger-editor.

        "responses": {
          "400": {
            "description": "Successful request.",
            "schema": {
              "$ref": "#/definitions/Error"
            }
          },
          "200": {
            "description": "Successful request.",
            "schema": {
              "title": "Success",
              "required": ["token"],
              "properties": {
                "token": {
                  "type": "string"
                }
              }
            }
          }
        }

missing response in swagger-ui looks like:
image

but seems to be fine in swagger-editor:
image

@avishaan avishaan reopened this Dec 24, 2014
@avishaan
Copy link
Author

It also doesn't appear above the operation as the response:
image

@webron
Copy link
Contributor

webron commented Dec 24, 2014

Yup, now you've hit #705, which will apply to any inline schema definitions.

Generally speaking, I'd advise not using inline schema definitions (unless they are primitives/arrays) even when they do get supported by the UI.

@avishaan
Copy link
Author

Haha ok, thanks for the speedy response!

@webron
Copy link
Contributor

webron commented Dec 24, 2014

As long as you keep opening issues late at night for you, you'll hit my early morning, and there's nothing like replying issues early in the morning ;)

@avishaan
Copy link
Author

haha

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

2 participants