From f1c0188b590957cf6c22617994033f3097f33447 Mon Sep 17 00:00:00 2001 From: owjs3901 Date: Wed, 17 Dec 2025 00:07:05 +0900 Subject: [PATCH] Add skill --- SKILL.md | 106 + .../generate-interface.test.ts.snap | 3426 ++++++++--------- 2 files changed, 1819 insertions(+), 1713 deletions(-) create mode 100644 SKILL.md diff --git a/SKILL.md b/SKILL.md new file mode 100644 index 0000000..987a342 --- /dev/null +++ b/SKILL.md @@ -0,0 +1,106 @@ +--- +name: devup-api +description: A tool for generating fully typed API clients from OpenAPI schemas. It offers a fetch-compatible API, auto-generated types without generics, and integrates with major build tools like Vite, Next.js, and Webpack. +--- + +# devup-api + +This skill helps you invoke the `devup-api` library to generate and use fully typed API clients in your TypeScript projects. `devup-api` reads your `openapi.json` and automatically generates a type-safe client that feels like `fetch` but with strict typing for paths, parameters, bodies, and responses. + +## Key Features + +- **OpenAPI-driven:** Generates types directly from `openapi.json`. +- **Fetch-compatible:** Ergonomic API similar to standard `fetch`. +- **Zero Generics:** No complex generic types to manage manually. +- **Build Tool Integration:** Plugins for Vite, Next.js, Webpack, and Rsbuild. +- **Two-phase Typing:** "Cold Typing" (relaxed types for initial setup) and "Bold Typing" (strict types after generation). + +## Usage Instructions + +### 1. Installation + +Install the core fetch package and the plugin for your build tool: + +```bash +npm install @devup-api/fetch @devup-api/vite-plugin # For Vite +# OR +npm install @devup-api/fetch @devup-api/next-plugin # For Next.js +# See README for Webpack and Rsbuild +``` + +### 2. Configuration + +Add the plugin to your build configuration (e.g., `vite.config.ts`, `next.config.ts`). + +**Vite Example:** +```ts +import { defineConfig } from 'vite' +import devupApi from '@devup-api/vite-plugin' + +export default defineConfig({ + plugins: [devupApi()], +}) +``` + +### 3. TypeScript Setup + +Include the generated types in your `tsconfig.json`: + +```json +{ + "include": [ + "src", + "df/**/*.d.ts" + ] +} +``` +*Note: `df` is the default temporary directory.* + +### 4. Create and Use Client + +```ts +import { createApi } from '@devup-api/fetch' + +// Initialize +const api = createApi('https://api.example.com') + +// GET Request (using operationId or path) +const users = await api.get('getUsers', { query: { page: 1 } }) +// OR +const user = await api.get('/users/{id}', { params: { id: '123' } }) + +// POST Request +const newUser = await api.post('createUser', { + body: { name: 'Alice', email: 'alice@example.com' } +}) +``` + +## Examples + +### Complete Workflow + +1. **Project Setup:** Ensure `openapi.json` is in your project root. +2. **Configure:** Add `devup-api/vite-plugin` to `vite.config.ts`. +3. **Run:** Run `npm run dev` or `npm run build`. This generates `df/api.d.ts`. +4. **Code:** Use `createApi` to make requests. IntelliSense will now show available paths and required parameters. + +### Handling Responses + +`devup-api` returns an object with either `data` (success) or `error` (failure). + +```ts +const response = await api.get('getUser', { params: { id: '1' } }) + +if (response.data) { + console.log('User Name:', response.data.name) +} else if (response.error) { + console.error('Error:', response.error.message) +} +``` + +## Guidelines + +- **"Cold" vs "Bold" Typing:** When you first start, types might be `any` (Cold Typing). Run your build command (`dev` or `build`) to generate the types and enable strict checking (Bold Typing). +- **Operation IDs vs Paths:** You can use either the OpenAPI `operationId` (e.g., `getUsers`) or the URL path (e.g., `/users`). `operationId` is often more concise. +- **Generated Files:** Do not manually edit the files in the `df` (or configured temp) directory. They are auto-generated. +- **Verification:** If types seem missing, ensure `tsconfig.json` includes the generated folder and that the build script has run at least once. diff --git a/packages/generator/src/__tests__/__snapshots__/generate-interface.test.ts.snap b/packages/generator/src/__tests__/__snapshots__/generate-interface.test.ts.snap index c4dca56..57a5a14 100644 --- a/packages/generator/src/__tests__/__snapshots__/generate-interface.test.ts.snap +++ b/packages/generator/src/__tests__/__snapshots__/generate-interface.test.ts.snap @@ -1,1713 +1,1713 @@ -// Bun Snapshot v1, https://bun.sh/docs/test/snapshots - -exports[`generateInterface returns interface for schema: %s 1`] = ` -"import "@devup-api/fetch"; - -declare module "@devup-api/fetch" { - interface DevupApiServers { - [\`openapi.json\`]: never - } - - interface DevupGetApiStruct { - [\`openapi.json\`]: { - [\`/users\`]: {}; - getUsers: {}; - } - } - - interface DevupRequestComponentStruct {} - - interface DevupResponseComponentStruct {} - - interface DevupErrorComponentStruct {} -}" -`; - -exports[`generateInterface returns interface for schema: %s 2`] = ` -"import "@devup-api/fetch"; - -declare module "@devup-api/fetch" { - interface DevupApiServers { - [\`openapi.json\`]: never - } - - interface DevupGetApiStruct { - [\`openapi.json\`]: { - [\`/users\`]: {}; - GetUsers: {}; - } - } - - interface DevupRequestComponentStruct {} - - interface DevupResponseComponentStruct {} - - interface DevupErrorComponentStruct {} -}" -`; - -exports[`generateInterface returns interface for schema: %s 3`] = ` -"import "@devup-api/fetch"; - -declare module "@devup-api/fetch" { - interface DevupApiServers { - [\`openapi.json\`]: never - } - - interface DevupGetApiStruct { - [\`openapi.json\`]: { - [\`/users\`]: {}; - get_users: {}; - } - } - - interface DevupRequestComponentStruct {} - - interface DevupResponseComponentStruct {} - - interface DevupErrorComponentStruct {} -}" -`; - -exports[`generateInterface returns interface for schema: %s 4`] = ` -"import "@devup-api/fetch"; - -declare module "@devup-api/fetch" { - interface DevupApiServers { - [\`openapi.json\`]: never - } - - interface DevupGetApiStruct { - [\`openapi.json\`]: { - [\`/users\`]: {}; - getUsers: {}; - } - } - - interface DevupRequestComponentStruct {} - - interface DevupResponseComponentStruct {} - - interface DevupErrorComponentStruct {} -}" -`; - -exports[`generateInterface returns interface for schema: %s 5`] = ` -"import "@devup-api/fetch"; - -declare module "@devup-api/fetch" { - interface DevupApiServers { - [\`openapi.json\`]: never - } - - interface DevupGetApiStruct { - [\`openapi.json\`]: { - [\`/users\`]: {}; - getUsers: {}; - } - } - - interface DevupRequestComponentStruct {} - - interface DevupResponseComponentStruct {} - - interface DevupErrorComponentStruct {} -}" -`; - -exports[`generateInterface returns interface for schema: %s 6`] = ` -"import "@devup-api/fetch"; - -declare module "@devup-api/fetch" { - interface DevupApiServers { - [\`openapi.json\`]: never - } - - interface DevupGetApiStruct { - [\`openapi.json\`]: { - [\`/users\`]: { - response: Array; - }; - getUsers: { - response: Array; - }; - } - } - - interface DevupPostApiStruct { - [\`openapi.json\`]: { - [\`/users\`]: { - response: DevupResponseComponentStruct['openapi.json']['User']; - }; - createUser: { - response: DevupResponseComponentStruct['openapi.json']['User']; - }; - } - } - - interface DevupRequestComponentStruct {} - - interface DevupResponseComponentStruct { - [\`openapi.json\`]: { - User: { - id?: string; - name?: string; - }; - } - } - - interface DevupErrorComponentStruct {} -}" -`; - -exports[`generateInterface returns interface for schema: %s 7`] = ` -"import "@devup-api/fetch"; - -declare module "@devup-api/fetch" { - interface DevupApiServers { - [\`openapi.json\`]: never - } - - interface DevupGetApiStruct { - [\`openapi.json\`]: { - [\`/users\`]: { - response: Array; - }; - GetUsers: { - response: Array; - }; - } - } - - interface DevupPostApiStruct { - [\`openapi.json\`]: { - [\`/users\`]: { - response: DevupResponseComponentStruct['openapi.json']['User']; - }; - CreateUser: { - response: DevupResponseComponentStruct['openapi.json']['User']; - }; - } - } - - interface DevupRequestComponentStruct {} - - interface DevupResponseComponentStruct { - [\`openapi.json\`]: { - User: { - id?: string; - name?: string; - }; - } - } - - interface DevupErrorComponentStruct {} -}" -`; - -exports[`generateInterface returns interface for schema: %s 8`] = ` -"import "@devup-api/fetch"; - -declare module "@devup-api/fetch" { - interface DevupApiServers { - [\`openapi.json\`]: never - } - - interface DevupGetApiStruct { - [\`openapi.json\`]: { - [\`/users\`]: { - response: Array; - }; - get_users: { - response: Array; - }; - } - } - - interface DevupPostApiStruct { - [\`openapi.json\`]: { - [\`/users\`]: { - response: DevupResponseComponentStruct['openapi.json']['User']; - }; - create_user: { - response: DevupResponseComponentStruct['openapi.json']['User']; - }; - } - } - - interface DevupRequestComponentStruct {} - - interface DevupResponseComponentStruct { - [\`openapi.json\`]: { - User: { - id?: string; - name?: string; - }; - } - } - - interface DevupErrorComponentStruct {} -}" -`; - -exports[`generateInterface returns interface for schema: %s 9`] = ` -"import "@devup-api/fetch"; - -declare module "@devup-api/fetch" { - interface DevupApiServers { - [\`openapi.json\`]: never - } - - interface DevupGetApiStruct { - [\`openapi.json\`]: { - [\`/users\`]: { - response: Array; - }; - getUsers: { - response: Array; - }; - } - } - - interface DevupPostApiStruct { - [\`openapi.json\`]: { - [\`/users\`]: { - response: DevupResponseComponentStruct['openapi.json']['User']; - }; - createUser: { - response: DevupResponseComponentStruct['openapi.json']['User']; - }; - } - } - - interface DevupRequestComponentStruct {} - - interface DevupResponseComponentStruct { - [\`openapi.json\`]: { - User: { - id?: string; - name?: string; - }; - } - } - - interface DevupErrorComponentStruct {} -}" -`; - -exports[`generateInterface returns interface for schema: %s 10`] = ` -"import "@devup-api/fetch"; - -declare module "@devup-api/fetch" { - interface DevupApiServers { - [\`openapi.json\`]: never - } - - interface DevupGetApiStruct { - [\`openapi.json\`]: { - [\`/users\`]: { - response: Array; - }; - getUsers: { - response: Array; - }; - } - } - - interface DevupPostApiStruct { - [\`openapi.json\`]: { - [\`/users\`]: { - response: DevupResponseComponentStruct['openapi.json']['User']; - }; - createUser: { - response: DevupResponseComponentStruct['openapi.json']['User']; - }; - } - } - - interface DevupRequestComponentStruct {} - - interface DevupResponseComponentStruct { - [\`openapi.json\`]: { - User: { - id?: string; - name?: string; - }; - } - } - - interface DevupErrorComponentStruct {} -}" -`; - -exports[`generateInterface handles all HTTP methods 1`] = ` -"import "@devup-api/fetch"; - -declare module "@devup-api/fetch" { - interface DevupApiServers { - [\`openapi.json\`]: never - } - - interface DevupGetApiStruct { - [\`openapi.json\`]: { - [\`/users\`]: { - response?: {}; - }; - getUsers: { - response?: {}; - }; - } - } - - interface DevupPostApiStruct { - [\`openapi.json\`]: { - [\`/users\`]: { - response?: {}; - }; - createUser: { - response?: {}; - }; - } - } - - interface DevupPutApiStruct { - [\`openapi.json\`]: { - [\`/users\`]: { - response?: {}; - }; - updateUser: { - response?: {}; - }; - } - } - - interface DevupDeleteApiStruct { - [\`openapi.json\`]: { - [\`/users\`]: {}; - deleteUser: {}; - } - } - - interface DevupPatchApiStruct { - [\`openapi.json\`]: { - [\`/users\`]: { - response?: {}; - }; - patchUser: { - response?: {}; - }; - } - } - - interface DevupRequestComponentStruct {} - - interface DevupResponseComponentStruct {} - - interface DevupErrorComponentStruct {} -}" -`; - -exports[`generateInterface handles path parameters 1`] = ` -"import "@devup-api/fetch"; - -declare module "@devup-api/fetch" { - interface DevupApiServers { - [\`openapi.json\`]: never - } - - interface DevupGetApiStruct { - [\`openapi.json\`]: { - [\`/users/{userId}\`]: { - params: { - userId: string; - }; - response?: {}; - }; - getUser: { - params: { - userId: string; - }; - response?: {}; - }; - } - } - - interface DevupRequestComponentStruct {} - - interface DevupResponseComponentStruct {} - - interface DevupErrorComponentStruct {} -}" -`; - -exports[`generateInterface handles query parameters 1`] = ` -"import "@devup-api/fetch"; - -declare module "@devup-api/fetch" { - interface DevupApiServers { - [\`openapi.json\`]: never - } - - interface DevupGetApiStruct { - [\`openapi.json\`]: { - [\`/users\`]: { - query: { - page?: number; - limit: number; - }; - response?: {}; - }; - getUsers: { - query: { - page?: number; - limit: number; - }; - response?: {}; - }; - } - } - - interface DevupRequestComponentStruct {} - - interface DevupResponseComponentStruct {} - - interface DevupErrorComponentStruct {} -}" -`; - -exports[`generateInterface handles path and query parameters together 1`] = ` -"import "@devup-api/fetch"; - -declare module "@devup-api/fetch" { - interface DevupApiServers { - [\`openapi.json\`]: never - } - - interface DevupGetApiStruct { - [\`openapi.json\`]: { - [\`/users/{userId}/posts\`]: { - params: { - userId: string; - }; - query?: { - page?: number; - }; - response?: {}; - }; - getUserPosts: { - params: { - userId: string; - }; - query?: { - page?: number; - }; - response?: {}; - }; - } - } - - interface DevupRequestComponentStruct {} - - interface DevupResponseComponentStruct {} - - interface DevupErrorComponentStruct {} -}" -`; - -exports[`generateInterface handles request body 1`] = ` -"import "@devup-api/fetch"; - -declare module "@devup-api/fetch" { - interface DevupApiServers { - [\`openapi.json\`]: never - } - - interface DevupPostApiStruct { - [\`openapi.json\`]: { - [\`/users\`]: { - body?: { - name?: string; - email?: string; - }; - response?: {}; - }; - createUser: { - body?: { - name?: string; - email?: string; - }; - response?: {}; - }; - } - } - - interface DevupRequestComponentStruct {} - - interface DevupResponseComponentStruct {} - - interface DevupErrorComponentStruct {} -}" -`; - -exports[`generateInterface handles request body with $ref 1`] = ` -"import "@devup-api/fetch"; - -declare module "@devup-api/fetch" { - interface DevupApiServers { - [\`openapi.json\`]: never - } - - interface DevupPostApiStruct { - [\`openapi.json\`]: { - [\`/users\`]: { - body: DevupRequestComponentStruct['openapi.json']['User']; - response?: {}; - }; - createUser: { - body: DevupRequestComponentStruct['openapi.json']['User']; - response?: {}; - }; - } - } - - interface DevupRequestComponentStruct { - [\`openapi.json\`]: { - User: { - name?: string; - email?: string; - }; - } - } - - interface DevupResponseComponentStruct {} - - interface DevupErrorComponentStruct {} -}" -`; - -exports[`generateInterface handles 200 response 1`] = ` -"import "@devup-api/fetch"; - -declare module "@devup-api/fetch" { - interface DevupApiServers { - [\`openapi.json\`]: never - } - - interface DevupGetApiStruct { - [\`openapi.json\`]: { - [\`/users\`]: { - response: Array; - }; - getUsers: { - response: Array; - }; - } - } - - interface DevupRequestComponentStruct {} - - interface DevupResponseComponentStruct { - [\`openapi.json\`]: { - User: { - id?: string; - name?: string; - }; - } - } - - interface DevupErrorComponentStruct {} -}" -`; - -exports[`generateInterface handles 201 response 1`] = ` -"import "@devup-api/fetch"; - -declare module "@devup-api/fetch" { - interface DevupApiServers { - [\`openapi.json\`]: never - } - - interface DevupPostApiStruct { - [\`openapi.json\`]: { - [\`/users\`]: { - response: DevupResponseComponentStruct['openapi.json']['User']; - }; - createUser: { - response: DevupResponseComponentStruct['openapi.json']['User']; - }; - } - } - - interface DevupRequestComponentStruct {} - - interface DevupResponseComponentStruct { - [\`openapi.json\`]: { - User: { - id?: string; - name?: string; - }; - } - } - - interface DevupErrorComponentStruct {} -}" -`; - -exports[`generateInterface handles response with other status codes 1`] = ` -"import "@devup-api/fetch"; - -declare module "@devup-api/fetch" { - interface DevupApiServers { - [\`openapi.json\`]: never - } - - interface DevupGetApiStruct { - [\`openapi.json\`]: { - [\`/users\`]: { - response?: { - message?: string; - }; - }; - getUsers: { - response?: { - message?: string; - }; - }; - } - } - - interface DevupRequestComponentStruct {} - - interface DevupResponseComponentStruct {} - - interface DevupErrorComponentStruct {} -}" -`; - -exports[`generateInterface handles error responses 1`] = ` -"import "@devup-api/fetch"; - -declare module "@devup-api/fetch" { - interface DevupApiServers { - [\`openapi.json\`]: never - } - - interface DevupGetApiStruct { - [\`openapi.json\`]: { - [\`/users\`]: { - response?: {}; - error?: { - error?: string; - }; - }; - getUsers: { - response?: {}; - error?: { - error?: string; - }; - }; - } - } - - interface DevupRequestComponentStruct {} - - interface DevupResponseComponentStruct {} - - interface DevupErrorComponentStruct { - [\`openapi.json\`]: { - Error: { - code?: string; - message?: string; - }; - } - } -}" -`; - -exports[`generateInterface handles default error response 1`] = ` -"import "@devup-api/fetch"; - -declare module "@devup-api/fetch" { - interface DevupApiServers { - [\`openapi.json\`]: never - } - - interface DevupGetApiStruct { - [\`openapi.json\`]: { - [\`/users\`]: { - response?: {}; - error?: { - error?: string; - }; - }; - getUsers: { - response?: {}; - error?: { - error?: string; - }; - }; - } - } - - interface DevupRequestComponentStruct {} - - interface DevupResponseComponentStruct {} - - interface DevupErrorComponentStruct {} -}" -`; - -exports[`generateInterface handles component schemas for request 1`] = ` -"import "@devup-api/fetch"; - -declare module "@devup-api/fetch" { - interface DevupApiServers { - [\`openapi.json\`]: never - } - - interface DevupPostApiStruct { - [\`openapi.json\`]: { - [\`/users\`]: { - body: DevupRequestComponentStruct['openapi.json']['CreateUserRequest']; - response?: {}; - }; - createUser: { - body: DevupRequestComponentStruct['openapi.json']['CreateUserRequest']; - response?: {}; - }; - } - } - - interface DevupRequestComponentStruct { - [\`openapi.json\`]: { - CreateUserRequest: { - name?: string; - email?: string; - }; - } - } - - interface DevupResponseComponentStruct {} - - interface DevupErrorComponentStruct {} -}" -`; - -exports[`generateInterface handles component schemas for response 1`] = ` -"import "@devup-api/fetch"; - -declare module "@devup-api/fetch" { - interface DevupApiServers { - [\`openapi.json\`]: never - } - - interface DevupGetApiStruct { - [\`openapi.json\`]: { - [\`/users\`]: { - response: DevupResponseComponentStruct['openapi.json']['User']; - }; - getUsers: { - response: DevupResponseComponentStruct['openapi.json']['User']; - }; - } - } - - interface DevupRequestComponentStruct {} - - interface DevupResponseComponentStruct { - [\`openapi.json\`]: { - User: { - id?: string; - name?: string; - }; - } - } - - interface DevupErrorComponentStruct {} -}" -`; - -exports[`generateInterface handles component schemas for error 1`] = ` -"import "@devup-api/fetch"; - -declare module "@devup-api/fetch" { - interface DevupApiServers { - [\`openapi.json\`]: never - } - - interface DevupGetApiStruct { - [\`openapi.json\`]: { - [\`/users\`]: { - response?: {}; - error: DevupErrorComponentStruct['Error']; - }; - getUsers: { - response?: {}; - error: DevupErrorComponentStruct['Error']; - }; - } - } - - interface DevupRequestComponentStruct {} - - interface DevupResponseComponentStruct {} - - interface DevupErrorComponentStruct { - [\`openapi.json\`]: { - Error: { - code?: string; - message?: string; - }; - } - } -}" -`; - -exports[`generateInterface handles array response with component schema 1`] = ` -"import "@devup-api/fetch"; - -declare module "@devup-api/fetch" { - interface DevupApiServers { - [\`openapi.json\`]: never - } - - interface DevupGetApiStruct { - [\`openapi.json\`]: { - [\`/users\`]: { - response: Array; - }; - getUsers: { - response: Array; - }; - } - } - - interface DevupRequestComponentStruct {} - - interface DevupResponseComponentStruct { - [\`openapi.json\`]: { - User: { - id?: string; - name?: string; - }; - } - } - - interface DevupErrorComponentStruct {} -}" -`; - -exports[`generateInterface creates both operationId and path keys 1`] = ` -"import "@devup-api/fetch"; - -declare module "@devup-api/fetch" { - interface DevupApiServers { - [\`openapi.json\`]: never - } - - interface DevupGetApiStruct { - [\`openapi.json\`]: { - [\`/users/{userId}\`]: { - params: { - userId: string; - }; - response?: {}; - }; - getUserById: { - params: { - userId: string; - }; - response?: {}; - }; - } - } - - interface DevupRequestComponentStruct {} - - interface DevupResponseComponentStruct {} - - interface DevupErrorComponentStruct {} -}" -`; - -exports[`generateInterface handles endpoints without operationId 1`] = ` -"import "@devup-api/fetch"; - -declare module "@devup-api/fetch" { - interface DevupApiServers { - [\`openapi.json\`]: never - } - - interface DevupGetApiStruct { - [\`openapi.json\`]: { - [\`/users\`]: { - response?: {}; - }; - } - } - - interface DevupRequestComponentStruct {} - - interface DevupResponseComponentStruct {} - - interface DevupErrorComponentStruct {} -}" -`; - -exports[`generateInterface handles requestDefaultNonNullable option 1`] = ` -"import "@devup-api/fetch"; - -declare module "@devup-api/fetch" { - interface DevupApiServers { - [\`openapi.json\`]: never - } - - interface DevupPostApiStruct { - [\`openapi.json\`]: { - [\`/users\`]: { - body?: { - name?: string; - email?: string; - }; - response?: {}; - }; - createUser: { - body?: { - name?: string; - email?: string; - }; - response?: {}; - }; - } - } - - interface DevupRequestComponentStruct {} - - interface DevupResponseComponentStruct {} - - interface DevupErrorComponentStruct {} -}" -`; - -exports[`generateInterface handles requestDefaultNonNullable option 2`] = ` -"import "@devup-api/fetch"; - -declare module "@devup-api/fetch" { - interface DevupApiServers { - [\`openapi.json\`]: never - } - - interface DevupPostApiStruct { - [\`openapi.json\`]: { - [\`/users\`]: { - body?: { - name?: string; - email?: string; - }; - response?: {}; - }; - createUser: { - body?: { - name?: string; - email?: string; - }; - response?: {}; - }; - } - } - - interface DevupRequestComponentStruct {} - - interface DevupResponseComponentStruct {} - - interface DevupErrorComponentStruct {} -}" -`; - -exports[`generateInterface handles responseDefaultNonNullable option 1`] = ` -"import "@devup-api/fetch"; - -declare module "@devup-api/fetch" { - interface DevupApiServers { - [\`openapi.json\`]: never - } - - interface DevupGetApiStruct { - [\`openapi.json\`]: { - [\`/users\`]: { - response: { - id: string; - name?: string; - }; - }; - getUsers: { - response: { - id: string; - name?: string; - }; - }; - } - } - - interface DevupRequestComponentStruct {} - - interface DevupResponseComponentStruct {} - - interface DevupErrorComponentStruct {} -}" -`; - -exports[`generateInterface handles responseDefaultNonNullable option 2`] = ` -"import "@devup-api/fetch"; - -declare module "@devup-api/fetch" { - interface DevupApiServers { - [\`openapi.json\`]: never - } - - interface DevupGetApiStruct { - [\`openapi.json\`]: { - [\`/users\`]: { - response?: { - id?: string; - name?: string; - }; - }; - getUsers: { - response?: { - id?: string; - name?: string; - }; - }; - } - } - - interface DevupRequestComponentStruct {} - - interface DevupResponseComponentStruct {} - - interface DevupErrorComponentStruct {} -}" -`; - -exports[`generateInterface handles nested schemas in allOf 1`] = ` -"import "@devup-api/fetch"; - -declare module "@devup-api/fetch" { - interface DevupApiServers { - [\`openapi.json\`]: never - } - - interface DevupGetApiStruct { - [\`openapi.json\`]: { - [\`/users\`]: { - response: { - id?: string; -} & { - extra?: string; -}; - }; - getUsers: { - response: { - id?: string; -} & { - extra?: string; -}; - }; - } - } - - interface DevupRequestComponentStruct {} - - interface DevupResponseComponentStruct { - [\`openapi.json\`]: { - Base: { - id?: string; - }; - } - } - - interface DevupErrorComponentStruct {} -}" -`; - -exports[`generateInterface handles empty paths 1`] = ` -"import "@devup-api/fetch"; - -declare module "@devup-api/fetch" { - interface DevupApiServers { - [\`openapi.json\`]: never - } - - interface DevupRequestComponentStruct {} - - interface DevupResponseComponentStruct {} - - interface DevupErrorComponentStruct {} -}" -`; - -exports[`generateInterface handles pathItem parameters 1`] = ` -"import "@devup-api/fetch"; - -declare module "@devup-api/fetch" { - interface DevupApiServers { - [\`openapi.json\`]: never - } - - interface DevupGetApiStruct { - [\`openapi.json\`]: { - [\`/users/{userId}\`]: { - params: { - userId: string; - }; - response?: {}; - }; - getUser: { - params: { - userId: string; - }; - response?: {}; - }; - } - } - - interface DevupRequestComponentStruct {} - - interface DevupResponseComponentStruct {} - - interface DevupErrorComponentStruct {} -}" -`; - -exports[`generateInterface handles requestBody $ref 1`] = ` -"import "@devup-api/fetch"; - -declare module "@devup-api/fetch" { - interface DevupApiServers { - [\`openapi.json\`]: never - } - - interface DevupPostApiStruct { - [\`openapi.json\`]: { - [\`/users\`]: { - body?: { - name?: string; - }; - response?: {}; - }; - createUser: { - body?: { - name?: string; - }; - response?: {}; - }; - } - } - - interface DevupRequestComponentStruct {} - - interface DevupResponseComponentStruct {} - - interface DevupErrorComponentStruct {} -}" -`; - -exports[`generateInterface handles response $ref 1`] = ` -"import "@devup-api/fetch"; - -declare module "@devup-api/fetch" { - interface DevupApiServers { - [\`openapi.json\`]: never - } - - interface DevupGetApiStruct { - [\`openapi.json\`]: { - [\`/users\`]: {}; - getUsers: {}; - } - } - - interface DevupRequestComponentStruct {} - - interface DevupResponseComponentStruct {} - - interface DevupErrorComponentStruct {} -}" -`; - -exports[`generateInterface handles complex scenario with all features 1`] = ` -"import "@devup-api/fetch"; - -declare module "@devup-api/fetch" { - interface DevupApiServers { - [\`openapi.json\`]: never - } - - interface DevupGetApiStruct { - [\`openapi.json\`]: { - [\`/users/{userId}/posts/{postId}\`]: { - params: { - userId: string; - postId: string; - }; - query?: { - include?: string; - }; - response: DevupResponseComponentStruct['openapi.json']['Post']; - error: DevupErrorComponentStruct['Error']; - }; - getUserPost: { - params: { - userId: string; - postId: string; - }; - query?: { - include?: string; - }; - response: DevupResponseComponentStruct['openapi.json']['Post']; - error: DevupErrorComponentStruct['Error']; - }; - } - } - - interface DevupPutApiStruct { - [\`openapi.json\`]: { - [\`/users/{userId}/posts/{postId}\`]: { - params: { - userId: string; - }; - body: DevupRequestComponentStruct['openapi.json']['UpdatePostRequest']; - response: DevupResponseComponentStruct['openapi.json']['Post']; - }; - updateUserPost: { - params: { - userId: string; - }; - body: DevupRequestComponentStruct['openapi.json']['UpdatePostRequest']; - response: DevupResponseComponentStruct['openapi.json']['Post']; - }; - } - } - - interface DevupRequestComponentStruct { - [\`openapi.json\`]: { - UpdatePostRequest: { - title?: string; - content?: string; - }; - } - } - - interface DevupResponseComponentStruct { - [\`openapi.json\`]: { - Post: { - id?: string; - title?: string; - content?: string; - }; - } - } - - interface DevupErrorComponentStruct { - [\`openapi.json\`]: { - Error: { - code?: string; - message?: string; - }; - } - } -}" -`; - -exports[`generateInterface handles anyOf in schema collection 1`] = ` -"import "@devup-api/fetch"; - -declare module "@devup-api/fetch" { - interface DevupApiServers { - [\`openapi.json\`]: never - } - - interface DevupGetApiStruct { - [\`openapi.json\`]: { - [\`/users\`]: { - response: ({ - id?: string; -} | { - id?: string; - role?: string; -}); - }; - getUsers: { - response: ({ - id?: string; -} | { - id?: string; - role?: string; -}); - }; - } - } - - interface DevupRequestComponentStruct {} - - interface DevupResponseComponentStruct { - [\`openapi.json\`]: { - User: { - id?: string; - }; - Admin: { - id?: string; - role?: string; - }; - } - } - - interface DevupErrorComponentStruct {} -}" -`; - -exports[`generateInterface handles oneOf in schema collection 1`] = ` -"import "@devup-api/fetch"; - -declare module "@devup-api/fetch" { - interface DevupApiServers { - [\`openapi.json\`]: never - } - - interface DevupGetApiStruct { - [\`openapi.json\`]: { - [\`/users\`]: { - response: ({ - id?: string; -} | { - name?: string; -}); - }; - getUsers: { - response: ({ - id?: string; -} | { - name?: string; -}); - }; - } - } - - interface DevupRequestComponentStruct {} - - interface DevupResponseComponentStruct { - [\`openapi.json\`]: { - User: { - id?: string; - }; - Guest: { - name?: string; - }; - } - } - - interface DevupErrorComponentStruct {} -}" -`; - -exports[`generateInterface handles requestBody $ref that extracts schema name 1`] = ` -"import "@devup-api/fetch"; - -declare module "@devup-api/fetch" { - interface DevupApiServers { - [\`openapi.json\`]: never - } - - interface DevupPostApiStruct { - [\`openapi.json\`]: { - [\`/users\`]: { - body: unknown; - response?: {}; - }; - createUser: { - body: unknown; - response?: {}; - }; - } - } - - interface DevupRequestComponentStruct { - [\`openapi.json\`]: { - CreateUserRequest: { - name?: string; - }; - } - } - - interface DevupResponseComponentStruct {} - - interface DevupErrorComponentStruct {} -}" -`; - -exports[`generateInterface handles response $ref that extracts schema name 1`] = ` -"import "@devup-api/fetch"; - -declare module "@devup-api/fetch" { - interface DevupApiServers { - [\`openapi.json\`]: never - } - - interface DevupGetApiStruct { - [\`openapi.json\`]: { - [\`/users\`]: {}; - getUsers: {}; - } - } - - interface DevupRequestComponentStruct {} - - interface DevupResponseComponentStruct { - [\`openapi.json\`]: { - UserResponse: { - id?: string; - }; - } - } - - interface DevupErrorComponentStruct {} -}" -`; - -exports[`generateInterface handles requestBody with $ref that is not a component schema 1`] = ` -"import "@devup-api/fetch"; - -declare module "@devup-api/fetch" { - interface DevupApiServers { - [\`openapi.json\`]: never - } - - interface DevupPostApiStruct { - [\`openapi.json\`]: { - [\`/users\`]: { - body: unknown; - response?: {}; - }; - createUser: { - body: unknown; - response?: {}; - }; - } - } - - interface DevupRequestComponentStruct {} - - interface DevupResponseComponentStruct {} - - interface DevupErrorComponentStruct {} -}" -`; - -exports[`generateInterface handles response with $ref that is not a component schema 1`] = ` -"import "@devup-api/fetch"; - -declare module "@devup-api/fetch" { - interface DevupApiServers { - [\`openapi.json\`]: never - } - - interface DevupGetApiStruct { - [\`openapi.json\`]: { - [\`/users\`]: { - response: unknown; - }; - getUsers: { - response: unknown; - }; - } - } - - interface DevupRequestComponentStruct {} - - interface DevupResponseComponentStruct {} - - interface DevupErrorComponentStruct {} -}" -`; - -exports[`generateInterface handles error response with $ref that is not a component schema 1`] = ` -"import "@devup-api/fetch"; - -declare module "@devup-api/fetch" { - interface DevupApiServers { - [\`openapi.json\`]: never - } - - interface DevupGetApiStruct { - [\`openapi.json\`]: { - [\`/users\`]: { - response?: {}; - error: unknown; - }; - getUsers: { - response?: {}; - error: unknown; - }; - } - } - - interface DevupRequestComponentStruct {} - - interface DevupResponseComponentStruct {} - - interface DevupErrorComponentStruct {} -}" -`; - -exports[`generateInterface handles array response with $ref that is not a component schema 1`] = ` -"import "@devup-api/fetch"; - -declare module "@devup-api/fetch" { - interface DevupApiServers { - [\`openapi.json\`]: never - } - - interface DevupGetApiStruct { - [\`openapi.json\`]: { - [\`/users\`]: { - response: Array; - }; - getUsers: { - response: Array; - }; - } - } - - interface DevupRequestComponentStruct {} - - interface DevupResponseComponentStruct {} - - interface DevupErrorComponentStruct {} -}" -`; - -exports[`generateInterface handles error array response with $ref that is not a component schema 1`] = ` -"import "@devup-api/fetch"; - -declare module "@devup-api/fetch" { - interface DevupApiServers { - [\`openapi.json\`]: never - } - - interface DevupGetApiStruct { - [\`openapi.json\`]: { - [\`/users\`]: { - response?: {}; - error: Array; - }; - getUsers: { - response?: {}; - error: Array; - }; - } - } - - interface DevupRequestComponentStruct {} - - interface DevupResponseComponentStruct {} - - interface DevupErrorComponentStruct {} -}" -`; - -exports[`generateInterface handles error array response with component schema 1`] = ` -"import "@devup-api/fetch"; - -declare module "@devup-api/fetch" { - interface DevupApiServers { - [\`openapi.json\`]: never - } - - interface DevupGetApiStruct { - [\`openapi.json\`]: { - [\`/users\`]: { - response?: {}; - error: Array; - }; - getUsers: { - response?: {}; - error: Array; - }; - } - } - - interface DevupRequestComponentStruct {} - - interface DevupResponseComponentStruct {} - - interface DevupErrorComponentStruct { - [\`openapi.json\`]: { - Error: { - code?: string; - message?: string; - }; - } - } -}" -`; - -exports[`generateInterface handles error response with $ref to response object 1`] = ` -"import "@devup-api/fetch"; - -declare module "@devup-api/fetch" { - interface DevupApiServers { - [\`openapi.json\`]: never - } - - interface DevupGetApiStruct { - [\`openapi.json\`]: { - [\`/users\`]: { - response?: {}; - }; - getUsers: { - response?: {}; - }; - } - } - - interface DevupRequestComponentStruct {} - - interface DevupResponseComponentStruct {} - - interface DevupErrorComponentStruct {} -}" -`; - -exports[`generateInterface handles error response $ref that extracts schema name 1`] = ` -"import "@devup-api/fetch"; - -declare module "@devup-api/fetch" { - interface DevupApiServers { - [\`openapi.json\`]: never - } - - interface DevupGetApiStruct { - [\`openapi.json\`]: { - [\`/users\`]: { - response?: {}; - }; - getUsers: { - response?: {}; - }; - } - } - - interface DevupRequestComponentStruct {} - - interface DevupResponseComponentStruct {} - - interface DevupErrorComponentStruct { - [\`openapi.json\`]: { - ServerError: { - error?: string; - }; - } - } -}" -`; +// Bun Snapshot v1, https://bun.sh/docs/test/snapshots + +exports[`generateInterface returns interface for schema: %s 1`] = ` +"import "@devup-api/fetch"; + +declare module "@devup-api/fetch" { + interface DevupApiServers { + [\`openapi.json\`]: never + } + + interface DevupGetApiStruct { + [\`openapi.json\`]: { + [\`/users\`]: {}; + getUsers: {}; + } + } + + interface DevupRequestComponentStruct {} + + interface DevupResponseComponentStruct {} + + interface DevupErrorComponentStruct {} +}" +`; + +exports[`generateInterface returns interface for schema: %s 2`] = ` +"import "@devup-api/fetch"; + +declare module "@devup-api/fetch" { + interface DevupApiServers { + [\`openapi.json\`]: never + } + + interface DevupGetApiStruct { + [\`openapi.json\`]: { + [\`/users\`]: {}; + GetUsers: {}; + } + } + + interface DevupRequestComponentStruct {} + + interface DevupResponseComponentStruct {} + + interface DevupErrorComponentStruct {} +}" +`; + +exports[`generateInterface returns interface for schema: %s 3`] = ` +"import "@devup-api/fetch"; + +declare module "@devup-api/fetch" { + interface DevupApiServers { + [\`openapi.json\`]: never + } + + interface DevupGetApiStruct { + [\`openapi.json\`]: { + [\`/users\`]: {}; + get_users: {}; + } + } + + interface DevupRequestComponentStruct {} + + interface DevupResponseComponentStruct {} + + interface DevupErrorComponentStruct {} +}" +`; + +exports[`generateInterface returns interface for schema: %s 4`] = ` +"import "@devup-api/fetch"; + +declare module "@devup-api/fetch" { + interface DevupApiServers { + [\`openapi.json\`]: never + } + + interface DevupGetApiStruct { + [\`openapi.json\`]: { + [\`/users\`]: {}; + getUsers: {}; + } + } + + interface DevupRequestComponentStruct {} + + interface DevupResponseComponentStruct {} + + interface DevupErrorComponentStruct {} +}" +`; + +exports[`generateInterface returns interface for schema: %s 5`] = ` +"import "@devup-api/fetch"; + +declare module "@devup-api/fetch" { + interface DevupApiServers { + [\`openapi.json\`]: never + } + + interface DevupGetApiStruct { + [\`openapi.json\`]: { + [\`/users\`]: {}; + getUsers: {}; + } + } + + interface DevupRequestComponentStruct {} + + interface DevupResponseComponentStruct {} + + interface DevupErrorComponentStruct {} +}" +`; + +exports[`generateInterface returns interface for schema: %s 6`] = ` +"import "@devup-api/fetch"; + +declare module "@devup-api/fetch" { + interface DevupApiServers { + [\`openapi.json\`]: never + } + + interface DevupGetApiStruct { + [\`openapi.json\`]: { + [\`/users\`]: { + response: Array; + }; + getUsers: { + response: Array; + }; + } + } + + interface DevupPostApiStruct { + [\`openapi.json\`]: { + [\`/users\`]: { + response: DevupResponseComponentStruct['openapi.json']['User']; + }; + createUser: { + response: DevupResponseComponentStruct['openapi.json']['User']; + }; + } + } + + interface DevupRequestComponentStruct {} + + interface DevupResponseComponentStruct { + [\`openapi.json\`]: { + User: { + id?: string; + name?: string; + }; + } + } + + interface DevupErrorComponentStruct {} +}" +`; + +exports[`generateInterface returns interface for schema: %s 7`] = ` +"import "@devup-api/fetch"; + +declare module "@devup-api/fetch" { + interface DevupApiServers { + [\`openapi.json\`]: never + } + + interface DevupGetApiStruct { + [\`openapi.json\`]: { + [\`/users\`]: { + response: Array; + }; + GetUsers: { + response: Array; + }; + } + } + + interface DevupPostApiStruct { + [\`openapi.json\`]: { + [\`/users\`]: { + response: DevupResponseComponentStruct['openapi.json']['User']; + }; + CreateUser: { + response: DevupResponseComponentStruct['openapi.json']['User']; + }; + } + } + + interface DevupRequestComponentStruct {} + + interface DevupResponseComponentStruct { + [\`openapi.json\`]: { + User: { + id?: string; + name?: string; + }; + } + } + + interface DevupErrorComponentStruct {} +}" +`; + +exports[`generateInterface returns interface for schema: %s 8`] = ` +"import "@devup-api/fetch"; + +declare module "@devup-api/fetch" { + interface DevupApiServers { + [\`openapi.json\`]: never + } + + interface DevupGetApiStruct { + [\`openapi.json\`]: { + [\`/users\`]: { + response: Array; + }; + get_users: { + response: Array; + }; + } + } + + interface DevupPostApiStruct { + [\`openapi.json\`]: { + [\`/users\`]: { + response: DevupResponseComponentStruct['openapi.json']['User']; + }; + create_user: { + response: DevupResponseComponentStruct['openapi.json']['User']; + }; + } + } + + interface DevupRequestComponentStruct {} + + interface DevupResponseComponentStruct { + [\`openapi.json\`]: { + User: { + id?: string; + name?: string; + }; + } + } + + interface DevupErrorComponentStruct {} +}" +`; + +exports[`generateInterface returns interface for schema: %s 9`] = ` +"import "@devup-api/fetch"; + +declare module "@devup-api/fetch" { + interface DevupApiServers { + [\`openapi.json\`]: never + } + + interface DevupGetApiStruct { + [\`openapi.json\`]: { + [\`/users\`]: { + response: Array; + }; + getUsers: { + response: Array; + }; + } + } + + interface DevupPostApiStruct { + [\`openapi.json\`]: { + [\`/users\`]: { + response: DevupResponseComponentStruct['openapi.json']['User']; + }; + createUser: { + response: DevupResponseComponentStruct['openapi.json']['User']; + }; + } + } + + interface DevupRequestComponentStruct {} + + interface DevupResponseComponentStruct { + [\`openapi.json\`]: { + User: { + id?: string; + name?: string; + }; + } + } + + interface DevupErrorComponentStruct {} +}" +`; + +exports[`generateInterface returns interface for schema: %s 10`] = ` +"import "@devup-api/fetch"; + +declare module "@devup-api/fetch" { + interface DevupApiServers { + [\`openapi.json\`]: never + } + + interface DevupGetApiStruct { + [\`openapi.json\`]: { + [\`/users\`]: { + response: Array; + }; + getUsers: { + response: Array; + }; + } + } + + interface DevupPostApiStruct { + [\`openapi.json\`]: { + [\`/users\`]: { + response: DevupResponseComponentStruct['openapi.json']['User']; + }; + createUser: { + response: DevupResponseComponentStruct['openapi.json']['User']; + }; + } + } + + interface DevupRequestComponentStruct {} + + interface DevupResponseComponentStruct { + [\`openapi.json\`]: { + User: { + id?: string; + name?: string; + }; + } + } + + interface DevupErrorComponentStruct {} +}" +`; + +exports[`generateInterface handles all HTTP methods 1`] = ` +"import "@devup-api/fetch"; + +declare module "@devup-api/fetch" { + interface DevupApiServers { + [\`openapi.json\`]: never + } + + interface DevupGetApiStruct { + [\`openapi.json\`]: { + [\`/users\`]: { + response?: {}; + }; + getUsers: { + response?: {}; + }; + } + } + + interface DevupPostApiStruct { + [\`openapi.json\`]: { + [\`/users\`]: { + response?: {}; + }; + createUser: { + response?: {}; + }; + } + } + + interface DevupPutApiStruct { + [\`openapi.json\`]: { + [\`/users\`]: { + response?: {}; + }; + updateUser: { + response?: {}; + }; + } + } + + interface DevupDeleteApiStruct { + [\`openapi.json\`]: { + [\`/users\`]: {}; + deleteUser: {}; + } + } + + interface DevupPatchApiStruct { + [\`openapi.json\`]: { + [\`/users\`]: { + response?: {}; + }; + patchUser: { + response?: {}; + }; + } + } + + interface DevupRequestComponentStruct {} + + interface DevupResponseComponentStruct {} + + interface DevupErrorComponentStruct {} +}" +`; + +exports[`generateInterface handles path parameters 1`] = ` +"import "@devup-api/fetch"; + +declare module "@devup-api/fetch" { + interface DevupApiServers { + [\`openapi.json\`]: never + } + + interface DevupGetApiStruct { + [\`openapi.json\`]: { + [\`/users/{userId}\`]: { + params: { + userId: string; + }; + response?: {}; + }; + getUser: { + params: { + userId: string; + }; + response?: {}; + }; + } + } + + interface DevupRequestComponentStruct {} + + interface DevupResponseComponentStruct {} + + interface DevupErrorComponentStruct {} +}" +`; + +exports[`generateInterface handles query parameters 1`] = ` +"import "@devup-api/fetch"; + +declare module "@devup-api/fetch" { + interface DevupApiServers { + [\`openapi.json\`]: never + } + + interface DevupGetApiStruct { + [\`openapi.json\`]: { + [\`/users\`]: { + query: { + page?: number; + limit: number; + }; + response?: {}; + }; + getUsers: { + query: { + page?: number; + limit: number; + }; + response?: {}; + }; + } + } + + interface DevupRequestComponentStruct {} + + interface DevupResponseComponentStruct {} + + interface DevupErrorComponentStruct {} +}" +`; + +exports[`generateInterface handles path and query parameters together 1`] = ` +"import "@devup-api/fetch"; + +declare module "@devup-api/fetch" { + interface DevupApiServers { + [\`openapi.json\`]: never + } + + interface DevupGetApiStruct { + [\`openapi.json\`]: { + [\`/users/{userId}/posts\`]: { + params: { + userId: string; + }; + query?: { + page?: number; + }; + response?: {}; + }; + getUserPosts: { + params: { + userId: string; + }; + query?: { + page?: number; + }; + response?: {}; + }; + } + } + + interface DevupRequestComponentStruct {} + + interface DevupResponseComponentStruct {} + + interface DevupErrorComponentStruct {} +}" +`; + +exports[`generateInterface handles request body 1`] = ` +"import "@devup-api/fetch"; + +declare module "@devup-api/fetch" { + interface DevupApiServers { + [\`openapi.json\`]: never + } + + interface DevupPostApiStruct { + [\`openapi.json\`]: { + [\`/users\`]: { + body?: { + name?: string; + email?: string; + }; + response?: {}; + }; + createUser: { + body?: { + name?: string; + email?: string; + }; + response?: {}; + }; + } + } + + interface DevupRequestComponentStruct {} + + interface DevupResponseComponentStruct {} + + interface DevupErrorComponentStruct {} +}" +`; + +exports[`generateInterface handles request body with $ref 1`] = ` +"import "@devup-api/fetch"; + +declare module "@devup-api/fetch" { + interface DevupApiServers { + [\`openapi.json\`]: never + } + + interface DevupPostApiStruct { + [\`openapi.json\`]: { + [\`/users\`]: { + body: DevupRequestComponentStruct['openapi.json']['User']; + response?: {}; + }; + createUser: { + body: DevupRequestComponentStruct['openapi.json']['User']; + response?: {}; + }; + } + } + + interface DevupRequestComponentStruct { + [\`openapi.json\`]: { + User: { + name?: string; + email?: string; + }; + } + } + + interface DevupResponseComponentStruct {} + + interface DevupErrorComponentStruct {} +}" +`; + +exports[`generateInterface handles 200 response 1`] = ` +"import "@devup-api/fetch"; + +declare module "@devup-api/fetch" { + interface DevupApiServers { + [\`openapi.json\`]: never + } + + interface DevupGetApiStruct { + [\`openapi.json\`]: { + [\`/users\`]: { + response: Array; + }; + getUsers: { + response: Array; + }; + } + } + + interface DevupRequestComponentStruct {} + + interface DevupResponseComponentStruct { + [\`openapi.json\`]: { + User: { + id?: string; + name?: string; + }; + } + } + + interface DevupErrorComponentStruct {} +}" +`; + +exports[`generateInterface handles 201 response 1`] = ` +"import "@devup-api/fetch"; + +declare module "@devup-api/fetch" { + interface DevupApiServers { + [\`openapi.json\`]: never + } + + interface DevupPostApiStruct { + [\`openapi.json\`]: { + [\`/users\`]: { + response: DevupResponseComponentStruct['openapi.json']['User']; + }; + createUser: { + response: DevupResponseComponentStruct['openapi.json']['User']; + }; + } + } + + interface DevupRequestComponentStruct {} + + interface DevupResponseComponentStruct { + [\`openapi.json\`]: { + User: { + id?: string; + name?: string; + }; + } + } + + interface DevupErrorComponentStruct {} +}" +`; + +exports[`generateInterface handles response with other status codes 1`] = ` +"import "@devup-api/fetch"; + +declare module "@devup-api/fetch" { + interface DevupApiServers { + [\`openapi.json\`]: never + } + + interface DevupGetApiStruct { + [\`openapi.json\`]: { + [\`/users\`]: { + response?: { + message?: string; + }; + }; + getUsers: { + response?: { + message?: string; + }; + }; + } + } + + interface DevupRequestComponentStruct {} + + interface DevupResponseComponentStruct {} + + interface DevupErrorComponentStruct {} +}" +`; + +exports[`generateInterface handles error responses 1`] = ` +"import "@devup-api/fetch"; + +declare module "@devup-api/fetch" { + interface DevupApiServers { + [\`openapi.json\`]: never + } + + interface DevupGetApiStruct { + [\`openapi.json\`]: { + [\`/users\`]: { + response?: {}; + error?: { + error?: string; + }; + }; + getUsers: { + response?: {}; + error?: { + error?: string; + }; + }; + } + } + + interface DevupRequestComponentStruct {} + + interface DevupResponseComponentStruct {} + + interface DevupErrorComponentStruct { + [\`openapi.json\`]: { + Error: { + code?: string; + message?: string; + }; + } + } +}" +`; + +exports[`generateInterface handles default error response 1`] = ` +"import "@devup-api/fetch"; + +declare module "@devup-api/fetch" { + interface DevupApiServers { + [\`openapi.json\`]: never + } + + interface DevupGetApiStruct { + [\`openapi.json\`]: { + [\`/users\`]: { + response?: {}; + error?: { + error?: string; + }; + }; + getUsers: { + response?: {}; + error?: { + error?: string; + }; + }; + } + } + + interface DevupRequestComponentStruct {} + + interface DevupResponseComponentStruct {} + + interface DevupErrorComponentStruct {} +}" +`; + +exports[`generateInterface handles component schemas for request 1`] = ` +"import "@devup-api/fetch"; + +declare module "@devup-api/fetch" { + interface DevupApiServers { + [\`openapi.json\`]: never + } + + interface DevupPostApiStruct { + [\`openapi.json\`]: { + [\`/users\`]: { + body: DevupRequestComponentStruct['openapi.json']['CreateUserRequest']; + response?: {}; + }; + createUser: { + body: DevupRequestComponentStruct['openapi.json']['CreateUserRequest']; + response?: {}; + }; + } + } + + interface DevupRequestComponentStruct { + [\`openapi.json\`]: { + CreateUserRequest: { + name?: string; + email?: string; + }; + } + } + + interface DevupResponseComponentStruct {} + + interface DevupErrorComponentStruct {} +}" +`; + +exports[`generateInterface handles component schemas for response 1`] = ` +"import "@devup-api/fetch"; + +declare module "@devup-api/fetch" { + interface DevupApiServers { + [\`openapi.json\`]: never + } + + interface DevupGetApiStruct { + [\`openapi.json\`]: { + [\`/users\`]: { + response: DevupResponseComponentStruct['openapi.json']['User']; + }; + getUsers: { + response: DevupResponseComponentStruct['openapi.json']['User']; + }; + } + } + + interface DevupRequestComponentStruct {} + + interface DevupResponseComponentStruct { + [\`openapi.json\`]: { + User: { + id?: string; + name?: string; + }; + } + } + + interface DevupErrorComponentStruct {} +}" +`; + +exports[`generateInterface handles component schemas for error 1`] = ` +"import "@devup-api/fetch"; + +declare module "@devup-api/fetch" { + interface DevupApiServers { + [\`openapi.json\`]: never + } + + interface DevupGetApiStruct { + [\`openapi.json\`]: { + [\`/users\`]: { + response?: {}; + error: DevupErrorComponentStruct['Error']; + }; + getUsers: { + response?: {}; + error: DevupErrorComponentStruct['Error']; + }; + } + } + + interface DevupRequestComponentStruct {} + + interface DevupResponseComponentStruct {} + + interface DevupErrorComponentStruct { + [\`openapi.json\`]: { + Error: { + code?: string; + message?: string; + }; + } + } +}" +`; + +exports[`generateInterface handles array response with component schema 1`] = ` +"import "@devup-api/fetch"; + +declare module "@devup-api/fetch" { + interface DevupApiServers { + [\`openapi.json\`]: never + } + + interface DevupGetApiStruct { + [\`openapi.json\`]: { + [\`/users\`]: { + response: Array; + }; + getUsers: { + response: Array; + }; + } + } + + interface DevupRequestComponentStruct {} + + interface DevupResponseComponentStruct { + [\`openapi.json\`]: { + User: { + id?: string; + name?: string; + }; + } + } + + interface DevupErrorComponentStruct {} +}" +`; + +exports[`generateInterface creates both operationId and path keys 1`] = ` +"import "@devup-api/fetch"; + +declare module "@devup-api/fetch" { + interface DevupApiServers { + [\`openapi.json\`]: never + } + + interface DevupGetApiStruct { + [\`openapi.json\`]: { + [\`/users/{userId}\`]: { + params: { + userId: string; + }; + response?: {}; + }; + getUserById: { + params: { + userId: string; + }; + response?: {}; + }; + } + } + + interface DevupRequestComponentStruct {} + + interface DevupResponseComponentStruct {} + + interface DevupErrorComponentStruct {} +}" +`; + +exports[`generateInterface handles endpoints without operationId 1`] = ` +"import "@devup-api/fetch"; + +declare module "@devup-api/fetch" { + interface DevupApiServers { + [\`openapi.json\`]: never + } + + interface DevupGetApiStruct { + [\`openapi.json\`]: { + [\`/users\`]: { + response?: {}; + }; + } + } + + interface DevupRequestComponentStruct {} + + interface DevupResponseComponentStruct {} + + interface DevupErrorComponentStruct {} +}" +`; + +exports[`generateInterface handles requestDefaultNonNullable option 1`] = ` +"import "@devup-api/fetch"; + +declare module "@devup-api/fetch" { + interface DevupApiServers { + [\`openapi.json\`]: never + } + + interface DevupPostApiStruct { + [\`openapi.json\`]: { + [\`/users\`]: { + body?: { + name?: string; + email?: string; + }; + response?: {}; + }; + createUser: { + body?: { + name?: string; + email?: string; + }; + response?: {}; + }; + } + } + + interface DevupRequestComponentStruct {} + + interface DevupResponseComponentStruct {} + + interface DevupErrorComponentStruct {} +}" +`; + +exports[`generateInterface handles requestDefaultNonNullable option 2`] = ` +"import "@devup-api/fetch"; + +declare module "@devup-api/fetch" { + interface DevupApiServers { + [\`openapi.json\`]: never + } + + interface DevupPostApiStruct { + [\`openapi.json\`]: { + [\`/users\`]: { + body?: { + name?: string; + email?: string; + }; + response?: {}; + }; + createUser: { + body?: { + name?: string; + email?: string; + }; + response?: {}; + }; + } + } + + interface DevupRequestComponentStruct {} + + interface DevupResponseComponentStruct {} + + interface DevupErrorComponentStruct {} +}" +`; + +exports[`generateInterface handles responseDefaultNonNullable option 1`] = ` +"import "@devup-api/fetch"; + +declare module "@devup-api/fetch" { + interface DevupApiServers { + [\`openapi.json\`]: never + } + + interface DevupGetApiStruct { + [\`openapi.json\`]: { + [\`/users\`]: { + response: { + id: string; + name?: string; + }; + }; + getUsers: { + response: { + id: string; + name?: string; + }; + }; + } + } + + interface DevupRequestComponentStruct {} + + interface DevupResponseComponentStruct {} + + interface DevupErrorComponentStruct {} +}" +`; + +exports[`generateInterface handles responseDefaultNonNullable option 2`] = ` +"import "@devup-api/fetch"; + +declare module "@devup-api/fetch" { + interface DevupApiServers { + [\`openapi.json\`]: never + } + + interface DevupGetApiStruct { + [\`openapi.json\`]: { + [\`/users\`]: { + response?: { + id?: string; + name?: string; + }; + }; + getUsers: { + response?: { + id?: string; + name?: string; + }; + }; + } + } + + interface DevupRequestComponentStruct {} + + interface DevupResponseComponentStruct {} + + interface DevupErrorComponentStruct {} +}" +`; + +exports[`generateInterface handles nested schemas in allOf 1`] = ` +"import "@devup-api/fetch"; + +declare module "@devup-api/fetch" { + interface DevupApiServers { + [\`openapi.json\`]: never + } + + interface DevupGetApiStruct { + [\`openapi.json\`]: { + [\`/users\`]: { + response: { + id?: string; +} & { + extra?: string; +}; + }; + getUsers: { + response: { + id?: string; +} & { + extra?: string; +}; + }; + } + } + + interface DevupRequestComponentStruct {} + + interface DevupResponseComponentStruct { + [\`openapi.json\`]: { + Base: { + id?: string; + }; + } + } + + interface DevupErrorComponentStruct {} +}" +`; + +exports[`generateInterface handles empty paths 1`] = ` +"import "@devup-api/fetch"; + +declare module "@devup-api/fetch" { + interface DevupApiServers { + [\`openapi.json\`]: never + } + + interface DevupRequestComponentStruct {} + + interface DevupResponseComponentStruct {} + + interface DevupErrorComponentStruct {} +}" +`; + +exports[`generateInterface handles pathItem parameters 1`] = ` +"import "@devup-api/fetch"; + +declare module "@devup-api/fetch" { + interface DevupApiServers { + [\`openapi.json\`]: never + } + + interface DevupGetApiStruct { + [\`openapi.json\`]: { + [\`/users/{userId}\`]: { + params: { + userId: string; + }; + response?: {}; + }; + getUser: { + params: { + userId: string; + }; + response?: {}; + }; + } + } + + interface DevupRequestComponentStruct {} + + interface DevupResponseComponentStruct {} + + interface DevupErrorComponentStruct {} +}" +`; + +exports[`generateInterface handles requestBody $ref 1`] = ` +"import "@devup-api/fetch"; + +declare module "@devup-api/fetch" { + interface DevupApiServers { + [\`openapi.json\`]: never + } + + interface DevupPostApiStruct { + [\`openapi.json\`]: { + [\`/users\`]: { + body?: { + name?: string; + }; + response?: {}; + }; + createUser: { + body?: { + name?: string; + }; + response?: {}; + }; + } + } + + interface DevupRequestComponentStruct {} + + interface DevupResponseComponentStruct {} + + interface DevupErrorComponentStruct {} +}" +`; + +exports[`generateInterface handles response $ref 1`] = ` +"import "@devup-api/fetch"; + +declare module "@devup-api/fetch" { + interface DevupApiServers { + [\`openapi.json\`]: never + } + + interface DevupGetApiStruct { + [\`openapi.json\`]: { + [\`/users\`]: {}; + getUsers: {}; + } + } + + interface DevupRequestComponentStruct {} + + interface DevupResponseComponentStruct {} + + interface DevupErrorComponentStruct {} +}" +`; + +exports[`generateInterface handles complex scenario with all features 1`] = ` +"import "@devup-api/fetch"; + +declare module "@devup-api/fetch" { + interface DevupApiServers { + [\`openapi.json\`]: never + } + + interface DevupGetApiStruct { + [\`openapi.json\`]: { + [\`/users/{userId}/posts/{postId}\`]: { + params: { + userId: string; + postId: string; + }; + query?: { + include?: string; + }; + response: DevupResponseComponentStruct['openapi.json']['Post']; + error: DevupErrorComponentStruct['Error']; + }; + getUserPost: { + params: { + userId: string; + postId: string; + }; + query?: { + include?: string; + }; + response: DevupResponseComponentStruct['openapi.json']['Post']; + error: DevupErrorComponentStruct['Error']; + }; + } + } + + interface DevupPutApiStruct { + [\`openapi.json\`]: { + [\`/users/{userId}/posts/{postId}\`]: { + params: { + userId: string; + }; + body: DevupRequestComponentStruct['openapi.json']['UpdatePostRequest']; + response: DevupResponseComponentStruct['openapi.json']['Post']; + }; + updateUserPost: { + params: { + userId: string; + }; + body: DevupRequestComponentStruct['openapi.json']['UpdatePostRequest']; + response: DevupResponseComponentStruct['openapi.json']['Post']; + }; + } + } + + interface DevupRequestComponentStruct { + [\`openapi.json\`]: { + UpdatePostRequest: { + title?: string; + content?: string; + }; + } + } + + interface DevupResponseComponentStruct { + [\`openapi.json\`]: { + Post: { + id?: string; + title?: string; + content?: string; + }; + } + } + + interface DevupErrorComponentStruct { + [\`openapi.json\`]: { + Error: { + code?: string; + message?: string; + }; + } + } +}" +`; + +exports[`generateInterface handles anyOf in schema collection 1`] = ` +"import "@devup-api/fetch"; + +declare module "@devup-api/fetch" { + interface DevupApiServers { + [\`openapi.json\`]: never + } + + interface DevupGetApiStruct { + [\`openapi.json\`]: { + [\`/users\`]: { + response: ({ + id?: string; +} | { + id?: string; + role?: string; +}); + }; + getUsers: { + response: ({ + id?: string; +} | { + id?: string; + role?: string; +}); + }; + } + } + + interface DevupRequestComponentStruct {} + + interface DevupResponseComponentStruct { + [\`openapi.json\`]: { + User: { + id?: string; + }; + Admin: { + id?: string; + role?: string; + }; + } + } + + interface DevupErrorComponentStruct {} +}" +`; + +exports[`generateInterface handles oneOf in schema collection 1`] = ` +"import "@devup-api/fetch"; + +declare module "@devup-api/fetch" { + interface DevupApiServers { + [\`openapi.json\`]: never + } + + interface DevupGetApiStruct { + [\`openapi.json\`]: { + [\`/users\`]: { + response: ({ + id?: string; +} | { + name?: string; +}); + }; + getUsers: { + response: ({ + id?: string; +} | { + name?: string; +}); + }; + } + } + + interface DevupRequestComponentStruct {} + + interface DevupResponseComponentStruct { + [\`openapi.json\`]: { + User: { + id?: string; + }; + Guest: { + name?: string; + }; + } + } + + interface DevupErrorComponentStruct {} +}" +`; + +exports[`generateInterface handles requestBody $ref that extracts schema name 1`] = ` +"import "@devup-api/fetch"; + +declare module "@devup-api/fetch" { + interface DevupApiServers { + [\`openapi.json\`]: never + } + + interface DevupPostApiStruct { + [\`openapi.json\`]: { + [\`/users\`]: { + body: unknown; + response?: {}; + }; + createUser: { + body: unknown; + response?: {}; + }; + } + } + + interface DevupRequestComponentStruct { + [\`openapi.json\`]: { + CreateUserRequest: { + name?: string; + }; + } + } + + interface DevupResponseComponentStruct {} + + interface DevupErrorComponentStruct {} +}" +`; + +exports[`generateInterface handles response $ref that extracts schema name 1`] = ` +"import "@devup-api/fetch"; + +declare module "@devup-api/fetch" { + interface DevupApiServers { + [\`openapi.json\`]: never + } + + interface DevupGetApiStruct { + [\`openapi.json\`]: { + [\`/users\`]: {}; + getUsers: {}; + } + } + + interface DevupRequestComponentStruct {} + + interface DevupResponseComponentStruct { + [\`openapi.json\`]: { + UserResponse: { + id?: string; + }; + } + } + + interface DevupErrorComponentStruct {} +}" +`; + +exports[`generateInterface handles requestBody with $ref that is not a component schema 1`] = ` +"import "@devup-api/fetch"; + +declare module "@devup-api/fetch" { + interface DevupApiServers { + [\`openapi.json\`]: never + } + + interface DevupPostApiStruct { + [\`openapi.json\`]: { + [\`/users\`]: { + body: unknown; + response?: {}; + }; + createUser: { + body: unknown; + response?: {}; + }; + } + } + + interface DevupRequestComponentStruct {} + + interface DevupResponseComponentStruct {} + + interface DevupErrorComponentStruct {} +}" +`; + +exports[`generateInterface handles response with $ref that is not a component schema 1`] = ` +"import "@devup-api/fetch"; + +declare module "@devup-api/fetch" { + interface DevupApiServers { + [\`openapi.json\`]: never + } + + interface DevupGetApiStruct { + [\`openapi.json\`]: { + [\`/users\`]: { + response: unknown; + }; + getUsers: { + response: unknown; + }; + } + } + + interface DevupRequestComponentStruct {} + + interface DevupResponseComponentStruct {} + + interface DevupErrorComponentStruct {} +}" +`; + +exports[`generateInterface handles error response with $ref that is not a component schema 1`] = ` +"import "@devup-api/fetch"; + +declare module "@devup-api/fetch" { + interface DevupApiServers { + [\`openapi.json\`]: never + } + + interface DevupGetApiStruct { + [\`openapi.json\`]: { + [\`/users\`]: { + response?: {}; + error: unknown; + }; + getUsers: { + response?: {}; + error: unknown; + }; + } + } + + interface DevupRequestComponentStruct {} + + interface DevupResponseComponentStruct {} + + interface DevupErrorComponentStruct {} +}" +`; + +exports[`generateInterface handles array response with $ref that is not a component schema 1`] = ` +"import "@devup-api/fetch"; + +declare module "@devup-api/fetch" { + interface DevupApiServers { + [\`openapi.json\`]: never + } + + interface DevupGetApiStruct { + [\`openapi.json\`]: { + [\`/users\`]: { + response: Array; + }; + getUsers: { + response: Array; + }; + } + } + + interface DevupRequestComponentStruct {} + + interface DevupResponseComponentStruct {} + + interface DevupErrorComponentStruct {} +}" +`; + +exports[`generateInterface handles error array response with $ref that is not a component schema 1`] = ` +"import "@devup-api/fetch"; + +declare module "@devup-api/fetch" { + interface DevupApiServers { + [\`openapi.json\`]: never + } + + interface DevupGetApiStruct { + [\`openapi.json\`]: { + [\`/users\`]: { + response?: {}; + error: Array; + }; + getUsers: { + response?: {}; + error: Array; + }; + } + } + + interface DevupRequestComponentStruct {} + + interface DevupResponseComponentStruct {} + + interface DevupErrorComponentStruct {} +}" +`; + +exports[`generateInterface handles error array response with component schema 1`] = ` +"import "@devup-api/fetch"; + +declare module "@devup-api/fetch" { + interface DevupApiServers { + [\`openapi.json\`]: never + } + + interface DevupGetApiStruct { + [\`openapi.json\`]: { + [\`/users\`]: { + response?: {}; + error: Array; + }; + getUsers: { + response?: {}; + error: Array; + }; + } + } + + interface DevupRequestComponentStruct {} + + interface DevupResponseComponentStruct {} + + interface DevupErrorComponentStruct { + [\`openapi.json\`]: { + Error: { + code?: string; + message?: string; + }; + } + } +}" +`; + +exports[`generateInterface handles error response with $ref to response object 1`] = ` +"import "@devup-api/fetch"; + +declare module "@devup-api/fetch" { + interface DevupApiServers { + [\`openapi.json\`]: never + } + + interface DevupGetApiStruct { + [\`openapi.json\`]: { + [\`/users\`]: { + response?: {}; + }; + getUsers: { + response?: {}; + }; + } + } + + interface DevupRequestComponentStruct {} + + interface DevupResponseComponentStruct {} + + interface DevupErrorComponentStruct {} +}" +`; + +exports[`generateInterface handles error response $ref that extracts schema name 1`] = ` +"import "@devup-api/fetch"; + +declare module "@devup-api/fetch" { + interface DevupApiServers { + [\`openapi.json\`]: never + } + + interface DevupGetApiStruct { + [\`openapi.json\`]: { + [\`/users\`]: { + response?: {}; + }; + getUsers: { + response?: {}; + }; + } + } + + interface DevupRequestComponentStruct {} + + interface DevupResponseComponentStruct {} + + interface DevupErrorComponentStruct { + [\`openapi.json\`]: { + ServerError: { + error?: string; + }; + } + } +}" +`;