blomqma/next-rest-framework

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

Closed this issue · 4 comments

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?

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

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

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

  • return invalid openapi json
  • omit all but one route (the last one alphabetically it seems)

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": {}
}

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