astahmer / openapi-zod-client

Generate a zodios (typescript http client with zod validation) from an OpenAPI spec (json/yaml)
openapi-zod-client.vercel.app
717 stars 80 forks source link

Invalid array output when grouping by tag #267

Closed codingmatty closed 5 months ago

codingmatty commented 6 months ago

Describe the bug When using an array as a body and using min/max items (either of both, doesn't matter) with group by tags the output is invalid.

After some debugging, it looks like the @key in the schemas block is the actual type with min/max applied and the actual type isn't emitted.

Minimal reproduction

{
  "openapi": "3.0.0",
  "info": { "title": "Test", "version": "1.0.1" },
  "paths": {
    "/test": {
      "put": {
        "summary": "Test",
        "description": "Test",
        "tags": ["Test"],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "testItem": {
                      "type": "string"
                    }
                  },
                  "additionalProperties": false
                },
                "minItems": 1,
                "maxItems": 10
              }
            }
          }
        },
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success",
            "content": { "application/json": {} }
          }
        }
      }
    }
  },
  "components": {},
  "tags": []
}

Expected behavior The emitted Type should be valid

Actual behvaior Invalid output:

import { makeApi, Zodios, type ZodiosOptions } from "@zodios/core";
import { z } from "zod";

const putTest_Body.min(1).max(10) = ;

export const schemas = {
    putTest_Body.min(1).max(10),
};

const endpoints = makeApi([
    {
        method: "put",
        path: "/test",
        alias: "putTest",
        description: `Test`,
        requestFormat: "json",
        parameters: [
            {
                name: "body",
                type: "Body",
                schema: putTest_Body.min(1).max(10)
            },
        ],
        response: z.void(),
    },
]);

export const TestApi = new Zodios(endpoints);

export function createApiClient(baseUrl: string, options?: ZodiosOptions) {
    return new Zodios(baseUrl, endpoints, options);
}

Additional context This seems to work normally, but doesn't work with --group-strategy tag-file. I didn't test other group strategies