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

Enhance error messages when input is not a valid openapi #25

Open
gooplancton opened this issue Apr 28, 2024 · 1 comment
Open

Enhance error messages when input is not a valid openapi #25

gooplancton opened this issue Apr 28, 2024 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@gooplancton
Copy link

I'm trying to use openapi-tui with an openapi document generated by the elysia/swagger plugin [link].
Graphical interfaces like scalar [link] don't seem to have a problem with it.
This is a stripped down version of the document that still raises the error:

{
  "openapi": "3.0.3",
  "info": {
    "title": "Elysia Documentation",
    "description": "Development documentation",
    "version": "0.0.0"
  },
  "paths": {
    "/users/": {
      "get": {
        "responses": {
          "200": {
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string"
                },
                "createdAt": {
                  "type": "string"
                },
                "name": {
                  "type": "string"
                },
                "email": {
                  "type": "string"
                },
                "birthDate": {
                  "type": "string"
                },
                "phoneNumberPrefix": {
                  "type": "string"
                },
                "phoneNumber": {
                  "type": "string"
                }
              },
              "required": [
                "id",
                "createdAt",
                "name",
                "email",
                "birthDate",
                "phoneNumberPrefix",
                "phoneNumber"
              ]
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "id": {
                        "type": "string"
                      },
                      "createdAt": {
                        "type": "string"
                      },
                      "name": {
                        "type": "string"
                      },
                      "email": {
                        "type": "string"
                      },
                      "birthDate": {
                        "type": "string"
                      },
                      "phoneNumberPrefix": {
                        "type": "string"
                      },
                      "phoneNumber": {
                        "type": "string"
                      }
                    },
                    "required": [
                      "id",
                      "createdAt",
                      "name",
                      "email",
                      "birthDate",
                      "phoneNumberPrefix",
                      "phoneNumber"
                    ]
                  }
                }
              },
              "multipart/form-data": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "id": {
                        "type": "string"
                      },
                      "createdAt": {
                        "type": "string"
                      },
                      "name": {
                        "type": "string"
                      },
                      "email": {
                        "type": "string"
                      },
                      "birthDate": {
                        "type": "string"
                      },
                      "phoneNumberPrefix": {
                        "type": "string"
                      },
                      "phoneNumber": {
                        "type": "string"
                      }
                    },
                    "required": [
                      "id",
                      "createdAt",
                      "name",
                      "email",
                      "birthDate",
                      "phoneNumberPrefix",
                      "phoneNumber"
                    ]
                  }
                }
              },
              "text/plain": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "id": {
                        "type": "string"
                      },
                      "createdAt": {
                        "type": "string"
                      },
                      "name": {
                        "type": "string"
                      },
                      "email": {
                        "type": "string"
                      },
                      "birthDate": {
                        "type": "string"
                      },
                      "phoneNumberPrefix": {
                        "type": "string"
                      },
                      "phoneNumber": {
                        "type": "string"
                      }
                    },
                    "required": [
                      "id",
                      "createdAt",
                      "name",
                      "email",
                      "birthDate",
                      "phoneNumberPrefix",
                      "phoneNumber"
                    ]
                  }
                }
              }
            }
          }
        },
        "operationId": "getUsers",
        "tags": [
          "User"
        ]
      }
    }
  },
  "components": {
    "schemas": {}
  }
}

openapi-tui -i ./api.json

openapi-tui error: Something went wrong
Error:
   0: paths: data did not match any variant of untagged enum ObjectOrRef at line 8 column 12
@zaghaghi zaghaghi self-assigned this Apr 29, 2024
@zaghaghi zaghaghi added bug Something isn't working enhancement New feature or request and removed bug Something isn't working labels Apr 29, 2024
@zaghaghi
Copy link
Owner

zaghaghi commented May 1, 2024

Hi @gooplancton 👋

I'm afraid to say that the above json file is not a valid openapi json.
Based on openapi-3.0.3 specification here description is a required field

image

You will be able to open the application if you add a description to response object, like this:

    "paths": {
        "/users/": {
            "get": {
                "responses": {
                    "200": {
                        "description": "get users",
                        // rest of the object
                    }
                }
           }
       }
   }

I've changed the label to enhancement in order to provider a better error messages.

@zaghaghi zaghaghi changed the title Error: 0: paths: data did not match any variant of untagged enum ObjectOrRef Enhance error messages when input is not a valid openapi May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants