Skip to content

Conversation

coderlfm
Copy link

@coderlfm coderlfm commented Jul 7, 2023

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

@vercel
Copy link

vercel bot commented Jul 7, 2023

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

@astahmer
Copy link
Owner

astahmer commented Jul 7, 2023

any opinion on this ? @WickyNilliams @feychenie

@WickyNilliams
Copy link
Collaborator

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)

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

Successfully merging this pull request may close these issues.

3 participants