fork of hey-api/openapi-ts because I need some additional things

chore: update axios example to match fetch

Lubos c7262f30 a0421224

+835 -796
+1 -1
examples/openapi-ts-axios/index.html
··· 2 2 <html lang="en"> 3 3 <head> 4 4 <meta charset="UTF-8" /> 5 - <link rel="icon" type="image/svg+xml" href="/vite.svg" /> 5 + <!-- <link rel="icon" type="image/svg+xml" href="/vite.svg" /> --> 6 6 <meta name="viewport" content="width=device-width, initial-scale=1.0" /> 7 7 <title>Hey API + Axios Demo</title> 8 8 </head>
+12 -3
examples/openapi-ts-axios/openapi-ts.config.ts
··· 1 1 import { defineConfig } from '@hey-api/openapi-ts'; 2 2 3 3 export default defineConfig({ 4 - format: 'prettier', 4 + base: 'https://petstore3.swagger.io/api/v3', 5 + client: '@hey-api/client-axios', 5 6 input: 6 7 'https://raw.githubusercontent.com/swagger-api/swagger-petstore/master/src/main/resources/openapi.yaml', 7 - lint: 'eslint', 8 - output: './src/client', 8 + // 'https://raw.githubusercontent.com/Redocly/museum-openapi-example/main/openapi.yaml', 9 + // '../../packages/openapi-ts/test/spec/v3.json', 10 + output: { 11 + format: 'prettier', 12 + lint: 'eslint', 13 + path: './src/client', 14 + }, 15 + types: { 16 + enums: 'javascript', 17 + }, 9 18 });
+6
examples/openapi-ts-axios/package.json
··· 13 13 }, 14 14 "dependencies": { 15 15 "@hey-api/client-axios": "workspace:*", 16 + "@radix-ui/react-form": "0.0.3", 17 + "@radix-ui/react-icons": "1.3.0", 18 + "@radix-ui/themes": "3.0.5", 16 19 "axios": "1.7.2", 17 20 "react": "18.3.1", 18 21 "react-dom": "18.3.1" ··· 24 27 "@typescript-eslint/eslint-plugin": "7.10.0", 25 28 "@typescript-eslint/parser": "7.10.0", 26 29 "@vitejs/plugin-react": "4.3.0", 30 + "autoprefixer": "10.4.19", 27 31 "eslint": "9.3.0", 28 32 "eslint-plugin-react-hooks": "4.6.2", 29 33 "eslint-plugin-react-refresh": "0.4.7", 34 + "postcss": "8.4.38", 30 35 "prettier": "3.2.5", 36 + "tailwindcss": "3.4.3", 31 37 "typescript": "5.4.5", 32 38 "vite": "5.2.11" 33 39 }
+6
examples/openapi-ts-axios/postcss.config.js
··· 1 + export default { 2 + plugins: { 3 + autoprefixer: {}, 4 + tailwindcss: {}, 5 + }, 6 + };
+3 -87
examples/openapi-ts-axios/src/App.css
··· 1 - :root { 2 - font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif; 3 - line-height: 1.5; 4 - font-weight: 400; 5 - 6 - color-scheme: light dark; 7 - color: rgba(255, 255, 255, 0.87); 8 - background-color: #242424; 9 - 10 - font-synthesis: none; 11 - text-rendering: optimizeLegibility; 12 - -webkit-font-smoothing: antialiased; 13 - -moz-osx-font-smoothing: grayscale; 14 - } 15 - 16 - .flex { 17 - align-items: center; 18 - display: flex; 19 - padding: 1em 0; 20 - } 21 - 22 - .pet-name { 23 - padding: 0 1em; 24 - } 25 - 26 - .button { 27 - border: 1px solid #444; 28 - } 29 - 30 - #root { 31 - max-width: 1280px; 32 - margin: 0 auto; 33 - padding: 0.5rem 2rem; 34 - } 35 - 36 - body { 37 - margin: 0; 38 - display: flex; 39 - place-items: center; 40 - min-width: 320px; 41 - min-height: 100vh; 42 - } 43 - 44 - .h1 { 45 - font-size: 1.2em; 46 - line-height: 1.1; 47 - } 1 + @tailwind base; 2 + @tailwind components; 3 + @tailwind utilities; 48 4 49 5 .logo { 50 6 height: 4em; 51 7 will-change: filter; 52 8 transition: filter 300ms; 53 9 } 54 - .logo:hover { 55 - filter: drop-shadow(0 0 2em #646cffaa); 56 - } 57 - .logo.react:hover { 58 - filter: drop-shadow(0 0 2em #61dafbaa); 59 - } 60 10 61 11 @keyframes logo-spin { 62 12 from { ··· 66 16 transform: rotate(360deg); 67 17 } 68 18 } 69 - 70 - @media (prefers-reduced-motion: no-preference) { 71 - a:nth-of-type(2) .logo { 72 - animation: logo-spin infinite 20s linear; 73 - } 74 - } 75 - 76 - .card { 77 - padding: 2em; 78 - } 79 - 80 - .container { 81 - align-items: center; 82 - display: flex; 83 - grid-gap: 1em; 84 - text-align: center; 85 - } 86 - 87 - .openapi-ts { 88 - color: #444; 89 - } 90 - 91 - @media (prefers-color-scheme: light) { 92 - :root { 93 - color: #213547; 94 - background-color: #ffffff; 95 - } 96 - a:hover { 97 - color: #747bff; 98 - } 99 - button { 100 - background-color: #f9f9f9; 101 - } 102 - }
+227 -38
examples/openapi-ts-axios/src/App.tsx
··· 1 1 import './App.css'; 2 2 3 - import { client, createClient } from '@hey-api/client-axios'; 3 + import { createClient } from '@hey-api/client-axios'; 4 + import * as Form from '@radix-ui/react-form'; 5 + import { DownloadIcon, PlusIcon, ReloadIcon } from '@radix-ui/react-icons'; 6 + import { 7 + Avatar, 8 + Box, 9 + Button, 10 + Card, 11 + Container, 12 + Flex, 13 + Heading, 14 + Section, 15 + Text, 16 + TextField, 17 + } from '@radix-ui/themes'; 4 18 import { useState } from 'react'; 5 19 6 20 import { $Pet } from './client/schemas.gen'; 7 - import { PetService } from './client/services.gen'; 21 + import { addPet, getPetById, updatePet } from './client/services.gen'; 22 + import type { Pet } from './client/types.gen'; 8 23 9 24 createClient({ 25 + // set default base url for requests 10 26 baseUrl: 'https://petstore3.swagger.io/api/v3', 27 + // set default headers for requests 28 + headers: { 29 + Authorization: 'Bearer <token_from_global_client>', 30 + }, 11 31 }); 12 32 13 - // OpenAPI.interceptors.response.use((response) => { 14 - // if (response.status === 200) { 15 - // console.log(`request to ${response.url} was successful`); 16 - // } 17 - // return response; 18 - // }); 33 + const localClient = createClient({ 34 + // set default base url for requests made by this client 35 + baseUrl: 'https://petstore3.swagger.io/api/v3', 36 + global: false, 37 + /** 38 + * Set default headers only for requests made by this client. This is to 39 + * demonstrate local clients and their configuration taking precedence over 40 + * global configuration. 41 + */ 42 + headers: { 43 + Authorization: 'Bearer <token_from_local_client>', 44 + }, 45 + }); 46 + 47 + localClient.interceptors.request.use((request, options) => { 48 + // Middleware is great for adding authorization tokens to requests made to 49 + // protected paths. Headers are set randomly here to allow surfacing the 50 + // default headers, too. 51 + if ( 52 + options.url === '/pet/{petId}' && 53 + options.method === 'GET' && 54 + Math.random() < 0.5 55 + ) { 56 + request.headers.set('Authorization', 'Bearer <token_from_interceptor>'); 57 + } 58 + return request; 59 + }); 19 60 20 61 function App() { 21 - const [pet, setPet] = 22 - useState<Awaited<ReturnType<typeof PetService.getPetById>>>(); 62 + const [pet, setPet] = useState<Pet>(); 63 + const [isRequiredNameError, setIsRequiredNameError] = useState(false); 64 + 65 + const onAddPet = async (formData: FormData) => { 66 + // simple form field validation to demonstrate using schemas 67 + if ($Pet.required.includes('name') && !formData.get('name')) { 68 + setIsRequiredNameError(true); 69 + return; 70 + } 71 + 72 + const { data, error } = await addPet({ 73 + body: { 74 + category: { 75 + id: 0, 76 + name: formData.get('category') as string, 77 + }, 78 + id: 0, 79 + name: formData.get('name') as string, 80 + photoUrls: ['string'], 81 + status: 'available', 82 + tags: [ 83 + { 84 + id: 0, 85 + name: 'string', 86 + }, 87 + ], 88 + }, 89 + }); 90 + if (error) { 91 + console.log(error); 92 + return; 93 + } 94 + setPet(data!); 95 + setIsRequiredNameError(false); 96 + }; 23 97 24 - const onFetchPet = async () => { 25 - client.get('/pet/{petId}'); 26 - const pet = await PetService.getPetById({ 27 - // random id 1-10 28 - petId: Math.floor(Math.random() * (10 - 1 + 1) + 1), 98 + const onGetPetById = async () => { 99 + const { data, error } = await getPetById({ 100 + client: localClient, 101 + path: { 102 + // random id 1-10 103 + petId: Math.floor(Math.random() * (10 - 1 + 1) + 1), 104 + }, 105 + }); 106 + if (error) { 107 + console.log(error); 108 + return; 109 + } 110 + setPet(data!); 111 + }; 112 + 113 + const onUpdatePet = async () => { 114 + const { data, error } = await updatePet({ 115 + body: { 116 + category: { 117 + id: 0, 118 + name: 'Cats', 119 + }, 120 + id: 2, 121 + name: 'Updated Kitty', 122 + photoUrls: ['string'], 123 + status: 'available', 124 + tags: [ 125 + { 126 + id: 0, 127 + name: 'string', 128 + }, 129 + ], 130 + }, 131 + // setting headers per request 132 + headers: { 133 + Authorization: 'Bearer <token_from_method>', 134 + }, 29 135 }); 30 - setPet(pet); 136 + if (error) { 137 + console.log(error); 138 + return; 139 + } 140 + setPet(data!); 31 141 }; 32 142 33 143 return ( 34 - <> 35 - <div className="container"> 36 - <a href="https://heyapi.vercel.app/" target="_blank"> 37 - <img 38 - src="https://heyapi.vercel.app/logo.png" 39 - className="logo vanilla" 40 - alt="Hey API logo" 41 - /> 42 - </a> 43 - <h1 className="h1">@hey-api/openapi-ts 🤝 Axios</h1> 44 - </div> 45 - <div className="flex"> 46 - <button className="button" onClick={onFetchPet}> 47 - Fetch random pet 48 - </button> 49 - <span className="pet-name">Fetched pet's name: {pet?.name}</span> 50 - </div> 51 - <div className="openapi-ts"> 52 - <code>{"import { $Pet } from './client/schemas.gen'"}</code> 53 - <pre>{JSON.stringify($Pet, null, 2)}</pre> 54 - </div> 55 - </> 144 + <Box 145 + style={{ background: 'var(--gray-a2)', borderRadius: 'var(--radius-3)' }} 146 + > 147 + <Container size="1"> 148 + <Section size="1" /> 149 + <Flex align="center"> 150 + <a href="https://heyapi.vercel.app/" target="_blank"> 151 + <img 152 + src="https://heyapi.vercel.app/logo.png" 153 + className="logo vanilla" 154 + alt="Hey API logo" 155 + /> 156 + </a> 157 + <Heading>@hey-api/openapi-ts 🤝 Axios</Heading> 158 + </Flex> 159 + <Section size="1" /> 160 + <Flex direction="column" gapY="2"> 161 + <Box maxWidth="240px"> 162 + <Card> 163 + <Flex gap="3" align="center"> 164 + <Avatar 165 + size="3" 166 + src={pet?.photoUrls[0]} 167 + radius="full" 168 + fallback={pet?.name.slice(0, 1) ?? 'N'} 169 + /> 170 + <Box> 171 + <Text as="div" size="2" weight="bold"> 172 + Name: {pet?.name ?? 'N/A'} 173 + </Text> 174 + <Text as="div" size="2" color="gray"> 175 + Category: {pet?.category?.name ?? 'N/A'} 176 + </Text> 177 + </Box> 178 + </Flex> 179 + </Card> 180 + </Box> 181 + <Button onClick={onGetPetById}> 182 + <DownloadIcon /> Get Random Pet 183 + </Button> 184 + </Flex> 185 + <Section size="1" /> 186 + <Flex direction="column" gapY="2"> 187 + <Form.Root 188 + className="w-[260px]" 189 + onSubmit={(event) => { 190 + event.preventDefault(); 191 + onAddPet(new FormData(event.currentTarget)); 192 + }} 193 + > 194 + <Form.Field className="grid mb-[10px]" name="email"> 195 + <div className="flex items-baseline justify-between"> 196 + <Form.Label className="text-[15px] font-medium leading-[35px] text-white"> 197 + Name 198 + </Form.Label> 199 + {isRequiredNameError && ( 200 + <Form.Message className="text-[13px] text-white opacity-[0.8]"> 201 + Please enter a name 202 + </Form.Message> 203 + )} 204 + </div> 205 + <Form.Control asChild> 206 + <TextField.Root placeholder="Kitty" name="name" type="text" /> 207 + </Form.Control> 208 + </Form.Field> 209 + <Form.Field className="grid mb-[10px]" name="question"> 210 + <div className="flex items-baseline justify-between"> 211 + <Form.Label className="text-[15px] font-medium leading-[35px] text-white"> 212 + Category 213 + </Form.Label> 214 + <Form.Message 215 + className="text-[13px] text-white opacity-[0.8]" 216 + match="valueMissing" 217 + > 218 + Please enter a category 219 + </Form.Message> 220 + </div> 221 + <Form.Control asChild> 222 + <TextField.Root 223 + placeholder="Cats" 224 + name="category" 225 + type="text" 226 + required 227 + /> 228 + </Form.Control> 229 + </Form.Field> 230 + <Flex gapX="2"> 231 + <Form.Submit asChild> 232 + <Button type="submit"> 233 + <PlusIcon /> Add Pet 234 + </Button> 235 + </Form.Submit> 236 + <Button onClick={onUpdatePet} type="button"> 237 + <ReloadIcon /> Update Pet 238 + </Button> 239 + </Flex> 240 + </Form.Root> 241 + </Flex> 242 + <Section size="1" /> 243 + </Container> 244 + </Box> 56 245 ); 57 246 } 58 247
+216 -422
examples/openapi-ts-axios/src/client/services.gen.ts
··· 1 1 // This file is auto-generated by @hey-api/openapi-ts 2 2 3 - import type { CancelablePromise } from '@hey-api/client-axios'; 4 - import { OpenAPI } from '@hey-api/client-axios'; 5 - import { request as __request } from '@hey-api/client-axios'; 3 + import { client, type Options } from '@hey-api/client-axios'; 6 4 7 - import type { $OpenApiTs } from './types.gen'; 5 + import type { 6 + AddPetData, 7 + AddPetError, 8 + AddPetResponse, 9 + CreateUserData, 10 + CreateUserError, 11 + CreateUserResponse, 12 + CreateUsersWithListInputData, 13 + CreateUsersWithListInputError, 14 + CreateUsersWithListInputResponse, 15 + DeleteOrderData, 16 + DeletePetData, 17 + DeleteUserData, 18 + FindPetsByStatusData, 19 + FindPetsByStatusError, 20 + FindPetsByStatusResponse, 21 + FindPetsByTagsData, 22 + FindPetsByTagsError, 23 + FindPetsByTagsResponse, 24 + GetInventoryError, 25 + GetInventoryResponse, 26 + GetOrderByIdData, 27 + GetOrderByIdError, 28 + GetOrderByIdResponse, 29 + GetPetByIdData, 30 + GetPetByIdError, 31 + GetPetByIdResponse, 32 + GetUserByNameData, 33 + GetUserByNameError, 34 + GetUserByNameResponse, 35 + LoginUserData, 36 + LoginUserError, 37 + LoginUserResponse, 38 + LogoutUserError, 39 + LogoutUserResponse, 40 + PlaceOrderData, 41 + PlaceOrderError, 42 + PlaceOrderResponse, 43 + UpdatePetData, 44 + UpdatePetError, 45 + UpdatePetResponse, 46 + UpdatePetWithFormData, 47 + UpdateUserData, 48 + UpdateUserError, 49 + UpdateUserResponse, 50 + UploadFileData, 51 + UploadFileError, 52 + UploadFileResponse, 53 + } from './types.gen'; 8 54 9 - export class PetService { 10 - /** 11 - * Add a new pet to the store 12 - * Add a new pet to the store 13 - * @param data The data for the request. 14 - * @param data.requestBody Create a new pet in the store 15 - * @returns Pet Successful operation 16 - * @throws ApiError 17 - */ 18 - public static addPet( 19 - data: $OpenApiTs['/pet']['post']['req'], 20 - ): CancelablePromise<$OpenApiTs['/pet']['post']['res'][200]> { 21 - return __request(OpenAPI, { 22 - body: data.requestBody, 23 - errors: { 24 - 405: 'Invalid input', 25 - }, 26 - mediaType: 'application/json', 27 - method: 'POST', 28 - url: '/pet', 29 - }); 30 - } 55 + /** 56 + * Add a new pet to the store 57 + * Add a new pet to the store 58 + */ 59 + export const addPet = (options: Options<AddPetData>) => (options?.client ?? client).post<AddPetResponse, AddPetError>({ 60 + ...options, 61 + url: '/pet', 62 + }); 31 63 32 - /** 33 - * Update an existing pet 34 - * Update an existing pet by Id 35 - * @param data The data for the request. 36 - * @param data.requestBody Update an existent pet in the store 37 - * @returns Pet Successful operation 38 - * @throws ApiError 39 - */ 40 - public static updatePet( 41 - data: $OpenApiTs['/pet']['put']['req'], 42 - ): CancelablePromise<$OpenApiTs['/pet']['put']['res'][200]> { 43 - return __request(OpenAPI, { 44 - body: data.requestBody, 45 - errors: { 46 - 400: 'Invalid ID supplied', 47 - 404: 'Pet not found', 48 - 405: 'Validation exception', 49 - }, 50 - mediaType: 'application/json', 51 - method: 'PUT', 52 - url: '/pet', 53 - }); 54 - } 64 + /** 65 + * Update an existing pet 66 + * Update an existing pet by Id 67 + */ 68 + export const updatePet = (options: Options<UpdatePetData>) => (options?.client ?? client).put<UpdatePetResponse, UpdatePetError>({ 69 + ...options, 70 + url: '/pet', 71 + }); 55 72 56 - /** 57 - * Finds Pets by status 58 - * Multiple status values can be provided with comma separated strings 59 - * @param data The data for the request. 60 - * @param data.status Status values that need to be considered for filter 61 - * @returns Pet successful operation 62 - * @throws ApiError 63 - */ 64 - public static findPetsByStatus( 65 - data: $OpenApiTs['/pet/findByStatus']['get']['req'] = {}, 66 - ): CancelablePromise<$OpenApiTs['/pet/findByStatus']['get']['res'][200]> { 67 - return __request(OpenAPI, { 68 - errors: { 69 - 400: 'Invalid status value', 70 - }, 71 - method: 'GET', 72 - query: { 73 - status: data.status, 74 - }, 75 - url: '/pet/findByStatus', 76 - }); 77 - } 73 + /** 74 + * Finds Pets by status 75 + * Multiple status values can be provided with comma separated strings 76 + */ 77 + export const findPetsByStatus = (options?: Options<FindPetsByStatusData>) => (options?.client ?? client).get< 78 + FindPetsByStatusResponse, 79 + FindPetsByStatusError 80 + >({ 81 + ...options, 82 + url: '/pet/findByStatus', 83 + }); 78 84 79 - /** 80 - * Finds Pets by tags 81 - * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. 82 - * @param data The data for the request. 83 - * @param data.tags Tags to filter by 84 - * @returns Pet successful operation 85 - * @throws ApiError 86 - */ 87 - public static findPetsByTags( 88 - data: $OpenApiTs['/pet/findByTags']['get']['req'] = {}, 89 - ): CancelablePromise<$OpenApiTs['/pet/findByTags']['get']['res'][200]> { 90 - return __request(OpenAPI, { 91 - errors: { 92 - 400: 'Invalid tag value', 93 - }, 94 - method: 'GET', 95 - query: { 96 - tags: data.tags, 97 - }, 98 - url: '/pet/findByTags', 99 - }); 100 - } 85 + /** 86 + * Finds Pets by tags 87 + * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. 88 + */ 89 + export const findPetsByTags = (options?: Options<FindPetsByTagsData>) => (options?.client ?? client).get< 90 + FindPetsByTagsResponse, 91 + FindPetsByTagsError 92 + >({ 93 + ...options, 94 + url: '/pet/findByTags', 95 + }); 101 96 102 - /** 103 - * Find pet by ID 104 - * Returns a single pet 105 - * @param data The data for the request. 106 - * @param data.petId ID of pet to return 107 - * @returns Pet successful operation 108 - * @throws ApiError 109 - */ 110 - public static getPetById( 111 - data: $OpenApiTs['/pet/{petId}']['get']['req'], 112 - ): CancelablePromise<$OpenApiTs['/pet/{petId}']['get']['res'][200]> { 113 - return __request(OpenAPI, { 114 - errors: { 115 - 400: 'Invalid ID supplied', 116 - 404: 'Pet not found', 117 - }, 118 - method: 'GET', 119 - path: { 120 - petId: data.petId, 121 - }, 122 - url: '/pet/{petId}', 123 - }); 124 - } 97 + /** 98 + * Find pet by ID 99 + * Returns a single pet 100 + */ 101 + export const getPetById = (options: Options<GetPetByIdData>) => (options?.client ?? client).get<GetPetByIdResponse, GetPetByIdError>({ 102 + ...options, 103 + url: '/pet/{petId}', 104 + }); 125 105 126 - /** 127 - * Updates a pet in the store with form data 128 - * @param data The data for the request. 129 - * @param data.petId ID of pet that needs to be updated 130 - * @param data.name Name of pet that needs to be updated 131 - * @param data.status Status of pet that needs to be updated 132 - * @throws ApiError 133 - */ 134 - public static updatePetWithForm( 135 - data: $OpenApiTs['/pet/{petId}']['post']['req'], 136 - ): CancelablePromise<void> { 137 - return __request(OpenAPI, { 138 - errors: { 139 - 405: 'Invalid input', 140 - }, 141 - method: 'POST', 142 - path: { 143 - petId: data.petId, 144 - }, 145 - query: { 146 - name: data.name, 147 - status: data.status, 148 - }, 149 - url: '/pet/{petId}', 150 - }); 151 - } 106 + /** 107 + * Updates a pet in the store with form data 108 + */ 109 + export const updatePetWithForm = (options: Options<UpdatePetWithFormData>) => (options?.client ?? client).post<void>({ 110 + ...options, 111 + url: '/pet/{petId}', 112 + }); 152 113 153 - /** 154 - * Deletes a pet 155 - * @param data The data for the request. 156 - * @param data.petId Pet id to delete 157 - * @param data.apiKey 158 - * @throws ApiError 159 - */ 160 - public static deletePet( 161 - data: $OpenApiTs['/pet/{petId}']['delete']['req'], 162 - ): CancelablePromise<void> { 163 - return __request(OpenAPI, { 164 - errors: { 165 - 400: 'Invalid pet value', 166 - }, 167 - headers: { 168 - api_key: data.apiKey, 169 - }, 170 - method: 'DELETE', 171 - path: { 172 - petId: data.petId, 173 - }, 174 - url: '/pet/{petId}', 175 - }); 176 - } 114 + /** 115 + * Deletes a pet 116 + */ 117 + export const deletePet = (options: Options<DeletePetData>) => (options?.client ?? client).delete<void>({ 118 + ...options, 119 + url: '/pet/{petId}', 120 + }); 177 121 178 - /** 179 - * uploads an image 180 - * @param data The data for the request. 181 - * @param data.petId ID of pet to update 182 - * @param data.additionalMetadata Additional Metadata 183 - * @param data.requestBody 184 - * @returns ApiResponse successful operation 185 - * @throws ApiError 186 - */ 187 - public static uploadFile( 188 - data: $OpenApiTs['/pet/{petId}/uploadImage']['post']['req'], 189 - ): CancelablePromise< 190 - $OpenApiTs['/pet/{petId}/uploadImage']['post']['res'][200] 191 - > { 192 - return __request(OpenAPI, { 193 - body: data.requestBody, 194 - mediaType: 'application/octet-stream', 195 - method: 'POST', 196 - path: { 197 - petId: data.petId, 198 - }, 199 - query: { 200 - additionalMetadata: data.additionalMetadata, 201 - }, 202 - url: '/pet/{petId}/uploadImage', 203 - }); 204 - } 205 - } 122 + /** 123 + * uploads an image 124 + */ 125 + export const uploadFile = (options: Options<UploadFileData>) => (options?.client ?? client).post<UploadFileResponse, UploadFileError>({ 126 + ...options, 127 + url: '/pet/{petId}/uploadImage', 128 + }); 206 129 207 - export class StoreService { 208 - /** 209 - * Returns pet inventories by status 210 - * Returns a map of status codes to quantities 211 - * @returns number successful operation 212 - * @throws ApiError 213 - */ 214 - public static getInventory(): CancelablePromise< 215 - $OpenApiTs['/store/inventory']['get']['res'][200] 216 - > { 217 - return __request(OpenAPI, { 218 - method: 'GET', 219 - url: '/store/inventory', 220 - }); 221 - } 130 + /** 131 + * Returns pet inventories by status 132 + * Returns a map of status codes to quantities 133 + */ 134 + export const getInventory = (options?: Options) => (options?.client ?? client).get< 135 + GetInventoryResponse, 136 + GetInventoryError 137 + >({ 138 + ...options, 139 + url: '/store/inventory', 140 + }); 222 141 223 - /** 224 - * Place an order for a pet 225 - * Place a new order in the store 226 - * @param data The data for the request. 227 - * @param data.requestBody 228 - * @returns Order successful operation 229 - * @throws ApiError 230 - */ 231 - public static placeOrder( 232 - data: $OpenApiTs['/store/order']['post']['req'] = {}, 233 - ): CancelablePromise<$OpenApiTs['/store/order']['post']['res'][200]> { 234 - return __request(OpenAPI, { 235 - body: data.requestBody, 236 - errors: { 237 - 405: 'Invalid input', 238 - }, 239 - mediaType: 'application/json', 240 - method: 'POST', 241 - url: '/store/order', 242 - }); 243 - } 142 + /** 143 + * Place an order for a pet 144 + * Place a new order in the store 145 + */ 146 + export const placeOrder = (options?: Options<PlaceOrderData>) => (options?.client ?? client).post<PlaceOrderResponse, PlaceOrderError>({ 147 + ...options, 148 + url: '/store/order', 149 + }); 244 150 245 - /** 246 - * Find purchase order by ID 247 - * For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions. 248 - * @param data The data for the request. 249 - * @param data.orderId ID of order that needs to be fetched 250 - * @returns Order successful operation 251 - * @throws ApiError 252 - */ 253 - public static getOrderById( 254 - data: $OpenApiTs['/store/order/{orderId}']['get']['req'], 255 - ): CancelablePromise< 256 - $OpenApiTs['/store/order/{orderId}']['get']['res'][200] 257 - > { 258 - return __request(OpenAPI, { 259 - errors: { 260 - 400: 'Invalid ID supplied', 261 - 404: 'Order not found', 262 - }, 263 - method: 'GET', 264 - path: { 265 - orderId: data.orderId, 266 - }, 267 - url: '/store/order/{orderId}', 268 - }); 269 - } 151 + /** 152 + * Find purchase order by ID 153 + * For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions. 154 + */ 155 + export const getOrderById = (options: Options<GetOrderByIdData>) => (options?.client ?? client).get< 156 + GetOrderByIdResponse, 157 + GetOrderByIdError 158 + >({ 159 + ...options, 160 + url: '/store/order/{orderId}', 161 + }); 270 162 271 - /** 272 - * Delete purchase order by ID 273 - * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors 274 - * @param data The data for the request. 275 - * @param data.orderId ID of the order that needs to be deleted 276 - * @throws ApiError 277 - */ 278 - public static deleteOrder( 279 - data: $OpenApiTs['/store/order/{orderId}']['delete']['req'], 280 - ): CancelablePromise<void> { 281 - return __request(OpenAPI, { 282 - errors: { 283 - 400: 'Invalid ID supplied', 284 - 404: 'Order not found', 285 - }, 286 - method: 'DELETE', 287 - path: { 288 - orderId: data.orderId, 289 - }, 290 - url: '/store/order/{orderId}', 291 - }); 292 - } 293 - } 163 + /** 164 + * Delete purchase order by ID 165 + * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors 166 + */ 167 + export const deleteOrder = (options: Options<DeleteOrderData>) => (options?.client ?? client).delete<void>({ 168 + ...options, 169 + url: '/store/order/{orderId}', 170 + }); 294 171 295 - export class UserService { 296 - /** 297 - * Create user 298 - * This can only be done by the logged in user. 299 - * @param data The data for the request. 300 - * @param data.requestBody Created user object 301 - * @returns User successful operation 302 - * @throws ApiError 303 - */ 304 - public static createUser( 305 - data: $OpenApiTs['/user']['post']['req'] = {}, 306 - ): CancelablePromise<$OpenApiTs['/user']['post']['res'][200]> { 307 - return __request(OpenAPI, { 308 - body: data.requestBody, 309 - mediaType: 'application/json', 310 - method: 'POST', 311 - url: '/user', 312 - }); 313 - } 172 + /** 173 + * Create user 174 + * This can only be done by the logged in user. 175 + */ 176 + export const createUser = (options?: Options<CreateUserData>) => (options?.client ?? client).post<CreateUserResponse, CreateUserError>({ 177 + ...options, 178 + url: '/user', 179 + }); 314 180 315 - /** 316 - * Creates list of users with given input array 317 - * Creates list of users with given input array 318 - * @param data The data for the request. 319 - * @param data.requestBody 320 - * @returns User Successful operation 321 - * @returns unknown successful operation 322 - * @throws ApiError 323 - */ 324 - public static createUsersWithListInput( 325 - data: $OpenApiTs['/user/createWithList']['post']['req'] = {}, 326 - ): CancelablePromise< 327 - | $OpenApiTs['/user/createWithList']['post']['res'][200] 328 - | $OpenApiTs['/user/createWithList']['post']['res'][200] 329 - > { 330 - return __request(OpenAPI, { 331 - body: data.requestBody, 332 - mediaType: 'application/json', 333 - method: 'POST', 334 - url: '/user/createWithList', 335 - }); 336 - } 181 + /** 182 + * Creates list of users with given input array 183 + * Creates list of users with given input array 184 + */ 185 + export const createUsersWithListInput = ( 186 + options?: Options<CreateUsersWithListInputData>, 187 + ) => (options?.client ?? client).post< 188 + CreateUsersWithListInputResponse, 189 + CreateUsersWithListInputError 190 + >({ 191 + ...options, 192 + url: '/user/createWithList', 193 + }); 337 194 338 - /** 339 - * Logs user into the system 340 - * @param data The data for the request. 341 - * @param data.username The user name for login 342 - * @param data.password The password for login in clear text 343 - * @returns string successful operation 344 - * @throws ApiError 345 - */ 346 - public static loginUser( 347 - data: $OpenApiTs['/user/login']['get']['req'] = {}, 348 - ): CancelablePromise<$OpenApiTs['/user/login']['get']['res'][200]> { 349 - return __request(OpenAPI, { 350 - errors: { 351 - 400: 'Invalid username/password supplied', 352 - }, 353 - method: 'GET', 354 - query: { 355 - password: data.password, 356 - username: data.username, 357 - }, 358 - url: '/user/login', 359 - }); 360 - } 195 + /** 196 + * Logs user into the system 197 + */ 198 + export const loginUser = (options?: Options<LoginUserData>) => (options?.client ?? client).get<LoginUserResponse, LoginUserError>({ 199 + ...options, 200 + url: '/user/login', 201 + }); 361 202 362 - /** 363 - * Logs out current logged in user session 364 - * @returns unknown successful operation 365 - * @throws ApiError 366 - */ 367 - public static logoutUser(): CancelablePromise< 368 - $OpenApiTs['/user/logout']['get']['res'][200] 369 - > { 370 - return __request(OpenAPI, { 371 - method: 'GET', 372 - url: '/user/logout', 373 - }); 374 - } 203 + /** 204 + * Logs out current logged in user session 205 + */ 206 + export const logoutUser = (options?: Options) => (options?.client ?? client).get<LogoutUserResponse, LogoutUserError>({ 207 + ...options, 208 + url: '/user/logout', 209 + }); 375 210 376 - /** 377 - * Get user by user name 378 - * @param data The data for the request. 379 - * @param data.username The name that needs to be fetched. Use user1 for testing. 380 - * @returns User successful operation 381 - * @throws ApiError 382 - */ 383 - public static getUserByName( 384 - data: $OpenApiTs['/user/{username}']['get']['req'], 385 - ): CancelablePromise<$OpenApiTs['/user/{username}']['get']['res'][200]> { 386 - return __request(OpenAPI, { 387 - errors: { 388 - 400: 'Invalid username supplied', 389 - 404: 'User not found', 390 - }, 391 - method: 'GET', 392 - path: { 393 - username: data.username, 394 - }, 395 - url: '/user/{username}', 396 - }); 397 - } 211 + /** 212 + * Get user by user name 213 + */ 214 + export const getUserByName = (options: Options<GetUserByNameData>) => (options?.client ?? client).get< 215 + GetUserByNameResponse, 216 + GetUserByNameError 217 + >({ 218 + ...options, 219 + url: '/user/{username}', 220 + }); 398 221 399 - /** 400 - * Update user 401 - * This can only be done by the logged in user. 402 - * @param data The data for the request. 403 - * @param data.username name that needs to be updated 404 - * @param data.requestBody Update an existent user in the store 405 - * @returns unknown successful operation 406 - * @throws ApiError 407 - */ 408 - public static updateUser( 409 - data: $OpenApiTs['/user/{username}']['put']['req'], 410 - ): CancelablePromise<$OpenApiTs['/user/{username}']['put']['res'][200]> { 411 - return __request(OpenAPI, { 412 - body: data.requestBody, 413 - mediaType: 'application/json', 414 - method: 'PUT', 415 - path: { 416 - username: data.username, 417 - }, 418 - url: '/user/{username}', 419 - }); 420 - } 222 + /** 223 + * Update user 224 + * This can only be done by the logged in user. 225 + */ 226 + export const updateUser = (options: Options<UpdateUserData>) => (options?.client ?? client).put<UpdateUserResponse, UpdateUserError>({ 227 + ...options, 228 + url: '/user/{username}', 229 + }); 421 230 422 - /** 423 - * Delete user 424 - * This can only be done by the logged in user. 425 - * @param data The data for the request. 426 - * @param data.username The name that needs to be deleted 427 - * @throws ApiError 428 - */ 429 - public static deleteUser( 430 - data: $OpenApiTs['/user/{username}']['delete']['req'], 431 - ): CancelablePromise<void> { 432 - return __request(OpenAPI, { 433 - errors: { 434 - 400: 'Invalid username supplied', 435 - 404: 'User not found', 436 - }, 437 - method: 'DELETE', 438 - path: { 439 - username: data.username, 440 - }, 441 - url: '/user/{username}', 442 - }); 443 - } 444 - } 231 + /** 232 + * Delete user 233 + * This can only be done by the logged in user. 234 + */ 235 + export const deleteUser = (options: Options<DeleteUserData>) => (options?.client ?? client).delete<void>({ 236 + ...options, 237 + url: '/user/{username}', 238 + });
+311 -153
examples/openapi-ts-axios/src/client/types.gen.ts
··· 12 12 complete?: boolean; 13 13 }; 14 14 15 + /** 16 + * Order Status 17 + */ 18 + export type status = 'placed' | 'approved' | 'delivered'; 19 + 20 + /** 21 + * Order Status 22 + */ 23 + export const status = { 24 + APPROVED: 'approved', 25 + DELIVERED: 'delivered', 26 + PLACED: 'placed', 27 + } as const; 28 + 15 29 export type Customer = { 16 30 id?: number; 17 31 username?: string; ··· 61 75 status?: 'available' | 'pending' | 'sold'; 62 76 }; 63 77 78 + /** 79 + * pet status in the store 80 + */ 81 + export type status2 = 'available' | 'pending' | 'sold'; 82 + 83 + /** 84 + * pet status in the store 85 + */ 86 + export const status2 = { 87 + AVAILABLE: 'available', 88 + PENDING: 'pending', 89 + SOLD: 'sold', 90 + } as const; 91 + 64 92 export type ApiResponse = { 65 93 code?: number; 66 94 type?: string; 67 95 message?: string; 68 96 }; 69 97 98 + export type AddPetData = { 99 + /** 100 + * Create a new pet in the store 101 + */ 102 + body: Pet; 103 + }; 104 + 105 + export type AddPetResponse = Pet; 106 + 107 + export type AddPetError = unknown; 108 + 109 + export type UpdatePetData = { 110 + /** 111 + * Update an existent pet in the store 112 + */ 113 + body: Pet; 114 + }; 115 + 116 + export type UpdatePetResponse = Pet; 117 + 118 + export type UpdatePetError = unknown; 119 + 120 + export type FindPetsByStatusData = { 121 + query?: { 122 + /** 123 + * Status values that need to be considered for filter 124 + */ 125 + status?: 'available' | 'pending' | 'sold'; 126 + }; 127 + }; 128 + 129 + export type FindPetsByStatusResponse = Array<Pet>; 130 + 131 + export type FindPetsByStatusError = unknown; 132 + 133 + export type FindPetsByTagsData = { 134 + query?: { 135 + /** 136 + * Tags to filter by 137 + */ 138 + tags?: Array<string>; 139 + }; 140 + }; 141 + 142 + export type FindPetsByTagsResponse = Array<Pet>; 143 + 144 + export type FindPetsByTagsError = unknown; 145 + 146 + export type GetPetByIdData = { 147 + path: { 148 + /** 149 + * ID of pet to return 150 + */ 151 + petId: number; 152 + }; 153 + }; 154 + 155 + export type GetPetByIdResponse = Pet; 156 + 157 + export type GetPetByIdError = unknown; 158 + 159 + export type UpdatePetWithFormData = { 160 + path: { 161 + /** 162 + * ID of pet that needs to be updated 163 + */ 164 + petId: number; 165 + }; 166 + query?: { 167 + /** 168 + * Name of pet that needs to be updated 169 + */ 170 + name?: string; 171 + /** 172 + * Status of pet that needs to be updated 173 + */ 174 + status?: string; 175 + }; 176 + }; 177 + 178 + export type DeletePetData = { 179 + headers?: { 180 + api_key?: string; 181 + }; 182 + path: { 183 + /** 184 + * Pet id to delete 185 + */ 186 + petId: number; 187 + }; 188 + }; 189 + 190 + export type UploadFileData = { 191 + body?: Blob | File; 192 + path: { 193 + /** 194 + * ID of pet to update 195 + */ 196 + petId: number; 197 + }; 198 + query?: { 199 + /** 200 + * Additional Metadata 201 + */ 202 + additionalMetadata?: string; 203 + }; 204 + }; 205 + 206 + export type UploadFileResponse = ApiResponse; 207 + 208 + export type UploadFileError = unknown; 209 + 210 + export type GetInventoryResponse = { 211 + [key: string]: number; 212 + }; 213 + 214 + export type GetInventoryError = unknown; 215 + 216 + export type PlaceOrderData = { 217 + body?: Order; 218 + }; 219 + 220 + export type PlaceOrderResponse = Order; 221 + 222 + export type PlaceOrderError = unknown; 223 + 224 + export type GetOrderByIdData = { 225 + path: { 226 + /** 227 + * ID of order that needs to be fetched 228 + */ 229 + orderId: number; 230 + }; 231 + }; 232 + 233 + export type GetOrderByIdResponse = Order; 234 + 235 + export type GetOrderByIdError = unknown; 236 + 237 + export type DeleteOrderData = { 238 + path: { 239 + /** 240 + * ID of the order that needs to be deleted 241 + */ 242 + orderId: number; 243 + }; 244 + }; 245 + 246 + export type CreateUserData = { 247 + /** 248 + * Created user object 249 + */ 250 + body?: User; 251 + }; 252 + 253 + export type CreateUserResponse = User; 254 + 255 + export type CreateUserError = unknown; 256 + 257 + export type CreateUsersWithListInputData = { 258 + body?: Array<User>; 259 + }; 260 + 261 + export type CreateUsersWithListInputResponse = User; 262 + 263 + export type CreateUsersWithListInputError = unknown; 264 + 265 + export type LoginUserData = { 266 + query?: { 267 + /** 268 + * The password for login in clear text 269 + */ 270 + password?: string; 271 + /** 272 + * The user name for login 273 + */ 274 + username?: string; 275 + }; 276 + }; 277 + 278 + export type LoginUserResponse = string; 279 + 280 + export type LoginUserError = unknown; 281 + 282 + export type LogoutUserResponse = unknown; 283 + 284 + export type LogoutUserError = unknown; 285 + 286 + export type GetUserByNameData = { 287 + path: { 288 + /** 289 + * The name that needs to be fetched. Use user1 for testing. 290 + */ 291 + username: string; 292 + }; 293 + }; 294 + 295 + export type GetUserByNameResponse = User; 296 + 297 + export type GetUserByNameError = unknown; 298 + 299 + export type UpdateUserData = { 300 + /** 301 + * Update an existent user in the store 302 + */ 303 + body?: User; 304 + path: { 305 + /** 306 + * name that needs to be updated 307 + */ 308 + username: string; 309 + }; 310 + }; 311 + 312 + export type UpdateUserResponse = unknown; 313 + 314 + export type UpdateUserError = unknown; 315 + 316 + export type DeleteUserData = { 317 + path: { 318 + /** 319 + * The name that needs to be deleted 320 + */ 321 + username: string; 322 + }; 323 + }; 324 + 70 325 export type $OpenApiTs = { 71 326 '/pet': { 72 327 post: { 73 - req: { 74 - /** 75 - * Create a new pet in the store 76 - */ 77 - requestBody: Pet; 78 - }; 328 + req: AddPetData; 79 329 res: { 80 330 /** 81 331 * Successful operation 82 332 */ 83 - 200: Pet; 333 + '200': Pet; 84 334 /** 85 335 * Invalid input 86 336 */ 87 - 405: unknown; 337 + '405': unknown; 88 338 }; 89 339 }; 90 340 put: { 91 - req: { 92 - /** 93 - * Update an existent pet in the store 94 - */ 95 - requestBody: Pet; 96 - }; 341 + req: UpdatePetData; 97 342 res: { 98 343 /** 99 344 * Successful operation 100 345 */ 101 - 200: Pet; 346 + '200': Pet; 102 347 /** 103 348 * Invalid ID supplied 104 349 */ 105 - 400: unknown; 350 + '400': unknown; 106 351 /** 107 352 * Pet not found 108 353 */ 109 - 404: unknown; 354 + '404': unknown; 110 355 /** 111 356 * Validation exception 112 357 */ 113 - 405: unknown; 358 + '405': unknown; 114 359 }; 115 360 }; 116 361 }; 117 362 '/pet/findByStatus': { 118 363 get: { 119 - req: { 120 - /** 121 - * Status values that need to be considered for filter 122 - */ 123 - status?: 'available' | 'pending' | 'sold'; 124 - }; 364 + req: FindPetsByStatusData; 125 365 res: { 126 366 /** 127 367 * successful operation 128 368 */ 129 - 200: Array<Pet>; 369 + '200': Array<Pet>; 130 370 /** 131 371 * Invalid status value 132 372 */ 133 - 400: unknown; 373 + '400': unknown; 134 374 }; 135 375 }; 136 376 }; 137 377 '/pet/findByTags': { 138 378 get: { 139 - req: { 140 - /** 141 - * Tags to filter by 142 - */ 143 - tags?: Array<string>; 144 - }; 379 + req: FindPetsByTagsData; 145 380 res: { 146 381 /** 147 382 * successful operation 148 383 */ 149 - 200: Array<Pet>; 384 + '200': Array<Pet>; 150 385 /** 151 386 * Invalid tag value 152 387 */ 153 - 400: unknown; 388 + '400': unknown; 154 389 }; 155 390 }; 156 391 }; 157 392 '/pet/{petId}': { 158 393 get: { 159 - req: { 160 - /** 161 - * ID of pet to return 162 - */ 163 - petId: number; 164 - }; 394 + req: GetPetByIdData; 165 395 res: { 166 396 /** 167 397 * successful operation 168 398 */ 169 - 200: Pet; 399 + '200': Pet; 170 400 /** 171 401 * Invalid ID supplied 172 402 */ 173 - 400: unknown; 403 + '400': unknown; 174 404 /** 175 405 * Pet not found 176 406 */ 177 - 404: unknown; 407 + '404': unknown; 178 408 }; 179 409 }; 180 410 post: { 181 - req: { 182 - /** 183 - * Name of pet that needs to be updated 184 - */ 185 - name?: string; 186 - /** 187 - * ID of pet that needs to be updated 188 - */ 189 - petId: number; 190 - /** 191 - * Status of pet that needs to be updated 192 - */ 193 - status?: string; 194 - }; 411 + req: UpdatePetWithFormData; 195 412 res: { 196 413 /** 197 414 * Invalid input 198 415 */ 199 - 405: unknown; 416 + '405': unknown; 200 417 }; 201 418 }; 202 419 delete: { 203 - req: { 204 - apiKey?: string; 205 - /** 206 - * Pet id to delete 207 - */ 208 - petId: number; 209 - }; 420 + req: DeletePetData; 210 421 res: { 211 422 /** 212 423 * Invalid pet value 213 424 */ 214 - 400: unknown; 425 + '400': unknown; 215 426 }; 216 427 }; 217 428 }; 218 429 '/pet/{petId}/uploadImage': { 219 430 post: { 220 - req: { 221 - /** 222 - * Additional Metadata 223 - */ 224 - additionalMetadata?: string; 225 - /** 226 - * ID of pet to update 227 - */ 228 - petId: number; 229 - requestBody?: Blob | File; 230 - }; 431 + req: UploadFileData; 231 432 res: { 232 433 /** 233 434 * successful operation 234 435 */ 235 - 200: ApiResponse; 436 + '200': ApiResponse; 236 437 }; 237 438 }; 238 439 }; ··· 242 443 /** 243 444 * successful operation 244 445 */ 245 - 200: { 446 + '200': { 246 447 [key: string]: number; 247 448 }; 248 449 }; ··· 250 451 }; 251 452 '/store/order': { 252 453 post: { 253 - req: { 254 - requestBody?: Order; 255 - }; 454 + req: PlaceOrderData; 256 455 res: { 257 456 /** 258 457 * successful operation 259 458 */ 260 - 200: Order; 459 + '200': Order; 261 460 /** 262 461 * Invalid input 263 462 */ 264 - 405: unknown; 463 + '405': unknown; 265 464 }; 266 465 }; 267 466 }; 268 467 '/store/order/{orderId}': { 269 468 get: { 270 - req: { 271 - /** 272 - * ID of order that needs to be fetched 273 - */ 274 - orderId: number; 275 - }; 469 + req: GetOrderByIdData; 276 470 res: { 277 471 /** 278 472 * successful operation 279 473 */ 280 - 200: Order; 474 + '200': Order; 281 475 /** 282 476 * Invalid ID supplied 283 477 */ 284 - 400: unknown; 478 + '400': unknown; 285 479 /** 286 480 * Order not found 287 481 */ 288 - 404: unknown; 482 + '404': unknown; 289 483 }; 290 484 }; 291 485 delete: { 292 - req: { 293 - /** 294 - * ID of the order that needs to be deleted 295 - */ 296 - orderId: number; 297 - }; 486 + req: DeleteOrderData; 298 487 res: { 299 488 /** 300 489 * Invalid ID supplied 301 490 */ 302 - 400: unknown; 491 + '400': unknown; 303 492 /** 304 493 * Order not found 305 494 */ 306 - 404: unknown; 495 + '404': unknown; 307 496 }; 308 497 }; 309 498 }; 310 499 '/user': { 311 500 post: { 312 - req: { 313 - /** 314 - * Created user object 315 - */ 316 - requestBody?: User; 317 - }; 501 + req: CreateUserData; 318 502 res: { 319 503 /** 320 504 * successful operation 321 505 */ 322 - 200: User; 506 + default: User; 323 507 }; 324 508 }; 325 509 }; 326 510 '/user/createWithList': { 327 511 post: { 328 - req: { 329 - requestBody?: Array<User>; 330 - }; 512 + req: CreateUsersWithListInputData; 331 513 res: { 332 514 /** 515 + * Successful operation 516 + */ 517 + '200': User; 518 + /** 333 519 * successful operation 334 520 */ 335 - 200: unknown; 521 + default: unknown; 336 522 }; 337 523 }; 338 524 }; 339 525 '/user/login': { 340 526 get: { 341 - req: { 342 - /** 343 - * The password for login in clear text 344 - */ 345 - password?: string; 346 - /** 347 - * The user name for login 348 - */ 349 - username?: string; 350 - }; 527 + req: LoginUserData; 351 528 res: { 352 529 /** 353 530 * successful operation 354 531 */ 355 - 200: string; 532 + '200': string; 356 533 /** 357 534 * Invalid username/password supplied 358 535 */ 359 - 400: unknown; 536 + '400': unknown; 360 537 }; 361 538 }; 362 539 }; ··· 366 543 /** 367 544 * successful operation 368 545 */ 369 - 200: unknown; 546 + default: unknown; 370 547 }; 371 548 }; 372 549 }; 373 550 '/user/{username}': { 374 551 get: { 375 - req: { 376 - /** 377 - * The name that needs to be fetched. Use user1 for testing. 378 - */ 379 - username: string; 380 - }; 552 + req: GetUserByNameData; 381 553 res: { 382 554 /** 383 555 * successful operation 384 556 */ 385 - 200: User; 557 + '200': User; 386 558 /** 387 559 * Invalid username supplied 388 560 */ 389 - 400: unknown; 561 + '400': unknown; 390 562 /** 391 563 * User not found 392 564 */ 393 - 404: unknown; 565 + '404': unknown; 394 566 }; 395 567 }; 396 568 put: { 397 - req: { 398 - /** 399 - * Update an existent user in the store 400 - */ 401 - requestBody?: User; 402 - /** 403 - * name that needs to be updated 404 - */ 405 - username: string; 406 - }; 569 + req: UpdateUserData; 407 570 res: { 408 571 /** 409 572 * successful operation 410 573 */ 411 - 200: unknown; 574 + default: unknown; 412 575 }; 413 576 }; 414 577 delete: { 415 - req: { 416 - /** 417 - * The name that needs to be deleted 418 - */ 419 - username: string; 420 - }; 578 + req: DeleteUserData; 421 579 res: { 422 580 /** 423 581 * Invalid username supplied 424 582 */ 425 - 400: unknown; 583 + '400': unknown; 426 584 /** 427 585 * User not found 428 586 */ 429 - 404: unknown; 587 + '404': unknown; 430 588 }; 431 589 }; 432 590 };
-68
examples/openapi-ts-axios/src/index.css
··· 1 - :root { 2 - font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif; 3 - line-height: 1.5; 4 - font-weight: 400; 5 - 6 - color-scheme: light dark; 7 - color: rgba(255, 255, 255, 0.87); 8 - background-color: #242424; 9 - 10 - font-synthesis: none; 11 - text-rendering: optimizeLegibility; 12 - -webkit-font-smoothing: antialiased; 13 - -moz-osx-font-smoothing: grayscale; 14 - } 15 - 16 - a { 17 - font-weight: 500; 18 - color: #646cff; 19 - text-decoration: inherit; 20 - } 21 - a:hover { 22 - color: #535bf2; 23 - } 24 - 25 - body { 26 - margin: 0; 27 - display: flex; 28 - place-items: center; 29 - min-width: 320px; 30 - min-height: 100vh; 31 - } 32 - 33 - h1 { 34 - font-size: 3.2em; 35 - line-height: 1.1; 36 - } 37 - 38 - button { 39 - border-radius: 8px; 40 - border: 1px solid transparent; 41 - padding: 0.6em 1.2em; 42 - font-size: 1em; 43 - font-weight: 500; 44 - font-family: inherit; 45 - background-color: #1a1a1a; 46 - cursor: pointer; 47 - transition: border-color 0.25s; 48 - } 49 - button:hover { 50 - border-color: #646cff; 51 - } 52 - button:focus, 53 - button:focus-visible { 54 - outline: 4px auto -webkit-focus-ring-color; 55 - } 56 - 57 - @media (prefers-color-scheme: light) { 58 - :root { 59 - color: #213547; 60 - background-color: #ffffff; 61 - } 62 - a:hover { 63 - color: #747bff; 64 - } 65 - button { 66 - background-color: #f9f9f9; 67 - } 68 - }
+5 -2
examples/openapi-ts-axios/src/main.tsx
··· 1 - import './index.css'; 1 + import '@radix-ui/themes/styles.css'; 2 2 3 + import { Theme } from '@radix-ui/themes'; 3 4 import React from 'react'; 4 5 import ReactDOM from 'react-dom/client'; 5 6 ··· 7 8 8 9 ReactDOM.createRoot(document.getElementById('root')!).render( 9 10 <React.StrictMode> 10 - <App /> 11 + <Theme appearance="dark"> 12 + <App /> 13 + </Theme> 11 14 </React.StrictMode>, 12 15 );
+8
examples/openapi-ts-axios/tailwind.config.js
··· 1 + /** @type {import('tailwindcss').Config} */ 2 + export default { 3 + content: ['./index.html', './src/**/*.{html,js,ts,jsx,tsx}'], 4 + plugins: [], 5 + theme: { 6 + extend: {}, 7 + }, 8 + };
+40 -22
pnpm-lock.yaml
··· 87 87 '@hey-api/client-axios': 88 88 specifier: workspace:* 89 89 version: link:../../packages/client-axios 90 + '@radix-ui/react-form': 91 + specifier: 0.0.3 92 + version: 0.0.3(@types/react-dom@18.3.0)(@types/react@18.3.3)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) 93 + '@radix-ui/react-icons': 94 + specifier: 1.3.0 95 + version: 1.3.0(react@18.3.1) 96 + '@radix-ui/themes': 97 + specifier: 3.0.5 98 + version: 3.0.5(@types/react-dom@18.3.0)(@types/react@18.3.3)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) 90 99 axios: 91 100 specifier: 1.7.2 92 101 version: 1.7.2 ··· 115 124 '@vitejs/plugin-react': 116 125 specifier: 4.3.0 117 126 version: 4.3.0(vite@5.2.11(@types/node@20.12.12)(less@4.2.0)(sass@1.71.1)(terser@5.31.0)) 127 + autoprefixer: 128 + specifier: 10.4.19 129 + version: 10.4.19(postcss@8.4.38) 118 130 eslint: 119 131 specifier: 9.3.0 120 132 version: 9.3.0 ··· 124 136 eslint-plugin-react-refresh: 125 137 specifier: 0.4.7 126 138 version: 0.4.7(eslint@9.3.0) 139 + postcss: 140 + specifier: 8.4.38 141 + version: 8.4.38 127 142 prettier: 128 143 specifier: 3.2.5 129 144 version: 3.2.5 145 + tailwindcss: 146 + specifier: 3.4.3 147 + version: 3.4.3(ts-node@10.9.2(@types/node@20.12.12)(typescript@5.4.5)) 130 148 typescript: 131 149 specifier: 5.4.5 132 150 version: 5.4.5 ··· 10624 10642 dom-serializer: 2.0.0 10625 10643 domhandler: 5.0.3 10626 10644 htmlparser2: 8.0.2 10627 - postcss: 8.4.35 10645 + postcss: 8.4.38 10628 10646 postcss-media-query-parser: 0.2.3 10629 10647 10630 10648 cross-spawn@5.1.0: ··· 10641 10659 10642 10660 css-loader@6.10.0(webpack@5.90.3(esbuild@0.20.1)): 10643 10661 dependencies: 10644 - icss-utils: 5.1.0(postcss@8.4.35) 10645 - postcss: 8.4.35 10646 - postcss-modules-extract-imports: 3.1.0(postcss@8.4.35) 10647 - postcss-modules-local-by-default: 4.0.5(postcss@8.4.35) 10648 - postcss-modules-scope: 3.2.0(postcss@8.4.35) 10649 - postcss-modules-values: 4.0.0(postcss@8.4.35) 10662 + icss-utils: 5.1.0(postcss@8.4.38) 10663 + postcss: 8.4.38 10664 + postcss-modules-extract-imports: 3.1.0(postcss@8.4.38) 10665 + postcss-modules-local-by-default: 4.0.5(postcss@8.4.38) 10666 + postcss-modules-scope: 3.2.0(postcss@8.4.38) 10667 + postcss-modules-values: 4.0.0(postcss@8.4.38) 10650 10668 postcss-value-parser: 4.2.0 10651 10669 semver: 7.6.2 10652 10670 optionalDependencies: ··· 11661 11679 dependencies: 11662 11680 safer-buffer: 2.1.2 11663 11681 11664 - icss-utils@5.1.0(postcss@8.4.35): 11682 + icss-utils@5.1.0(postcss@8.4.38): 11665 11683 dependencies: 11666 - postcss: 8.4.35 11684 + postcss: 8.4.38 11667 11685 11668 11686 ieee754@1.2.1: {} 11669 11687 ··· 12757 12775 12758 12776 postcss-media-query-parser@0.2.3: {} 12759 12777 12760 - postcss-modules-extract-imports@3.1.0(postcss@8.4.35): 12778 + postcss-modules-extract-imports@3.1.0(postcss@8.4.38): 12761 12779 dependencies: 12762 - postcss: 8.4.35 12780 + postcss: 8.4.38 12763 12781 12764 - postcss-modules-local-by-default@4.0.5(postcss@8.4.35): 12782 + postcss-modules-local-by-default@4.0.5(postcss@8.4.38): 12765 12783 dependencies: 12766 - icss-utils: 5.1.0(postcss@8.4.35) 12767 - postcss: 8.4.35 12784 + icss-utils: 5.1.0(postcss@8.4.38) 12785 + postcss: 8.4.38 12768 12786 postcss-selector-parser: 6.0.16 12769 12787 postcss-value-parser: 4.2.0 12770 12788 12771 - postcss-modules-scope@3.2.0(postcss@8.4.35): 12789 + postcss-modules-scope@3.2.0(postcss@8.4.38): 12772 12790 dependencies: 12773 - postcss: 8.4.35 12791 + postcss: 8.4.38 12774 12792 postcss-selector-parser: 6.0.16 12775 12793 12776 - postcss-modules-values@4.0.0(postcss@8.4.35): 12794 + postcss-modules-values@4.0.0(postcss@8.4.38): 12777 12795 dependencies: 12778 - icss-utils: 5.1.0(postcss@8.4.35) 12779 - postcss: 8.4.35 12796 + icss-utils: 5.1.0(postcss@8.4.38) 12797 + postcss: 8.4.38 12780 12798 12781 12799 postcss-nested@6.0.1(postcss@8.4.38): 12782 12800 dependencies: ··· 13080 13098 adjust-sourcemap-loader: 4.0.0 13081 13099 convert-source-map: 1.9.0 13082 13100 loader-utils: 2.0.4 13083 - postcss: 8.4.35 13101 + postcss: 8.4.38 13084 13102 source-map: 0.6.1 13085 13103 13086 13104 resolve@1.22.8: ··· 13580 13598 is-glob: 4.0.3 13581 13599 jiti: 1.21.0 13582 13600 lilconfig: 2.1.0 13583 - micromatch: 4.0.6 13601 + micromatch: 4.0.7 13584 13602 normalize-path: 3.0.0 13585 13603 object-hash: 3.0.0 13586 13604 picocolors: 1.0.1 ··· 13911 13929 vite@5.1.7(@types/node@20.12.12)(less@4.2.0)(sass@1.71.1)(terser@5.29.1): 13912 13930 dependencies: 13913 13931 esbuild: 0.19.12 13914 - postcss: 8.4.35 13932 + postcss: 8.4.38 13915 13933 rollup: 4.18.0 13916 13934 optionalDependencies: 13917 13935 '@types/node': 20.12.12