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

Same schema on different request Methods #54

Open
schillerenrico opened this issue Jul 11, 2024 · 5 comments
Open

Same schema on different request Methods #54

schillerenrico opened this issue Jul 11, 2024 · 5 comments

Comments

@schillerenrico
Copy link

schillerenrico commented Jul 11, 2024

Environment

  • Operating System: Windows_NT
  • Node Version: v20.15.0
  • Nuxt Version: 3.12.3
  • CLI Version: 3.12.0
  • Nitro Version: 2.9.7
  • Package Manager: npm@10.8.1
  • Builder: -
  • User Config: css, ssr, devtools, modules, runtimeConfig, ui, colorMode, app, openFetch, vue, compatibilityDate, future, srcDir
  • Runtime Modules: @nuxt/ui@2.17.0, @vueuse/nuxt@10.11.0, nuxt-open-fetch@0.8.0, nuxt-lodash@2.5.3
  • Build Modules: -

Reproduction

using a swagger.json like this

...

"/api/health/logs": {
      "get": {
        "tags": [
          "Health"
        ],
        "summary": "Show logs",
        "description": "Show all application logs",
        "operationId": "ApplicationLogEndpoint",
        "parameters": [
          {
            "name": "user",
            "in": "query",
            "schema": {
              "type": "string",
              "default": "SYSTEM",
              "nullable": true
            }
          },
          {
            "name": "logLevel",
            "in": "query",
            "schema": {
              "default": "INFO",
              "nullable": true,
              "$ref": "#/components/schemas/LogLevelType"
            }
          },
          {
            "name": "page",
            "in": "query",
            "required": true,
            "schema": {
              "type": "integer",
              "format": "int32"
            }
          },
          {
            "name": "pageSize",
            "in": "query",
            "required": true,
            "schema": {
              "type": "integer",
              "format": "int32"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PaginationResponseOfLog"
                },
                "example": [
                  {
                    "logLevel": "TRACE",
                    "eventUser": "SYSTEM",
                    "message": "Trace Log",
                    "data": null,
                    "created": "2024-07-11T09:19:00.6673497+02:00"
                  },
                  {
                    "logLevel": "DEBUG",
                    "eventUser": "SYSTEM",
                    "message": "Debug Log",
                    "data": null,
                    "created": "2024-07-11T09:19:00.6674457+02:00"
                  }
                ]
              }
            }
          },
          "401": {
            "description": "Unauthorized"
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiBadRequestResponse"
                }
              }
            }
          },
          "500": {
            "description": "Server Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiExceptionResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "JWTBearerAuth": []
          }
        ]
      },
      "delete": {
        "tags": [
          "Health"
        ],
        "summary": "Clear all logs",
        "description": "Clear all collected logs",
        "operationId": "ClearApplicationLogsEndpoint",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "text/plain": {
                "schema": {
                  "$ref": "#/components/schemas/EmptyResponse"
                }
              },
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EmptyResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized"
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiBadRequestResponse"
                }
              }
            }
          },
          "500": {
            "description": "Server Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiExceptionResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "JWTBearerAuth": []
          }
        ]
      }
    },

...

Describe the bug

When I request the "GET" the generated schema wanted me to provide "query" with pagesize and page. Thats totally fine.
But if I request the "DELETE" it uses the same schema and wants me to provide page and pagesize as well.

Is this a bug or a swagger misconfiguration. Cause in swagger no parameters are needed for the "DELETE" method

Additional context

No response

Logs

No response

@schillerenrico
Copy link
Author

image
image

@schillerenrico
Copy link
Author

hope this repo is still maintained 🙏 cause this module is helping so much

@schillerenrico
Copy link
Author

schillerenrico commented Oct 16, 2024

We really need a solution for this problem. If we use an endpoint with different methods like POST PUT and GET and each one is giving another response, typescript is not distinguish between those methods in the response.

The typescript response schema is the same for ALL methods and thats wrong. I dont know how to solve this problem and it looks like a typescript bug in your module

@enkot
Copy link
Owner

enkot commented Oct 31, 2024

Hi @schillerenrico,
Sorry for long delay. Could you please make a repro or provide an OpenAPI file?

@schillerenrico
Copy link
Author

schillerenrico commented Nov 4, 2024

Hello @enkot,
sure here is a bit of the json which results into the error
openapi.json

When using the DELETE method typescript requires it to have a query property but that should not be the case for DELETE, just for the GET method
image
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants