Skip to content

Commit 54948ab

Browse files
committed
feat(generator): add interface generation for all content types
- Import getRequestBodyContent helper from generate-schema - Update schema collection pass to use helper for all content types - Update body extraction pass to use helper for all content types - Add raw multipart handling: empty object schema → FormData | Record<string, unknown> - Add 6 new test cases for form/multipart endpoints - All 52 tests pass with 54 snapshots
1 parent 1b4a94c commit 54948ab

File tree

3 files changed

+713
-13
lines changed

3 files changed

+713
-13
lines changed

packages/generator/src/__tests__/__snapshots__/generate-interface.test.ts.snap

Lines changed: 279 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1752,3 +1752,282 @@ declare module "@devup-api/fetch" {
17521752
}
17531753
}"
17541754
`;
1755+
1756+
exports[`generateInterface handles urlencoded request body with $ref 1`] = `
1757+
"import "@devup-api/fetch";
1758+
import type { DevupObject } from "@devup-api/fetch";
1759+
1760+
declare module "@devup-api/fetch" {
1761+
interface DevupApiServers {
1762+
'openapi.json': never
1763+
}
1764+
1765+
interface DevupPostApiStruct {
1766+
'openapi.json': {
1767+
'/form': {
1768+
body: DevupObject<'request', 'openapi.json'>['SubscribeRequest'];
1769+
response?: {
1770+
ok?: boolean;
1771+
};
1772+
};
1773+
subscribe: {
1774+
body: DevupObject<'request', 'openapi.json'>['SubscribeRequest'];
1775+
response?: {
1776+
ok?: boolean;
1777+
};
1778+
};
1779+
}
1780+
}
1781+
1782+
interface DevupRequestComponentStruct {
1783+
'openapi.json': {
1784+
SubscribeRequest: {
1785+
name?: string;
1786+
email?: string;
1787+
};
1788+
}
1789+
}
1790+
1791+
interface DevupResponseComponentStruct {}
1792+
1793+
interface DevupErrorComponentStruct {}
1794+
}"
1795+
`;
1796+
1797+
exports[`generateInterface handles urlencoded request body with inline schema 1`] = `
1798+
"import "@devup-api/fetch";
1799+
import type { DevupObject } from "@devup-api/fetch";
1800+
1801+
declare module "@devup-api/fetch" {
1802+
interface DevupApiServers {
1803+
'openapi.json': never
1804+
}
1805+
1806+
interface DevupPostApiStruct {
1807+
'openapi.json': {
1808+
'/form/contact': {
1809+
body?: {
1810+
name?: string;
1811+
email?: string;
1812+
message?: string;
1813+
};
1814+
response?: {};
1815+
};
1816+
contact: {
1817+
body?: {
1818+
name?: string;
1819+
email?: string;
1820+
message?: string;
1821+
};
1822+
response?: {};
1823+
};
1824+
}
1825+
}
1826+
1827+
interface DevupRequestComponentStruct {}
1828+
1829+
interface DevupResponseComponentStruct {}
1830+
1831+
interface DevupErrorComponentStruct {}
1832+
}"
1833+
`;
1834+
1835+
exports[`generateInterface handles typed multipart request body with $ref 1`] = `
1836+
"import "@devup-api/fetch";
1837+
import type { DevupObject } from "@devup-api/fetch";
1838+
1839+
declare module "@devup-api/fetch" {
1840+
interface DevupApiServers {
1841+
'openapi.json': never
1842+
}
1843+
1844+
interface DevupPostApiStruct {
1845+
'openapi.json': {
1846+
'/typed-form': {
1847+
body: DevupObject<'request', 'openapi.json'>['CreateFileUploadRequest'];
1848+
response?: {
1849+
id?: string;
1850+
};
1851+
};
1852+
createFileUpload: {
1853+
body: DevupObject<'request', 'openapi.json'>['CreateFileUploadRequest'];
1854+
response?: {
1855+
id?: string;
1856+
};
1857+
};
1858+
}
1859+
}
1860+
1861+
interface DevupRequestComponentStruct {
1862+
'openapi.json': {
1863+
CreateFileUploadRequest: {
1864+
name: string;
1865+
document?: File | Blob;
1866+
tags?: Array<string>;
1867+
thumbnail?: File | Blob;
1868+
};
1869+
}
1870+
}
1871+
1872+
interface DevupResponseComponentStruct {}
1873+
1874+
interface DevupErrorComponentStruct {}
1875+
}"
1876+
`;
1877+
1878+
exports[`generateInterface handles raw multipart with empty object schema 1`] = `
1879+
"import "@devup-api/fetch";
1880+
import type { DevupObject } from "@devup-api/fetch";
1881+
1882+
declare module "@devup-api/fetch" {
1883+
interface DevupApiServers {
1884+
'openapi.json': never
1885+
}
1886+
1887+
interface DevupPostApiStruct {
1888+
'openapi.json': {
1889+
'/form/upload': {
1890+
body: FormData | Record<string, unknown>;
1891+
response?: {
1892+
url?: string;
1893+
};
1894+
};
1895+
upload: {
1896+
body: FormData | Record<string, unknown>;
1897+
response?: {
1898+
url?: string;
1899+
};
1900+
};
1901+
}
1902+
}
1903+
1904+
interface DevupRequestComponentStruct {}
1905+
1906+
interface DevupResponseComponentStruct {}
1907+
1908+
interface DevupErrorComponentStruct {}
1909+
}"
1910+
`;
1911+
1912+
exports[`generateInterface handles multipart PUT and PATCH endpoints 1`] = `
1913+
"import "@devup-api/fetch";
1914+
import type { DevupObject } from "@devup-api/fetch";
1915+
1916+
declare module "@devup-api/fetch" {
1917+
interface DevupApiServers {
1918+
'openapi.json': never
1919+
}
1920+
1921+
interface DevupPutApiStruct {
1922+
'openapi.json': {
1923+
'/typed-form/{id}': {
1924+
params: {
1925+
id: string;
1926+
};
1927+
body: DevupObject<'request', 'openapi.json'>['UpdateFileUploadRequest'];
1928+
response?: {};
1929+
};
1930+
updateFileUpload: {
1931+
params: {
1932+
id: string;
1933+
};
1934+
body: DevupObject<'request', 'openapi.json'>['UpdateFileUploadRequest'];
1935+
response?: {};
1936+
};
1937+
}
1938+
}
1939+
1940+
interface DevupPatchApiStruct {
1941+
'openapi.json': {
1942+
'/typed-form/{id}': {
1943+
params: {
1944+
id: string;
1945+
};
1946+
body: DevupObject<'request', 'openapi.json'>['PatchFileUploadRequest'];
1947+
response?: {};
1948+
};
1949+
patchFileUpload: {
1950+
params: {
1951+
id: string;
1952+
};
1953+
body: DevupObject<'request', 'openapi.json'>['PatchFileUploadRequest'];
1954+
response?: {};
1955+
};
1956+
}
1957+
}
1958+
1959+
interface DevupRequestComponentStruct {
1960+
'openapi.json': {
1961+
UpdateFileUploadRequest: {
1962+
name: string;
1963+
document?: File | Blob;
1964+
};
1965+
PatchFileUploadRequest: {
1966+
name?: string;
1967+
document?: File | Blob;
1968+
};
1969+
}
1970+
}
1971+
1972+
interface DevupResponseComponentStruct {}
1973+
1974+
interface DevupErrorComponentStruct {}
1975+
}"
1976+
`;
1977+
1978+
exports[`generateInterface preserves JSON endpoints alongside form/multipart endpoints 1`] = `
1979+
"import "@devup-api/fetch";
1980+
import type { DevupObject } from "@devup-api/fetch";
1981+
1982+
declare module "@devup-api/fetch" {
1983+
interface DevupApiServers {
1984+
'openapi.json': never
1985+
}
1986+
1987+
interface DevupPostApiStruct {
1988+
'openapi.json': {
1989+
'/users': {
1990+
body: DevupObject<'request', 'openapi.json'>['CreateUserRequest'];
1991+
response?: {};
1992+
};
1993+
createUser: {
1994+
body: DevupObject<'request', 'openapi.json'>['CreateUserRequest'];
1995+
response?: {};
1996+
};
1997+
'/form': {
1998+
body: DevupObject<'request', 'openapi.json'>['SubscribeRequest'];
1999+
response?: {};
2000+
};
2001+
subscribe: {
2002+
body: DevupObject<'request', 'openapi.json'>['SubscribeRequest'];
2003+
response?: {};
2004+
};
2005+
'/form/upload': {
2006+
body: FormData | Record<string, unknown>;
2007+
response?: {};
2008+
};
2009+
upload: {
2010+
body: FormData | Record<string, unknown>;
2011+
response?: {};
2012+
};
2013+
}
2014+
}
2015+
2016+
interface DevupRequestComponentStruct {
2017+
'openapi.json': {
2018+
CreateUserRequest: {
2019+
name?: string;
2020+
email?: string;
2021+
};
2022+
SubscribeRequest: {
2023+
name?: string;
2024+
email?: string;
2025+
};
2026+
}
2027+
}
2028+
2029+
interface DevupResponseComponentStruct {}
2030+
2031+
interface DevupErrorComponentStruct {}
2032+
}"
2033+
`;

0 commit comments

Comments
 (0)