WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Commit efd94e5

Browse files
authored
added test for ref strategy (#108)
1 parent d98f5b8 commit efd94e5

File tree

1 file changed

+101
-0
lines changed

1 file changed

+101
-0
lines changed

test/generator.test.ts

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2024,4 +2024,105 @@ describe('generator', () => {
20242024
`);
20252025
}
20262026
});
2027+
2028+
test('with no refs', () => {
2029+
const schemas = { emails: z.array(z.string().email()) };
2030+
2031+
const appRouter = trpc.router<any, OpenApiMeta>().mutation('refs', {
2032+
meta: { openapi: { enabled: true, method: 'POST', path: '/refs' } },
2033+
input: z.object({ allowed: schemas.emails, blocked: schemas.emails }),
2034+
output: z.object({ allowed: schemas.emails, blocked: schemas.emails }),
2035+
resolve: () => ({ allowed: [], blocked: [] }),
2036+
});
2037+
2038+
const openApiDocument = generateOpenApiDocument(appRouter, {
2039+
title: 'tRPC OpenAPI',
2040+
version: '1.0.0',
2041+
baseUrl: 'http://localhost:3000/api',
2042+
});
2043+
2044+
expect(openApiSchemaValidator.validate(openApiDocument).errors).toEqual([]);
2045+
expect(openApiDocument.paths['/refs']!.post!.requestBody).toMatchInlineSnapshot(`
2046+
Object {
2047+
"content": Object {
2048+
"application/json": Object {
2049+
"schema": Object {
2050+
"additionalProperties": false,
2051+
"properties": Object {
2052+
"allowed": Object {
2053+
"items": Object {
2054+
"format": "email",
2055+
"type": "string",
2056+
},
2057+
"type": "array",
2058+
},
2059+
"blocked": Object {
2060+
"items": Object {
2061+
"format": "email",
2062+
"type": "string",
2063+
},
2064+
"type": "array",
2065+
},
2066+
},
2067+
"required": Array [
2068+
"allowed",
2069+
"blocked",
2070+
],
2071+
"type": "object",
2072+
},
2073+
},
2074+
},
2075+
"required": true,
2076+
}
2077+
`);
2078+
expect(openApiDocument.paths['/refs']!.post!.responses[200]).toMatchInlineSnapshot(`
2079+
Object {
2080+
"content": Object {
2081+
"application/json": Object {
2082+
"schema": Object {
2083+
"additionalProperties": false,
2084+
"properties": Object {
2085+
"data": Object {
2086+
"additionalProperties": false,
2087+
"properties": Object {
2088+
"allowed": Object {
2089+
"items": Object {
2090+
"format": "email",
2091+
"type": "string",
2092+
},
2093+
"type": "array",
2094+
},
2095+
"blocked": Object {
2096+
"items": Object {
2097+
"format": "email",
2098+
"type": "string",
2099+
},
2100+
"type": "array",
2101+
},
2102+
},
2103+
"required": Array [
2104+
"allowed",
2105+
"blocked",
2106+
],
2107+
"type": "object",
2108+
},
2109+
"ok": Object {
2110+
"enum": Array [
2111+
true,
2112+
],
2113+
"type": "boolean",
2114+
},
2115+
},
2116+
"required": Array [
2117+
"ok",
2118+
"data",
2119+
],
2120+
"type": "object",
2121+
},
2122+
},
2123+
},
2124+
"description": "Successful response",
2125+
}
2126+
`);
2127+
});
20272128
});

0 commit comments

Comments
 (0)