blomqma / next-rest-framework

Type-safe, self-documenting APIs for Next.js
https://next-rest-framework.vercel.app
Other
136 stars 18 forks source link

Can't get v4.0.0 + next 14 off the ground #109

Closed creimers closed 9 months ago

creimers commented 9 months ago

I'm almost sure I'm missing something, but I can't get the docsRouteHandler to display anything on the auto generated front end.

I'm running next-rest-framework 4.0.0 and nextjs 14.0.4.

Here's a repo that reproduces the phenomenon: https://github.com/creimers/next-rest-test

Running npx next-rest-framework generate does populate the openapi.json file, but nothing is being rendered.

In addition, generate and validate on the cli give me this funny ping pong:

image

Again, I'm almost sure I must me missing something. Maybe you can spot it?

creimers commented 9 months ago

There was a problem with the example repo, it is updated and correctly linked now.

creimers commented 9 months ago

Another thing I have noticed are these nested "paths" keys in the openapi.json:

image

In this repo's example folder, it looks different:

image
creimers commented 9 months ago

After digging some more, I've found the following:

The docsRouteHandler is working just fine. When provided with a valid openapi.json, it will generate and display the docs as expected.

What seems to be causing the trouble is the generate cli command. It appears to

From this folder structure

image

this openapi.json is generate:

{
  "openapi": "3.0.1",
  "info": {
    "title": "Next REST Framework",
    "description": "This is an autogenerated documentation by Next REST Framework.",
    "version": "v4.0.0"
  },
  "paths": {
    "paths": {
      "/api/todo": {
        "get": {
          "responses": {
            "200": {
              "description": "Response for status 200",
              "content": {
                "application/json": {
                  "schema": {
                    "$ref": "#/components/schemas/GetTodoResponseBody"
                  }
                }
              }
            },
            "500": {
              "description": "An unknown error occurred, trying again might help.",
              "content": {
                "application/json": {
                  "schema": { "$ref": "#/components/schemas/UnexpectedError" }
                }
              }
            }
          }
        },
        "post": {
          "requestBody": {
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/PostTodoRequestBody" }
              }
            }
          },
          "responses": {
            "201": {
              "description": "Response for status 201",
              "content": {
                "application/json": {
                  "schema": {
                    "$ref": "#/components/schemas/PostTodoResponseBody"
                  }
                }
              }
            },
            "401": {
              "description": "Response for status 401",
              "content": {
                "application/json": {
                  "schema": {
                    "$ref": "#/components/schemas/PostTodoErrorResponseBody"
                  }
                }
              }
            },
            "500": {
              "description": "An unknown error occurred, trying again might help.",
              "content": {
                "application/json": {
                  "schema": { "$ref": "#/components/schemas/UnexpectedError" }
                }
              }
            }
          }
        }
      }
    },
    "schemas": {
      "PostTodoRequestBody": {
        "type": "object",
        "properties": { "name": { "type": "string" } },
        "required": ["name"],
        "additionalProperties": false
      },
      "UnexpectedError": {
        "type": "object",
        "properties": { "message": { "type": "string" } },
        "additionalProperties": false
      },
      "GetTodoResponseBody": {
        "type": "array",
        "items": {
          "type": "object",
          "properties": {
            "id": { "type": "number" },
            "name": { "type": "string" },
            "completed": { "type": "boolean" }
          },
          "required": ["id", "name", "completed"],
          "additionalProperties": false
        }
      },
      "PostTodoResponseBody": { "type": "string" },
      "PostTodoErrorResponseBody": { "type": "string" }
    }
  },
  "components": {}
}
creimers commented 9 months ago

Eventually, it did start to work. Can't reproduce what I ended up changing, but it is working now... Sorry.