blomqma / next-rest-framework

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

Fix: query params generation/validation #130

Closed itsjxck closed 5 months ago

itsjxck commented 6 months ago

Noticed a bug that meant query params get generated in the openapi file like:

        "parameters": [
          {
            "name": "site_id",
            "in": "query",
            "required": false,
            "schema": {
              "anyOf": [{ "not": {} }, { "type": "string", "format": "uuid" }]
            }
          },
          {
            "name": "entity_ids",
            "in": "query",
            "required": false,
            "schema": { "anyOf": [{ "not": {} }, { "type": "string" }] }
          },
          {
            "name": "tags",
            "in": "query",
            "required": false,
            "schema": { "anyOf": [{ "not": {} }, { "type": "string" }] }
          },
          {
            "name": "created_by",
            "in": "query",
            "required": false,
            "schema": {
              "anyOf": [{ "not": {} }, { "type": "string", "format": "uuid" }]
            }
          }
        ],

This anyOf: [{ "not": {} }] meant the swagger UI wasn't being generated correctly. I also noticed that the parsing of query params doesn't handle arrays properly so updated that as well.

vercel[bot] commented 6 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
next-rest-framework ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 26, 2024 10:43am
next-rest-framework-demo ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 26, 2024 10:43am
itsjxck commented 5 months ago

Hey @blomqma sorry to ping, but this bug with query params is causing us issues - please could we get your eyes on this?

blomqma commented 5 months ago

Hey @blomqma sorry to ping, but this bug with query params is causing us issues - please could we get your eyes on this?

@itsjxck Thanks for the contribution & welcome to the contributor club, your fix seems like a correct one. I cleaned up the commits a bit and added some test coverage in https://github.com/blomqma/next-rest-framework/pull/138 where I also added you as the co-author. The OpenAPI generation is fixed in v5.1.9 with these changes now.