-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: invalid dependency when using chaining with tag group strategy
- Loading branch information
1 parent
def55df
commit 197316b
Showing
3 changed files
with
101 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"openapi-zod-client": patch | ||
--- | ||
|
||
Fix invalid output when using array types as the endpoint body with minItems or maxItems and using the tag-file group-strategy. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
lib/tests/array-body-with-chains-tag-group-strategy.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import type { OpenAPIObject } from "openapi3-ts"; | ||
import { expect, test } from "vitest"; | ||
import { generateZodClientFromOpenAPI } from "../src"; | ||
|
||
test("array-body-with-chains-tag-group-strategy", async () => { | ||
const openApiDoc: OpenAPIObject = { | ||
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: [], | ||
}; | ||
|
||
const output = await generateZodClientFromOpenAPI({ | ||
disableWriteToFile: true, | ||
openApiDoc, | ||
options: { groupStrategy: "tag-file" }, | ||
}); | ||
expect(output).toMatchInlineSnapshot(` | ||
{ | ||
"Test": "import { makeApi, Zodios, type ZodiosOptions } from "@zodios/core"; | ||
import { z } from "zod"; | ||
const putTest_Body = z.array(z.object({ testItem: z.string() }).partial()); | ||
export const schemas = { | ||
putTest_Body, | ||
}; | ||
const endpoints = makeApi([ | ||
{ | ||
method: "put", | ||
path: "/test", | ||
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); | ||
} | ||
", | ||
"__index": "export { TestApi } from "./Test"; | ||
", | ||
} | ||
`); | ||
}); |