Skip to content

Commit 4c35b82

Browse files
committed
Add test
1 parent 10956a5 commit 4c35b82

File tree

2 files changed

+146
-0
lines changed

2 files changed

+146
-0
lines changed

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

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1714,6 +1714,75 @@ declare module "@devup-api/fetch" {
17141714
}"
17151715
`;
17161716

1717+
exports[`generateInterface handles response with non-JSON content type only 1`] = `
1718+
"import "@devup-api/fetch";
1719+
import type { DevupObject } from "@devup-api/fetch";
1720+
1721+
declare module "@devup-api/fetch" {
1722+
interface DevupApiServers {
1723+
'openapi.json': never
1724+
}
1725+
1726+
interface DevupGetApiStruct {
1727+
'openapi.json': {
1728+
'/files/{id}': {
1729+
params: {
1730+
id: string;
1731+
};
1732+
};
1733+
downloadFile: {
1734+
params: {
1735+
id: string;
1736+
};
1737+
};
1738+
}
1739+
}
1740+
1741+
interface DevupRequestComponentStruct {}
1742+
1743+
interface DevupResponseComponentStruct {}
1744+
1745+
interface DevupErrorComponentStruct {}
1746+
}"
1747+
`;
1748+
1749+
exports[`generateInterface handles response schema with inline enum 1`] = `
1750+
"import "@devup-api/fetch";
1751+
import type { DevupObject } from "@devup-api/fetch";
1752+
1753+
declare module "@devup-api/fetch" {
1754+
type ItemResponseStatus = "active" | "inactive" | "archived"
1755+
1756+
interface DevupApiServers {
1757+
'openapi.json': never
1758+
}
1759+
1760+
interface DevupGetApiStruct {
1761+
'openapi.json': {
1762+
'/items': {
1763+
response: DevupObject<'response', 'openapi.json'>['ItemResponse'];
1764+
};
1765+
listItems: {
1766+
response: DevupObject<'response', 'openapi.json'>['ItemResponse'];
1767+
};
1768+
}
1769+
}
1770+
1771+
interface DevupRequestComponentStruct {}
1772+
1773+
interface DevupResponseComponentStruct {
1774+
'openapi.json': {
1775+
ItemResponse: {
1776+
name?: string;
1777+
status?: ItemResponseStatus;
1778+
};
1779+
}
1780+
}
1781+
1782+
interface DevupErrorComponentStruct {}
1783+
}"
1784+
`;
1785+
17171786
exports[`generateInterface handles error schema with inline enum 1`] = `
17181787
"import "@devup-api/fetch";
17191788
import type { DevupObject } from "@devup-api/fetch";

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

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2003,6 +2003,83 @@ test('generateInterface handles request schema with inline enum', () => {
20032003
})
20042004

20052005
// Test error schema with inline enum (lines 705-707 coverage)
2006+
test('generateInterface handles response with non-JSON content type only', () => {
2007+
const schema = {
2008+
paths: {
2009+
'/files/{id}': {
2010+
get: {
2011+
operationId: 'downloadFile',
2012+
parameters: [
2013+
{
2014+
name: 'id',
2015+
in: 'path',
2016+
required: true,
2017+
schema: { type: 'string' },
2018+
},
2019+
],
2020+
responses: {
2021+
'200': {
2022+
description: 'File content',
2023+
content: {
2024+
'text/plain': {
2025+
schema: { type: 'string' },
2026+
},
2027+
},
2028+
},
2029+
},
2030+
},
2031+
},
2032+
},
2033+
}
2034+
const result = generateInterface(createSchemas(createDocument(schema as any)))
2035+
expect(result).toMatchSnapshot()
2036+
// Should not have a typed response since there's no application/json
2037+
expect(result).not.toContain("DevupObject<'response'")
2038+
})
2039+
2040+
test('generateInterface handles response schema with inline enum', () => {
2041+
const schema = {
2042+
paths: {
2043+
'/items': {
2044+
get: {
2045+
operationId: 'listItems',
2046+
responses: {
2047+
'200': {
2048+
description: 'Success',
2049+
content: {
2050+
'application/json': {
2051+
schema: {
2052+
$ref: '#/components/schemas/ItemResponse',
2053+
},
2054+
},
2055+
},
2056+
},
2057+
},
2058+
},
2059+
},
2060+
},
2061+
components: {
2062+
schemas: {
2063+
ItemResponse: {
2064+
type: 'object',
2065+
properties: {
2066+
name: { type: 'string' },
2067+
status: {
2068+
type: 'string',
2069+
enum: ['active', 'inactive', 'archived'],
2070+
},
2071+
},
2072+
},
2073+
},
2074+
},
2075+
}
2076+
const result = generateInterface(createSchemas(createDocument(schema as any)))
2077+
expect(result).toMatchSnapshot()
2078+
// Inline enum in response schema should generate type alias
2079+
expect(result).toContain('type ItemResponseStatus =')
2080+
expect(result).toContain('"active"')
2081+
})
2082+
20062083
test('generateInterface handles error schema with inline enum', () => {
20072084
const schema = {
20082085
paths: {

0 commit comments

Comments
 (0)