Skip to content

Commit f06719f

Browse files
committed
chore: bump version to 0.0.16, refine required parameter handling in OpenAPI generation and add new test for mixed query parameters
1 parent 66de60b commit f06719f

3 files changed

Lines changed: 33 additions & 3 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@dokploy/trpc-openapi",
3-
"version": "0.0.15",
3+
"version": "0.0.16",
44
"description": "tRPC OpenAPI",
55
"author": "dokploy",
66
"private": false,

src/generator/schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export const getParameterObjects = (
9090
return {
9191
name: shapeKey,
9292
paramType: isPathParameter ? 'path' : 'query',
93-
required: isPathParameter || required || isShapeRequired,
93+
required: isPathParameter || isShapeRequired,
9494
schema: shapeSchema,
9595
};
9696
})

test/generator.test.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1663,7 +1663,6 @@ describe('generator', () => {
16631663
Object {
16641664
"in": "query",
16651665
"name": "one",
1666-
"required": true,
16671666
"schema": Object {
16681667
"type": "string",
16691668
},
@@ -1814,6 +1813,37 @@ describe('generator', () => {
18141813
`);
18151814
});
18161815

1816+
test('with mixed required and optional query params', () => {
1817+
const containerIdRegex = /^[a-zA-Z0-9.\-_]+$/;
1818+
const appRouter = t.router({
1819+
getConfig: t.procedure
1820+
.meta({ openapi: { method: 'GET', path: '/docker/getConfig' } })
1821+
.input(
1822+
z.object({
1823+
containerId: z.string().min(1).regex(containerIdRegex, 'Invalid container id.'),
1824+
serverId: z.string().optional(),
1825+
}),
1826+
)
1827+
.output(z.object({}))
1828+
.query(() => ({})),
1829+
});
1830+
1831+
const openApiDocument = generateOpenApiDocument(appRouter, defaultDocOpts);
1832+
const params = openApiDocument.paths!['/docker/getConfig']!.get!.parameters as Array<{
1833+
name: string;
1834+
required?: boolean;
1835+
schema: unknown;
1836+
}>;
1837+
expect(params).toBeDefined();
1838+
const containerIdParam = params.find((p) => p.name === 'containerId');
1839+
const serverIdParam = params.find((p) => p.name === 'serverId');
1840+
expect(containerIdParam).toBeDefined();
1841+
expect(containerIdParam!.required).toBe(true);
1842+
expect(containerIdParam!.schema).toMatchObject({ type: 'string', minLength: 1, pattern: containerIdRegex.source });
1843+
expect(serverIdParam).toBeDefined();
1844+
expect(serverIdParam!.required).not.toBe(true);
1845+
});
1846+
18171847
test('with default', () => {
18181848
const appRouter = t.router({
18191849
default: t.procedure

0 commit comments

Comments
 (0)