Code Monkey home page Code Monkey logo

Comments (4)

Snapstromegon avatar Snapstromegon commented on June 16, 2024 1

@drwpow thanks for pointing me to redocly. It seems like there are issues in the generated openapi.json. I will close this issue for now and if I can resolve the lints and the issue persists, I will reopen it.

from openapi-typescript.

drwpow avatar drwpow commented on June 16, 2024

In OpenAPI 3, Media types (e.g. application/json) should have a schema property that points to the actual data shape. Without this it’s invalid. Does your OpenAPI schema have this? Also, does your schema throw any errors in validation (run through Redocly CLI)?

from openapi-typescript.

Snapstromegon avatar Snapstromegon commented on June 16, 2024

I'm using rust's aide crate to generate my schema, so I hope that's generated correctly.

This is my openapi.json path:

"/api/events/{id}": {
      "get": {
        "responses": {
          "200": {
            "description": "",
            "content": {
              "application/json": {
                "schema": {
                  "anyOf": [
                    {
                      "$ref": "#/components/schemas/Event"
                    },
                    {
                      "type": "null"
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "description": "Internal Server Error"
          }
        }
      }
    },

And this is the referenced component schema:

"Event": {
        "type": "object",
        "required": [
          "created",
          "end",
          "id",
          "name",
          "owner_id",
          "slug",
          "start",
          "updated",
          "visible"
        ],
        "properties": {
          "coverimage_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "created": {
            "type": "string",
            "format": "date-time"
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "end": {
            "type": "string",
            "format": "date-time"
          },
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "location": {
            "type": [
              "string",
              "null"
            ]
          },
          "name": {
            "type": "string"
          },
          "owner_id": {
            "type": "string",
            "format": "uuid"
          },
          "password_hash": {
            "type": [
              "string",
              "null"
            ]
          },
          "slug": {
            "type": "string"
          },
          "start": {
            "type": "string",
            "format": "date-time"
          },
          "updated": {
            "type": "string",
            "format": "date-time"
          },
          "visible": {
            "type": "boolean"
          },
          "website": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
For reference, here is my complete openapi.json:
{
  "openapi": "3.1.0",
  "info": {
    "title": "",
    "version": ""
  },
  "paths": {
    "/api/query/list_events": {
      "get": {
        "responses": {
          "200": {
            "description": "",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/PublicEvent"
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal Server Error"
          }
        }
      }
    },
    "/api/query/list_users": {
      "get": {
        "responses": {
          "200": {
            "description": "",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/PublicUser"
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal Server Error"
          }
        }
      }
    },
    "/api/events/": {
      "get": {
        "responses": {
          "200": {
            "description": "",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/ReadEvent"
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal Server Error"
          }
        }
      },
      "post": {
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/EventCreateBody"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Event"
                }
              }
            }
          },
          "500": {
            "description": "Internal Server Error"
          }
        }
      }
    },
    "/api/events/{id}": {
      "get": {
        "responses": {
          "200": {
            "description": "",
            "content": {
              "application/json": {
                "schema": {
                  "anyOf": [
                    {
                      "$ref": "#/components/schemas/Event"
                    },
                    {
                      "type": "null"
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "description": "Internal Server Error"
          }
        }
      }
    },
    "/api/images/": {
      "get": {
        "responses": {
          "200": {
            "description": "",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Image"
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal Server Error"
          }
        }
      },
      "post": {
        "requestBody": {
          "description": "multipart form data",
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "array"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "additionalProperties": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal Server Error"
          }
        }
      }
    },
    "/api/images/{id}": {
      "get": {
        "responses": {
          "200": {
            "description": "",
            "content": {
              "application/json": {
                "schema": {
                  "anyOf": [
                    {
                      "$ref": "#/components/schemas/Image"
                    },
                    {
                      "type": "null"
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "description": "Internal Server Error"
          }
        }
      }
    },
    "/api/images/s3/*path": {
      "get": {
        "responses": {
          "500": {
            "description": "Internal Server Error"
          }
        }
      }
    },
    "/api/users/": {
      "get": {
        "responses": {
          "200": {
            "description": "",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/ReadUser"
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal Server Error"
          }
        }
      }
    },
    "/api/users/{id}": {
      "get": {
        "responses": {
          "200": {
            "description": "",
            "content": {
              "application/json": {
                "schema": {
                  "anyOf": [
                    {
                      "$ref": "#/components/schemas/ReadUser"
                    },
                    {
                      "type": "null"
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "description": "Internal Server Error"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Event": {
        "type": "object",
        "required": [
          "created",
          "end",
          "id",
          "name",
          "owner_id",
          "slug",
          "start",
          "updated",
          "visible"
        ],
        "properties": {
          "coverimage_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "created": {
            "type": "string",
            "format": "date-time"
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "end": {
            "type": "string",
            "format": "date-time"
          },
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "location": {
            "type": [
              "string",
              "null"
            ]
          },
          "name": {
            "type": "string"
          },
          "owner_id": {
            "type": "string",
            "format": "uuid"
          },
          "password_hash": {
            "type": [
              "string",
              "null"
            ]
          },
          "slug": {
            "type": "string"
          },
          "start": {
            "type": "string",
            "format": "date-time"
          },
          "updated": {
            "type": "string",
            "format": "date-time"
          },
          "visible": {
            "type": "boolean"
          },
          "website": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "EventCreateBody": {
        "type": "object",
        "required": [
          "end",
          "name",
          "owner_id",
          "slug",
          "start",
          "visible"
        ],
        "properties": {
          "coverimage_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "end": {
            "type": "string",
            "format": "date-time"
          },
          "location": {
            "type": [
              "string",
              "null"
            ]
          },
          "name": {
            "type": "string"
          },
          "owner_id": {
            "type": "string",
            "format": "uuid"
          },
          "password_hash": {
            "type": [
              "string",
              "null"
            ]
          },
          "slug": {
            "type": "string"
          },
          "start": {
            "type": "string",
            "format": "date-time"
          },
          "visible": {
            "type": "boolean"
          },
          "website": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "Image": {
        "type": "object",
        "required": [
          "hash",
          "hidden",
          "id",
          "keywords",
          "metadata",
          "photographer_id",
          "size",
          "uploaded"
        ],
        "properties": {
          "created": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "event_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "hash": {
            "type": "string"
          },
          "hidden": {
            "type": "boolean"
          },
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "keywords": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "metadata": true,
          "photographer_id": {
            "type": "string",
            "format": "uuid"
          },
          "size": {
            "type": "integer",
            "format": "int32"
          },
          "upload_completed": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "upload_filename": {
            "type": [
              "string",
              "null"
            ]
          },
          "uploaded": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "PublicEvent": {
        "type": "object",
        "required": [
          "created",
          "end",
          "id",
          "name",
          "owner",
          "slug",
          "start",
          "updated",
          "visible"
        ],
        "properties": {
          "coverimage_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "created": {
            "type": "string",
            "format": "date-time"
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "end": {
            "type": "string",
            "format": "date-time"
          },
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "location": {
            "type": [
              "string",
              "null"
            ]
          },
          "name": {
            "type": "string"
          },
          "owner": {
            "$ref": "#/components/schemas/PublicUser"
          },
          "slug": {
            "type": "string"
          },
          "start": {
            "type": "string",
            "format": "date-time"
          },
          "updated": {
            "type": "string",
            "format": "date-time"
          },
          "visible": {
            "type": "boolean"
          },
          "website": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "PublicUser": {
        "type": "object",
        "required": [
          "created",
          "display_name",
          "id",
          "is_admin",
          "username"
        ],
        "properties": {
          "created": {
            "type": "string",
            "format": "date-time"
          },
          "display_name": {
            "type": "string"
          },
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "image_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "is_admin": {
            "type": "boolean"
          },
          "username": {
            "type": "string"
          }
        }
      },
      "ReadEvent": {
        "type": "object",
        "required": [
          "created",
          "end",
          "id",
          "name",
          "owner_id",
          "slug",
          "start",
          "updated",
          "visible"
        ],
        "properties": {
          "coverimage_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "created": {
            "type": "string",
            "format": "date-time"
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "end": {
            "type": "string",
            "format": "date-time"
          },
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "location": {
            "type": [
              "string",
              "null"
            ]
          },
          "name": {
            "type": "string"
          },
          "owner_id": {
            "type": "string",
            "format": "uuid"
          },
          "slug": {
            "type": "string"
          },
          "start": {
            "type": "string",
            "format": "date-time"
          },
          "updated": {
            "type": "string",
            "format": "date-time"
          },
          "visible": {
            "type": "boolean"
          },
          "website": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "ReadUser": {
        "type": "object",
        "required": [
          "created",
          "display_name",
          "id",
          "is_admin",
          "username"
        ],
        "properties": {
          "created": {
            "type": "string",
            "format": "date-time"
          },
          "display_name": {
            "type": "string"
          },
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "image_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "is_admin": {
            "type": "boolean"
          },
          "last_login": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "username": {
            "type": "string"
          }
        }
      }
    }
  }
}

from openapi-typescript.

drwpow avatar drwpow commented on June 16, 2024

Sounds good! Yeah with 6.x and below we didn’t have the ability to validate schemas because it’s basically a whole separate problem and project. But the upcoming 7.x (next) version does validate via Redocly because this has been a common sticking point (it’s complete for the most part, just needs a few more bugfixes to ship the stable version)

from openapi-typescript.

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.