openapi-zod-client icon indicating copy to clipboard operation
openapi-zod-client copied to clipboard

fix: Fixed an error when requestBody was of type "object"

Open coderlfm opened this issue 2 years ago • 3 comments
trafficstars

Fixed an error when requestBody was of type "object" When the requestBody type is Object, an error is reported

{
    "openapi": "3.0.3",
    "info": {
        "title": "Pets",
        "version": "1.0.0"
    },
    "paths": {
        "/pets": {
            "post": {
                "summary": "Post pets.",
                "operationId": "PostPets",
                "requestBody": {
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "data": {
                                        "$ref": "#/components/schemas/PostPetsRequest"
                                    }
                                }
                            }
                        }
                    }
                },
                "responses": {}
            }
        }
    },
    "components": {
        "schemas": {
            "PostPetsRequest": {
                "type": "object",
                "properties": {
                    "id": {
                        "type": "string"
                    }
                }
            }
        }
    }
}
depsGraphs.deepDependencyGraph[result.resolver.resolveSchemaName(schemaName).ref]?.forEach(
                                                                                      ^

TypeError: Cannot read properties of undefined (reading 'ref')
    at /Users/liufengmao/Desktop/vjshi/zod-test/packages/openapi-zod-client-vjs/dist/cli.js:1228:87
    at Array.forEach (<anonymous>)
    at /Users/liufengmao/Desktop/vjshi/zod-test/packages/openapi-zod-client-vjs/dist/cli.js:1223:27
    at Array.forEach (<anonymous>)
    at getZodClientTemplateContext (/Users/liufengmao/Desktop/vjshi/zod-test/packages/openapi-zod-client-vjs/dist/cli.js:1188:20)
    at generateZodClientFromOpenAPI (/Users/liufengmao/Desktop/vjshi/zod-test/packages/openapi-zod-client-vjs/dist/cli.js:1298:16)
    at CAC.<anonymous> (/Users/liufengmao/Desktop/vjshi/zod-test/packages/openapi-zod-client-vjs/dist/cli.js:1422:9)

Node.js v20.3.1

coderlfm avatar Jul 07 '23 03:07 coderlfm

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

Name Status Preview Comments Updated (UTC)
openapi-zod-client ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 7, 2023 3:52am

vercel[bot] avatar Jul 07 '23 03:07 vercel[bot]

any opinion on this ? @WickyNilliams @feychenie

astahmer avatar Jul 07 '23 08:07 astahmer

seems like the behavior is not correct now, since it never uses the named schema for requestBody, it always inlines a copy of it (hence all the failing tests)

WickyNilliams avatar Jul 11 '23 09:07 WickyNilliams