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

Configure Feed

Select the types of activity you want to include in your feed.

chore: use operation data type in openapi type tree

Lubos 93a6308e d13cfd26

+680 -2001
+2 -1
examples/openapi-ts-fetch/openapi-ts.config.ts
··· 4 4 base: 'https://petstore3.swagger.io/api/v3', 5 5 format: 'prettier', 6 6 input: 7 - 'https://raw.githubusercontent.com/swagger-api/swagger-petstore/master/src/main/resources/openapi.yaml', 7 + // 'https://raw.githubusercontent.com/swagger-api/swagger-petstore/master/src/main/resources/openapi.yaml', 8 + 'https://raw.githubusercontent.com/Redocly/museum-openapi-example/main/openapi.yaml', 8 9 lint: 'eslint', 9 10 output: './src/client', 10 11 });
+217 -171
examples/openapi-ts-fetch/src/client/schemas.gen.ts
··· 1 1 // This file is auto-generated by @hey-api/openapi-ts 2 2 3 - export const $Order = { 3 + export const $TicketType = { 4 + description: 5 + 'Type of ticket being purchased. Use `general` for regular museum entry and `event` for tickets to special events.', 6 + enum: ['event', 'general'], 7 + example: 'event', 8 + type: 'string', 9 + } as const; 10 + 11 + export const $Date = { 12 + example: '2023-10-29', 13 + format: 'date', 14 + type: 'string', 15 + } as const; 16 + 17 + export const $Email = { 18 + description: 'Email address for ticket purchaser.', 19 + example: 'museum-lover@example.com', 20 + format: 'email', 21 + type: 'string', 22 + } as const; 23 + 24 + export const $Phone = { 25 + description: 'Phone number for the ticket purchaser (optional).', 26 + example: '+1(234)-567-8910', 27 + type: 'string', 28 + } as const; 29 + 30 + export const $BuyMuseumTicketsRequest = { 31 + description: 'Request payload used for purchasing museum tickets.', 4 32 properties: { 5 - complete: { 6 - type: 'boolean', 33 + email: { 34 + $ref: '#/components/schemas/Email', 7 35 }, 8 - id: { 9 - example: 10, 10 - format: 'int64', 11 - type: 'integer', 36 + eventId: { 37 + $ref: '#/components/schemas/EventId', 38 + description: 39 + "Unique identifier for a special event. Required if purchasing tickets for the museum's special events.", 12 40 }, 13 - petId: { 14 - example: 198772, 15 - format: 'int64', 16 - type: 'integer', 41 + phone: { 42 + $ref: '#/components/schemas/Phone', 17 43 }, 18 - quantity: { 19 - example: 7, 20 - format: 'int32', 21 - type: 'integer', 22 - }, 23 - shipDate: { 24 - format: 'date-time', 25 - type: 'string', 44 + ticketDate: { 45 + $ref: '#/components/schemas/Date', 46 + description: 'Date that the ticket is valid for.', 26 47 }, 27 - status: { 28 - description: 'Order Status', 29 - enum: ['placed', 'approved', 'delivered'], 30 - example: 'approved', 31 - type: 'string', 48 + ticketType: { 49 + $ref: '#/components/schemas/TicketType', 32 50 }, 33 51 }, 52 + required: ['ticketType', 'ticketDate', 'email'], 34 53 type: 'object', 35 - 'x-swagger-router-model': 'io.swagger.petstore.model.Order', 36 - xml: { 37 - name: 'order', 38 - }, 39 54 } as const; 40 55 41 - export const $Customer = { 56 + export const $TicketMessage = { 57 + description: 'Confirmation message after a ticket purchase.', 58 + example: 'Museum general entry ticket purchased', 59 + type: 'string', 60 + } as const; 61 + 62 + export const $TicketId = { 63 + description: 'Unique identifier for museum ticket. Generated when purchased.', 64 + example: 'a54a57ca-36f8-421b-a6b4-2e8f26858a4c', 65 + format: 'uuid', 66 + type: 'string', 67 + } as const; 68 + 69 + export const $TicketConfirmation = { 70 + description: 'Unique confirmation code used to verify ticket purchase.', 71 + example: 'ticket-event-a98c8f-7eb12', 72 + type: 'string', 73 + } as const; 74 + 75 + export const $BuyMuseumTicketsResponse = { 76 + description: 'Details for a museum ticket after a successful purchase.', 42 77 properties: { 43 - address: { 44 - items: { 45 - $ref: '#/components/schemas/Address', 46 - }, 47 - type: 'array', 48 - xml: { 49 - name: 'addresses', 50 - wrapped: true, 51 - }, 78 + confirmationCode: { 79 + $ref: '#/components/schemas/TicketConfirmation', 80 + }, 81 + eventName: { 82 + $ref: '#/components/schemas/EventName', 83 + }, 84 + message: { 85 + $ref: '#/components/schemas/TicketMessage', 86 + }, 87 + ticketDate: { 88 + $ref: '#/components/schemas/Date', 89 + description: 'Date the ticket is valid for.', 52 90 }, 53 - id: { 54 - example: 100000, 55 - format: 'int64', 56 - type: 'integer', 91 + ticketId: { 92 + $ref: '#/components/schemas/TicketId', 57 93 }, 58 - username: { 59 - example: 'fehguy', 60 - type: 'string', 94 + ticketType: { 95 + $ref: '#/components/schemas/TicketType', 61 96 }, 62 97 }, 98 + required: [ 99 + 'message', 100 + 'ticketId', 101 + 'ticketType', 102 + 'ticketDate', 103 + 'confirmationCode', 104 + ], 63 105 type: 'object', 64 - xml: { 65 - name: 'customer', 106 + } as const; 107 + 108 + export const $GetTicketCodeResponse = { 109 + description: 110 + 'Image of a ticket with a QR code used for museum or event entry.', 111 + format: 'binary', 112 + type: 'string', 113 + } as const; 114 + 115 + export const $GetMuseumHoursResponse = { 116 + description: 'List of museum operating hours for consecutive days.', 117 + items: { 118 + $ref: '#/components/schemas/MuseumDailyHours', 66 119 }, 120 + type: 'array', 67 121 } as const; 68 122 69 - export const $Address = { 123 + export const $MuseumDailyHours = { 124 + description: 'Daily operating hours for the museum.', 70 125 properties: { 71 - city: { 72 - example: 'Palo Alto', 73 - type: 'string', 74 - }, 75 - state: { 76 - example: 'CA', 77 - type: 'string', 126 + date: { 127 + $ref: '#/components/schemas/Date', 128 + description: 'Date the operating hours apply to.', 129 + example: '2024-12-31', 78 130 }, 79 - street: { 80 - example: '437 Lytton', 131 + timeClose: { 132 + description: 133 + 'Time the museum closes on a specific date. Uses 24 hour time format (`HH:mm`).', 134 + example: '18:00', 135 + pattern: '^([01]\\d|2[0-3]):?([0-5]\\d)$', 81 136 type: 'string', 82 137 }, 83 - zip: { 84 - example: 94301, 138 + timeOpen: { 139 + description: 140 + 'Time the museum opens on a specific date. Uses 24 hour time format (`HH:mm`).', 141 + example: '09:00', 142 + pattern: '^([01]\\d|2[0-3]):?([0-5]\\d)$', 85 143 type: 'string', 86 144 }, 87 145 }, 146 + required: ['date', 'timeOpen', 'timeClose'], 88 147 type: 'object', 89 - xml: { 90 - name: 'address', 91 - }, 92 148 } as const; 93 149 94 - export const $Category = { 95 - properties: { 96 - id: { 97 - example: 1, 98 - format: 'int64', 99 - type: 'integer', 100 - }, 101 - name: { 102 - example: 'Dogs', 103 - type: 'string', 104 - }, 105 - }, 106 - type: 'object', 107 - 'x-swagger-router-model': 'io.swagger.petstore.model.Category', 108 - xml: { 109 - name: 'category', 150 + export const $EventId = { 151 + description: 'Identifier for a special event.', 152 + example: '3be6453c-03eb-4357-ae5a-984a0e574a54', 153 + format: 'uuid', 154 + type: 'string', 155 + } as const; 156 + 157 + export const $EventName = { 158 + description: 'Name of the special event.', 159 + example: 'Pirate Coding Workshop', 160 + type: 'string', 161 + } as const; 162 + 163 + export const $EventLocation = { 164 + description: 'Location where the special event is held.', 165 + example: 'Computer Room', 166 + type: 'string', 167 + } as const; 168 + 169 + export const $EventDescription = { 170 + description: 'Description of the special event.', 171 + example: 172 + 'Captain Blackbeard shares his love of the C...language. And possibly Arrrrr (R lang).', 173 + type: 'string', 174 + } as const; 175 + 176 + export const $EventDates = { 177 + description: 'List of planned dates for the special event.', 178 + items: { 179 + $ref: '#/components/schemas/Date', 110 180 }, 181 + type: 'array', 111 182 } as const; 112 183 113 - export const $User = { 184 + export const $EventPrice = { 185 + description: 'Price of a ticket for the special event.', 186 + example: 25, 187 + format: 'float', 188 + type: 'number', 189 + } as const; 190 + 191 + export const $CreateSpecialEventRequest = { 192 + description: 'Request payload for creating new special events at the museum.', 114 193 properties: { 115 - email: { 116 - example: 'john@email.com', 117 - type: 'string', 194 + dates: { 195 + $ref: '#/components/schemas/EventDates', 118 196 }, 119 - firstName: { 120 - example: 'John', 121 - type: 'string', 122 - }, 123 - id: { 124 - example: 10, 125 - format: 'int64', 126 - type: 'integer', 127 - }, 128 - lastName: { 129 - example: 'James', 130 - type: 'string', 131 - }, 132 - password: { 133 - example: 12345, 134 - type: 'string', 197 + eventDescription: { 198 + $ref: '#/components/schemas/EventDescription', 135 199 }, 136 - phone: { 137 - example: 12345, 138 - type: 'string', 200 + location: { 201 + $ref: '#/components/schemas/EventLocation', 139 202 }, 140 - userStatus: { 141 - description: 'User Status', 142 - example: 1, 143 - format: 'int32', 144 - type: 'integer', 203 + name: { 204 + $ref: '#/components/schemas/EventName', 145 205 }, 146 - username: { 147 - example: 'theUser', 148 - type: 'string', 206 + price: { 207 + $ref: '#/components/schemas/EventPrice', 149 208 }, 150 209 }, 210 + required: ['name', 'location', 'eventDescription', 'dates', 'price'], 151 211 type: 'object', 152 - 'x-swagger-router-model': 'io.swagger.petstore.model.User', 153 - xml: { 154 - name: 'user', 155 - }, 156 212 } as const; 157 213 158 - export const $Tag = { 214 + export const $UpdateSpecialEventRequest = { 215 + description: 216 + 'Request payload for updating an existing special event. Only included fields are updated in the event.', 159 217 properties: { 160 - id: { 161 - format: 'int64', 162 - type: 'integer', 218 + dates: { 219 + $ref: '#/components/schemas/EventDates', 220 + }, 221 + eventDescription: { 222 + $ref: '#/components/schemas/EventDescription', 223 + }, 224 + location: { 225 + $ref: '#/components/schemas/EventLocation', 163 226 }, 164 227 name: { 165 - type: 'string', 228 + $ref: '#/components/schemas/EventName', 229 + }, 230 + price: { 231 + $ref: '#/components/schemas/EventPrice', 166 232 }, 167 233 }, 168 234 type: 'object', 169 - 'x-swagger-router-model': 'io.swagger.petstore.model.Tag', 170 - xml: { 171 - name: 'tag', 235 + } as const; 236 + 237 + export const $ListSpecialEventsResponse = { 238 + description: 'List of upcoming special events.', 239 + items: { 240 + $ref: '#/components/schemas/SpecialEventResponse', 172 241 }, 242 + type: 'array', 173 243 } as const; 174 244 175 - export const $Pet = { 245 + export const $SpecialEventResponse = { 246 + description: 'Information about a special event.', 176 247 properties: { 177 - category: { 178 - $ref: '#/components/schemas/Category', 248 + dates: { 249 + $ref: '#/components/schemas/EventDates', 179 250 }, 180 - id: { 181 - example: 10, 182 - format: 'int64', 183 - type: 'integer', 251 + eventDescription: { 252 + $ref: '#/components/schemas/EventDescription', 184 253 }, 185 - name: { 186 - example: 'doggie', 187 - type: 'string', 254 + eventId: { 255 + $ref: '#/components/schemas/EventId', 188 256 }, 189 - photoUrls: { 190 - items: { 191 - type: 'string', 192 - xml: { 193 - name: 'photoUrl', 194 - }, 195 - }, 196 - type: 'array', 197 - xml: { 198 - wrapped: true, 199 - }, 257 + location: { 258 + $ref: '#/components/schemas/EventLocation', 200 259 }, 201 - status: { 202 - description: 'pet status in the store', 203 - enum: ['available', 'pending', 'sold'], 204 - type: 'string', 260 + name: { 261 + $ref: '#/components/schemas/EventName', 205 262 }, 206 - tags: { 207 - items: { 208 - $ref: '#/components/schemas/Tag', 209 - xml: { 210 - name: 'tag', 211 - }, 212 - }, 213 - type: 'array', 214 - xml: { 215 - wrapped: true, 216 - }, 263 + price: { 264 + $ref: '#/components/schemas/EventPrice', 217 265 }, 218 266 }, 219 - required: ['name', 'photoUrls'], 267 + required: [ 268 + 'eventId', 269 + 'name', 270 + 'location', 271 + 'eventDescription', 272 + 'dates', 273 + 'price', 274 + ], 220 275 type: 'object', 221 - 'x-swagger-router-model': 'io.swagger.petstore.model.Pet', 222 - xml: { 223 - name: 'pet', 224 - }, 225 276 } as const; 226 277 227 - export const $ApiResponse = { 278 + export const $Error = { 228 279 properties: { 229 - code: { 230 - format: 'int32', 231 - type: 'integer', 232 - }, 233 - message: { 280 + title: { 281 + example: 'Validation failed', 234 282 type: 'string', 235 283 }, 236 284 type: { 285 + example: 'object', 237 286 type: 'string', 238 287 }, 239 288 }, 240 289 type: 'object', 241 - xml: { 242 - name: '##default', 243 - }, 244 290 } as const;
+76 -236
examples/openapi-ts-fetch/src/client/services.gen.ts
··· 3 3 import { client, type Options } from '@hey-api/client-fetch'; 4 4 5 5 import type { 6 - AddPetData, 7 - AddPetResponse, 8 - CreateUserData, 9 - CreateUserResponse, 10 - CreateUsersWithListInputData, 11 - CreateUsersWithListInputResponse, 12 - DeleteOrderData, 13 - DeletePetData, 14 - DeleteUserData, 15 - FindPetsByStatusData, 16 - FindPetsByStatusResponse, 17 - FindPetsByTagsData, 18 - FindPetsByTagsResponse, 19 - GetInventoryResponse, 20 - GetOrderByIdData, 21 - GetOrderByIdResponse, 22 - GetPetByIdData, 23 - GetPetByIdResponse, 24 - GetUserByNameData, 25 - GetUserByNameResponse, 26 - LoginUserData, 27 - LoginUserResponse, 28 - LogoutUserResponse, 29 - PlaceOrderData, 30 - PlaceOrderResponse, 31 - UpdatePetData, 32 - UpdatePetResponse, 33 - UpdatePetWithFormData, 34 - UpdateUserData, 35 - UpdateUserResponse, 36 - UploadFileData, 37 - UploadFileResponse, 6 + BuyMuseumTicketsData, 7 + BuyMuseumTicketsResponse2, 8 + CreateSpecialEventData, 9 + CreateSpecialEventResponse, 10 + DeleteSpecialEventData, 11 + DeleteSpecialEventResponse, 12 + GetMuseumHoursData, 13 + GetMuseumHoursResponse2, 14 + GetSpecialEventData, 15 + GetSpecialEventResponse, 16 + GetTicketCodeData, 17 + GetTicketCodeResponse2, 18 + ListSpecialEventsData, 19 + ListSpecialEventsResponse2, 20 + UpdateSpecialEventData, 21 + UpdateSpecialEventResponse, 38 22 } from './types.gen'; 39 23 40 24 /** 41 - * Add a new pet to the store 42 - * Add a new pet to the store 43 - * @param data The data for the request. 44 - * @param data.requestBody Create a new pet in the store 45 - * @returns Pet Successful operation 46 - * @throws ApiError 47 - */ 48 - export const addPet = (options: Options<AddPetData>) => 49 - client.post<AddPetResponse>({ 50 - ...options, 51 - url: '/pet', 52 - }); 53 - 54 - /** 55 - * Update an existing pet 56 - * Update an existing pet by Id 57 - * @param data The data for the request. 58 - * @param data.requestBody Update an existent pet in the store 59 - * @returns Pet Successful operation 60 - * @throws ApiError 61 - */ 62 - export const updatePet = (options: Options<UpdatePetData>) => 63 - client.put<UpdatePetResponse>({ 64 - ...options, 65 - url: '/pet', 66 - }); 67 - 68 - /** 69 - * Finds Pets by status 70 - * Multiple status values can be provided with comma separated strings 71 - * @param data The data for the request. 72 - * @param data.status Status values that need to be considered for filter 73 - * @returns Pet successful operation 74 - * @throws ApiError 75 - */ 76 - export const findPetsByStatus = (options?: Options<FindPetsByStatusData>) => 77 - client.get<FindPetsByStatusResponse>({ 78 - ...options, 79 - url: '/pet/findByStatus', 80 - }); 81 - 82 - /** 83 - * Finds Pets by tags 84 - * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. 85 - * @param data The data for the request. 86 - * @param data.tags Tags to filter by 87 - * @returns Pet successful operation 88 - * @throws ApiError 89 - */ 90 - export const findPetsByTags = (options?: Options<FindPetsByTagsData>) => 91 - client.get<FindPetsByTagsResponse>({ 92 - ...options, 93 - url: '/pet/findByTags', 94 - }); 95 - 96 - /** 97 - * Find pet by ID 98 - * Returns a single pet 99 - * @param data The data for the request. 100 - * @param data.petId ID of pet to return 101 - * @returns Pet successful operation 102 - * @throws ApiError 103 - */ 104 - export const getPetById = (options: Options<GetPetByIdData>) => 105 - client.get<GetPetByIdResponse>({ 106 - ...options, 107 - url: '/pet/{petId}', 108 - }); 109 - 110 - /** 111 - * Updates a pet in the store with form data 112 - * @param data The data for the request. 113 - * @param data.petId ID of pet that needs to be updated 114 - * @param data.name Name of pet that needs to be updated 115 - * @param data.status Status of pet that needs to be updated 116 - * @throws ApiError 117 - */ 118 - export const updatePetWithForm = (options: Options<UpdatePetWithFormData>) => 119 - client.post<void>({ 120 - ...options, 121 - url: '/pet/{petId}', 122 - }); 123 - 124 - /** 125 - * Deletes a pet 25 + * Get museum hours 26 + * Get upcoming museum operating hours. 126 27 * @param data The data for the request. 127 - * @param data.petId Pet id to delete 128 - * @param data.apiKey 129 - * @throws ApiError 130 - */ 131 - export const deletePet = (options: Options<DeletePetData>) => 132 - client.delete<void>({ 133 - ...options, 134 - url: '/pet/{petId}', 135 - }); 136 - 137 - /** 138 - * uploads an image 139 - * @param data The data for the request. 140 - * @param data.petId ID of pet to update 141 - * @param data.additionalMetadata Additional Metadata 142 - * @param data.requestBody 143 - * @returns ApiResponse successful operation 144 - * @throws ApiError 145 - */ 146 - export const uploadFile = (options: Options<UploadFileData>) => 147 - client.post<UploadFileResponse>({ 148 - ...options, 149 - url: '/pet/{petId}/uploadImage', 150 - }); 151 - 152 - /** 153 - * Returns pet inventories by status 154 - * Returns a map of status codes to quantities 155 - * @returns number successful operation 28 + * @param data.startDate Starting date to retrieve future operating hours from. Defaults to today's date. 29 + * @param data.page Page number to retrieve. 30 + * @param data.limit Number of days per page. 31 + * @returns GetMuseumHoursResponse Success. 156 32 * @throws ApiError 157 33 */ 158 - export const getInventory = (options?: Options) => 159 - client.get<GetInventoryResponse>({ 34 + export const getMuseumHours = (options?: Options<GetMuseumHoursData>) => 35 + client.get<GetMuseumHoursResponse2>({ 160 36 ...options, 161 - url: '/store/inventory', 37 + url: '/museum-hours', 162 38 }); 163 39 164 40 /** 165 - * Place an order for a pet 166 - * Place a new order in the store 41 + * Create special events 42 + * Creates a new special event for the museum. 167 43 * @param data The data for the request. 168 44 * @param data.requestBody 169 - * @returns Order successful operation 45 + * @returns SpecialEventResponse Success. 170 46 * @throws ApiError 171 47 */ 172 - export const placeOrder = (options?: Options<PlaceOrderData>) => 173 - client.post<PlaceOrderResponse>({ 174 - ...options, 175 - url: '/store/order', 176 - }); 177 - 178 - /** 179 - * Find purchase order by ID 180 - * For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions. 181 - * @param data The data for the request. 182 - * @param data.orderId ID of order that needs to be fetched 183 - * @returns Order successful operation 184 - * @throws ApiError 185 - */ 186 - export const getOrderById = (options: Options<GetOrderByIdData>) => 187 - client.get<GetOrderByIdResponse>({ 48 + export const createSpecialEvent = (options: Options<CreateSpecialEventData>) => 49 + client.post<CreateSpecialEventResponse>({ 188 50 ...options, 189 - url: '/store/order/{orderId}', 51 + url: '/special-events', 190 52 }); 191 53 192 54 /** 193 - * Delete purchase order by ID 194 - * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors 55 + * List special events 56 + * Return a list of upcoming special events at the museum. 195 57 * @param data The data for the request. 196 - * @param data.orderId ID of the order that needs to be deleted 58 + * @param data.startDate Starting date to retrieve future operating hours from. Defaults to today's date. 59 + * @param data.endDate End of a date range to retrieve special events for. Defaults to 7 days after `startDate`. 60 + * @param data.page Page number to retrieve. 61 + * @param data.limit Number of days per page. 62 + * @returns ListSpecialEventsResponse Success. 197 63 * @throws ApiError 198 64 */ 199 - export const deleteOrder = (options: Options<DeleteOrderData>) => 200 - client.delete<void>({ 65 + export const listSpecialEvents = (options?: Options<ListSpecialEventsData>) => 66 + client.get<ListSpecialEventsResponse2>({ 201 67 ...options, 202 - url: '/store/order/{orderId}', 68 + url: '/special-events', 203 69 }); 204 70 205 71 /** 206 - * Create user 207 - * This can only be done by the logged in user. 72 + * Get special event 73 + * Get details about a special event. 208 74 * @param data The data for the request. 209 - * @param data.requestBody Created user object 210 - * @returns User successful operation 75 + * @param data.eventId Identifier for a special event. 76 + * @returns SpecialEventResponse Success. 211 77 * @throws ApiError 212 78 */ 213 - export const createUser = (options?: Options<CreateUserData>) => 214 - client.post<CreateUserResponse>({ 79 + export const getSpecialEvent = (options: Options<GetSpecialEventData>) => 80 + client.get<GetSpecialEventResponse>({ 215 81 ...options, 216 - url: '/user', 82 + url: '/special-events/{eventId}', 217 83 }); 218 84 219 85 /** 220 - * Creates list of users with given input array 221 - * Creates list of users with given input array 86 + * Update special event 87 + * Update the details of a special event. 222 88 * @param data The data for the request. 89 + * @param data.eventId Identifier for a special event. 223 90 * @param data.requestBody 224 - * @returns User Successful operation 225 - * @returns unknown successful operation 91 + * @returns SpecialEventResponse Success. 226 92 * @throws ApiError 227 93 */ 228 - export const createUsersWithListInput = ( 229 - options?: Options<CreateUsersWithListInputData>, 230 - ) => 231 - client.post<CreateUsersWithListInputResponse>({ 94 + export const updateSpecialEvent = (options: Options<UpdateSpecialEventData>) => 95 + client.patch<UpdateSpecialEventResponse>({ 232 96 ...options, 233 - url: '/user/createWithList', 97 + url: '/special-events/{eventId}', 234 98 }); 235 99 236 100 /** 237 - * Logs user into the system 238 - * @param data The data for the request. 239 - * @param data.username The user name for login 240 - * @param data.password The password for login in clear text 241 - * @returns string successful operation 242 - * @throws ApiError 243 - */ 244 - export const loginUser = (options?: Options<LoginUserData>) => 245 - client.get<LoginUserResponse>({ 246 - ...options, 247 - url: '/user/login', 248 - }); 249 - 250 - /** 251 - * Logs out current logged in user session 252 - * @returns unknown successful operation 253 - * @throws ApiError 254 - */ 255 - export const logoutUser = (options?: Options) => 256 - client.get<LogoutUserResponse>({ 257 - ...options, 258 - url: '/user/logout', 259 - }); 260 - 261 - /** 262 - * Get user by user name 101 + * Delete special event 102 + * Delete a special event from the collection. Allows museum to cancel planned events. 263 103 * @param data The data for the request. 264 - * @param data.username The name that needs to be fetched. Use user1 for testing. 265 - * @returns User successful operation 104 + * @param data.eventId Identifier for a special event. 105 + * @returns void Success - no content. 266 106 * @throws ApiError 267 107 */ 268 - export const getUserByName = (options: Options<GetUserByNameData>) => 269 - client.get<GetUserByNameResponse>({ 108 + export const deleteSpecialEvent = (options: Options<DeleteSpecialEventData>) => 109 + client.delete<DeleteSpecialEventResponse>({ 270 110 ...options, 271 - url: '/user/{username}', 111 + url: '/special-events/{eventId}', 272 112 }); 273 113 274 114 /** 275 - * Update user 276 - * This can only be done by the logged in user. 115 + * Buy museum tickets 116 + * Purchase museum tickets for general entry or special events. 277 117 * @param data The data for the request. 278 - * @param data.username name that needs to be updated 279 - * @param data.requestBody Update an existent user in the store 280 - * @returns unknown successful operation 118 + * @param data.requestBody 119 + * @returns BuyMuseumTicketsResponse Success. 281 120 * @throws ApiError 282 121 */ 283 - export const updateUser = (options: Options<UpdateUserData>) => 284 - client.put<UpdateUserResponse>({ 122 + export const buyMuseumTickets = (options: Options<BuyMuseumTicketsData>) => 123 + client.post<BuyMuseumTicketsResponse2>({ 285 124 ...options, 286 - url: '/user/{username}', 125 + url: '/tickets', 287 126 }); 288 127 289 128 /** 290 - * Delete user 291 - * This can only be done by the logged in user. 129 + * Get ticket QR code 130 + * Return an image of your ticket with scannable QR code. Used for event entry. 292 131 * @param data The data for the request. 293 - * @param data.username The name that needs to be deleted 132 + * @param data.ticketId Identifier for a ticket to a museum event. Used to generate ticket image. 133 + * @returns GetTicketCodeResponse Scannable event ticket in image format. 294 134 * @throws ApiError 295 135 */ 296 - export const deleteUser = (options: Options<DeleteUserData>) => 297 - client.delete<void>({ 136 + export const getTicketCode = (options: Options<GetTicketCodeData>) => 137 + client.get<GetTicketCodeResponse2>({ 298 138 ...options, 299 - url: '/user/{username}', 139 + url: '/tickets/{ticketId}/qr', 300 140 });
+281 -496
examples/openapi-ts-fetch/src/client/types.gen.ts
··· 1 1 // This file is auto-generated by @hey-api/openapi-ts 2 2 3 - export type Order = { 4 - id?: number; 5 - petId?: number; 6 - quantity?: number; 7 - shipDate?: string; 3 + /** 4 + * Type of ticket being purchased. Use `general` for regular museum entry and `event` for tickets to special events. 5 + */ 6 + export type TicketType = 'event' | 'general'; 7 + 8 + export type Date = string; 9 + 10 + /** 11 + * Email address for ticket purchaser. 12 + */ 13 + export type Email = string; 14 + 15 + /** 16 + * Phone number for the ticket purchaser (optional). 17 + */ 18 + export type Phone = string; 19 + 20 + /** 21 + * Request payload used for purchasing museum tickets. 22 + */ 23 + export type BuyMuseumTicketsRequest = { 24 + ticketType: TicketType; 25 + /** 26 + * Unique identifier for a special event. Required if purchasing tickets for the museum's special events. 27 + */ 28 + eventId?: EventId; 8 29 /** 9 - * Order Status 30 + * Date that the ticket is valid for. 10 31 */ 11 - status?: 'placed' | 'approved' | 'delivered'; 12 - complete?: boolean; 32 + ticketDate: Date; 33 + email: Email; 34 + phone?: Phone; 13 35 }; 14 36 15 - export type Customer = { 16 - id?: number; 17 - username?: string; 18 - address?: Array<Address>; 19 - }; 37 + /** 38 + * Confirmation message after a ticket purchase. 39 + */ 40 + export type TicketMessage = string; 20 41 21 - export type Address = { 22 - street?: string; 23 - city?: string; 24 - state?: string; 25 - zip?: string; 26 - }; 42 + /** 43 + * Unique identifier for museum ticket. Generated when purchased. 44 + */ 45 + export type TicketId = string; 27 46 28 - export type Category = { 29 - id?: number; 30 - name?: string; 31 - }; 47 + /** 48 + * Unique confirmation code used to verify ticket purchase. 49 + */ 50 + export type TicketConfirmation = string; 32 51 33 - export type User = { 34 - id?: number; 35 - username?: string; 36 - firstName?: string; 37 - lastName?: string; 38 - email?: string; 39 - password?: string; 40 - phone?: string; 52 + /** 53 + * Details for a museum ticket after a successful purchase. 54 + */ 55 + export type BuyMuseumTicketsResponse = { 56 + message: TicketMessage; 57 + eventName?: EventName; 58 + ticketId: TicketId; 59 + ticketType: TicketType; 41 60 /** 42 - * User Status 61 + * Date the ticket is valid for. 43 62 */ 44 - userStatus?: number; 63 + ticketDate: Date; 64 + confirmationCode: TicketConfirmation; 45 65 }; 46 66 47 - export type Tag = { 48 - id?: number; 49 - name?: string; 50 - }; 67 + /** 68 + * Image of a ticket with a QR code used for museum or event entry. 69 + */ 70 + export type GetTicketCodeResponse = Blob | File; 71 + 72 + /** 73 + * List of museum operating hours for consecutive days. 74 + */ 75 + export type GetMuseumHoursResponse = Array<MuseumDailyHours>; 51 76 52 - export type Pet = { 53 - id?: number; 54 - name: string; 55 - category?: Category; 56 - photoUrls: Array<string>; 57 - tags?: Array<Tag>; 77 + /** 78 + * Daily operating hours for the museum. 79 + */ 80 + export type MuseumDailyHours = { 81 + /** 82 + * Date the operating hours apply to. 83 + */ 84 + date: Date; 85 + /** 86 + * Time the museum opens on a specific date. Uses 24 hour time format (`HH:mm`). 87 + */ 88 + timeOpen: string; 58 89 /** 59 - * pet status in the store 90 + * Time the museum closes on a specific date. Uses 24 hour time format (`HH:mm`). 60 91 */ 61 - status?: 'available' | 'pending' | 'sold'; 92 + timeClose: string; 62 93 }; 63 94 64 - export type ApiResponse = { 65 - code?: number; 66 - type?: string; 67 - message?: string; 95 + /** 96 + * Identifier for a special event. 97 + */ 98 + export type EventId = string; 99 + 100 + /** 101 + * Name of the special event. 102 + */ 103 + export type EventName = string; 104 + 105 + /** 106 + * Location where the special event is held. 107 + */ 108 + export type EventLocation = string; 109 + 110 + /** 111 + * Description of the special event. 112 + */ 113 + export type EventDescription = string; 114 + 115 + /** 116 + * List of planned dates for the special event. 117 + */ 118 + export type EventDates = Array<Date>; 119 + 120 + /** 121 + * Price of a ticket for the special event. 122 + */ 123 + export type EventPrice = number; 124 + 125 + /** 126 + * Request payload for creating new special events at the museum. 127 + */ 128 + export type CreateSpecialEventRequest = { 129 + name: EventName; 130 + location: EventLocation; 131 + eventDescription: EventDescription; 132 + dates: EventDates; 133 + price: EventPrice; 68 134 }; 69 135 70 - export type AddPetData = { 71 - /** 72 - * Create a new pet in the store 73 - */ 74 - body: Pet; 136 + /** 137 + * Request payload for updating an existing special event. Only included fields are updated in the event. 138 + */ 139 + export type UpdateSpecialEventRequest = { 140 + name?: EventName; 141 + location?: EventLocation; 142 + eventDescription?: EventDescription; 143 + dates?: EventDates; 144 + price?: EventPrice; 75 145 }; 76 146 77 - export type AddPetResponse = Pet; 147 + /** 148 + * List of upcoming special events. 149 + */ 150 + export type ListSpecialEventsResponse = Array<SpecialEventResponse>; 78 151 79 - export type UpdatePetData = { 80 - /** 81 - * Update an existent pet in the store 82 - */ 83 - body: Pet; 152 + /** 153 + * Information about a special event. 154 + */ 155 + export type SpecialEventResponse = { 156 + eventId: EventId; 157 + name: EventName; 158 + location: EventLocation; 159 + eventDescription: EventDescription; 160 + dates: EventDates; 161 + price: EventPrice; 84 162 }; 85 163 86 - export type UpdatePetResponse = Pet; 164 + export type Error = { 165 + type?: string; 166 + title?: string; 167 + }; 87 168 88 - export type FindPetsByStatusData = { 89 - query?: { 90 - /** 91 - * Status values that need to be considered for filter 92 - */ 93 - status?: 'available' | 'pending' | 'sold'; 94 - }; 95 - }; 169 + /** 170 + * Page number to retrieve. 171 + */ 172 + export type ParameterPaginationPage = number; 96 173 97 - export type FindPetsByStatusResponse = Array<Pet>; 174 + /** 175 + * Number of days per page. 176 + */ 177 + export type ParameterPaginationLimit = number; 98 178 99 - export type FindPetsByTagsData = { 100 - query?: { 101 - /** 102 - * Tags to filter by 103 - */ 104 - tags?: Array<string>; 105 - }; 106 - }; 179 + /** 180 + * Identifier for a special event. 181 + */ 182 + export type ParameterEventId = string; 107 183 108 - export type FindPetsByTagsResponse = Array<Pet>; 184 + /** 185 + * Starting date to retrieve future operating hours from. Defaults to today's date. 186 + */ 187 + export type ParameterStartDate = string; 109 188 110 - export type GetPetByIdData = { 111 - path: { 112 - /** 113 - * ID of pet to return 114 - */ 115 - petId: number; 116 - }; 117 - }; 189 + /** 190 + * End of a date range to retrieve special events for. Defaults to 7 days after `startDate`. 191 + */ 192 + export type ParameterEndDate = string; 118 193 119 - export type GetPetByIdResponse = Pet; 194 + /** 195 + * Identifier for a ticket to a museum event. Used to generate ticket image. 196 + */ 197 + export type ParameterTicketId = string; 120 198 121 - export type UpdatePetWithFormData = { 122 - path: { 199 + export type GetMuseumHoursData = { 200 + query?: { 123 201 /** 124 - * ID of pet that needs to be updated 202 + * Number of days per page. 125 203 */ 126 - petId: number; 127 - }; 128 - query?: { 204 + limit?: number; 129 205 /** 130 - * Name of pet that needs to be updated 206 + * Page number to retrieve. 131 207 */ 132 - name?: string; 208 + page?: number; 133 209 /** 134 - * Status of pet that needs to be updated 210 + * Starting date to retrieve future operating hours from. Defaults to today's date. 135 211 */ 136 - status?: string; 212 + startDate?: string; 137 213 }; 138 214 }; 139 215 140 - export type DeletePetData = { 141 - header?: { 142 - apiKey?: string; 143 - }; 144 - path: { 145 - /** 146 - * Pet id to delete 147 - */ 148 - petId: number; 149 - }; 216 + export type GetMuseumHoursResponse2 = GetMuseumHoursResponse; 217 + 218 + export type CreateSpecialEventData = { 219 + body: CreateSpecialEventRequest; 150 220 }; 151 221 152 - export type UploadFileData = { 153 - body?: Blob | File; 154 - path: { 222 + export type CreateSpecialEventResponse = SpecialEventResponse; 223 + 224 + export type ListSpecialEventsData = { 225 + query?: { 155 226 /** 156 - * ID of pet to update 227 + * End of a date range to retrieve special events for. Defaults to 7 days after `startDate`. 228 + */ 229 + endDate?: string; 230 + /** 231 + * Number of days per page. 157 232 */ 158 - petId: number; 159 - }; 160 - query?: { 233 + limit?: number; 161 234 /** 162 - * Additional Metadata 235 + * Page number to retrieve. 163 236 */ 164 - additionalMetadata?: string; 165 - }; 166 - }; 167 - 168 - export type UploadFileResponse = ApiResponse; 169 - 170 - export type GetInventoryResponse = { 171 - [key: string]: number; 172 - }; 173 - 174 - export type PlaceOrderData = { 175 - body?: Order; 176 - }; 177 - 178 - export type PlaceOrderResponse = Order; 179 - 180 - export type GetOrderByIdData = { 181 - path: { 237 + page?: number; 182 238 /** 183 - * ID of order that needs to be fetched 239 + * Starting date to retrieve future operating hours from. Defaults to today's date. 184 240 */ 185 - orderId: number; 241 + startDate?: string; 186 242 }; 187 243 }; 188 244 189 - export type GetOrderByIdResponse = Order; 245 + export type ListSpecialEventsResponse2 = ListSpecialEventsResponse; 190 246 191 - export type DeleteOrderData = { 247 + export type GetSpecialEventData = { 192 248 path: { 193 249 /** 194 - * ID of the order that needs to be deleted 250 + * Identifier for a special event. 195 251 */ 196 - orderId: number; 252 + eventId: string; 197 253 }; 198 254 }; 199 255 200 - export type CreateUserData = { 201 - /** 202 - * Created user object 203 - */ 204 - body?: User; 205 - }; 256 + export type GetSpecialEventResponse = SpecialEventResponse; 206 257 207 - export type CreateUserResponse = User; 208 - 209 - export type CreateUsersWithListInputData = { 210 - body?: Array<User>; 211 - }; 212 - 213 - export type CreateUsersWithListInputResponse = User | unknown; 214 - 215 - export type LoginUserData = { 216 - query?: { 217 - /** 218 - * The password for login in clear text 219 - */ 220 - password?: string; 258 + export type UpdateSpecialEventData = { 259 + body: UpdateSpecialEventRequest; 260 + path: { 221 261 /** 222 - * The user name for login 262 + * Identifier for a special event. 223 263 */ 224 - username?: string; 264 + eventId: string; 225 265 }; 226 266 }; 227 267 228 - export type LoginUserResponse = string; 229 - 230 - export type LogoutUserResponse = unknown; 268 + export type UpdateSpecialEventResponse = SpecialEventResponse; 231 269 232 - export type GetUserByNameData = { 270 + export type DeleteSpecialEventData = { 233 271 path: { 234 272 /** 235 - * The name that needs to be fetched. Use user1 for testing. 273 + * Identifier for a special event. 236 274 */ 237 - username: string; 275 + eventId: string; 238 276 }; 239 277 }; 240 278 241 - export type GetUserByNameResponse = User; 279 + export type DeleteSpecialEventResponse = void; 242 280 243 - export type UpdateUserData = { 244 - /** 245 - * Update an existent user in the store 246 - */ 247 - body?: User; 248 - path: { 249 - /** 250 - * name that needs to be updated 251 - */ 252 - username: string; 253 - }; 281 + export type BuyMuseumTicketsData = { 282 + body: BuyMuseumTicketsRequest; 254 283 }; 255 284 256 - export type UpdateUserResponse = unknown; 285 + export type BuyMuseumTicketsResponse2 = BuyMuseumTicketsResponse; 257 286 258 - export type DeleteUserData = { 287 + export type GetTicketCodeData = { 259 288 path: { 260 289 /** 261 - * The name that needs to be deleted 290 + * Identifier for a ticket to a museum event. Used to generate ticket image. 262 291 */ 263 - username: string; 292 + ticketId: string; 264 293 }; 265 294 }; 295 + 296 + export type GetTicketCodeResponse2 = GetTicketCodeResponse; 266 297 267 298 export type $OpenApiTs = { 268 - '/pet': { 269 - post: { 270 - req: { 271 - /** 272 - * Create a new pet in the store 273 - */ 274 - body: Pet; 275 - }; 276 - res: { 277 - /** 278 - * Successful operation 279 - */ 280 - 200: Pet; 281 - /** 282 - * Invalid input 283 - */ 284 - 405: unknown; 285 - }; 286 - }; 287 - put: { 288 - req: { 289 - /** 290 - * Update an existent pet in the store 291 - */ 292 - body: Pet; 293 - }; 294 - res: { 295 - /** 296 - * Successful operation 297 - */ 298 - 200: Pet; 299 - /** 300 - * Invalid ID supplied 301 - */ 302 - 400: unknown; 303 - /** 304 - * Pet not found 305 - */ 306 - 404: unknown; 307 - /** 308 - * Validation exception 309 - */ 310 - 405: unknown; 311 - }; 312 - }; 313 - }; 314 - '/pet/findByStatus': { 299 + '/museum-hours': { 315 300 get: { 316 - req: { 317 - query?: { 318 - /** 319 - * Status values that need to be considered for filter 320 - */ 321 - status?: 'available' | 'pending' | 'sold'; 322 - }; 323 - }; 301 + req: GetMuseumHoursData; 324 302 res: { 325 303 /** 326 - * successful operation 327 - */ 328 - 200: Array<Pet>; 329 - /** 330 - * Invalid status value 304 + * Success. 331 305 */ 332 - 400: unknown; 333 - }; 334 - }; 335 - }; 336 - '/pet/findByTags': { 337 - get: { 338 - req: { 339 - query?: { 340 - /** 341 - * Tags to filter by 342 - */ 343 - tags?: Array<string>; 344 - }; 345 - }; 346 - res: { 306 + 200: GetMuseumHoursResponse; 347 307 /** 348 - * successful operation 308 + * Bad request. 349 309 */ 350 - 200: Array<Pet>; 310 + 400: Error; 351 311 /** 352 - * Invalid tag value 312 + * Not found. 353 313 */ 354 - 400: unknown; 314 + 404: Error; 355 315 }; 356 316 }; 357 317 }; 358 - '/pet/{petId}': { 359 - get: { 360 - req: { 361 - path: { 362 - /** 363 - * ID of pet to return 364 - */ 365 - petId: number; 366 - }; 367 - }; 318 + '/special-events': { 319 + post: { 320 + req: ListSpecialEventsData; 368 321 res: { 369 322 /** 370 - * successful operation 323 + * Success. 371 324 */ 372 - 200: Pet; 325 + 200: SpecialEventResponse; 373 326 /** 374 - * Invalid ID supplied 327 + * Bad request. 375 328 */ 376 - 400: unknown; 329 + 400: Error; 377 330 /** 378 - * Pet not found 331 + * Not found. 379 332 */ 380 - 404: unknown; 333 + 404: Error; 381 334 }; 382 335 }; 383 - post: { 384 - req: { 385 - path: { 386 - /** 387 - * ID of pet that needs to be updated 388 - */ 389 - petId: number; 390 - }; 391 - query?: { 392 - /** 393 - * Name of pet that needs to be updated 394 - */ 395 - name?: string; 396 - /** 397 - * Status of pet that needs to be updated 398 - */ 399 - status?: string; 400 - }; 401 - }; 336 + get: { 337 + req: ListSpecialEventsData; 402 338 res: { 403 339 /** 404 - * Invalid input 340 + * Success. 405 341 */ 406 - 405: unknown; 407 - }; 408 - }; 409 - delete: { 410 - req: { 411 - header?: { 412 - apiKey?: string; 413 - }; 414 - path: { 415 - /** 416 - * Pet id to delete 417 - */ 418 - petId: number; 419 - }; 420 - }; 421 - res: { 342 + 200: ListSpecialEventsResponse; 422 343 /** 423 - * Invalid pet value 344 + * Bad request. 424 345 */ 425 - 400: unknown; 426 - }; 427 - }; 428 - }; 429 - '/pet/{petId}/uploadImage': { 430 - post: { 431 - req: { 432 - body?: Blob | File; 433 - path: { 434 - /** 435 - * ID of pet to update 436 - */ 437 - petId: number; 438 - }; 439 - query?: { 440 - /** 441 - * Additional Metadata 442 - */ 443 - additionalMetadata?: string; 444 - }; 445 - }; 446 - res: { 346 + 400: Error; 447 347 /** 448 - * successful operation 348 + * Not found. 449 349 */ 450 - 200: ApiResponse; 350 + 404: Error; 451 351 }; 452 352 }; 453 353 }; 454 - '/store/inventory': { 354 + '/special-events/{eventId}': { 455 355 get: { 356 + req: DeleteSpecialEventData; 456 357 res: { 457 358 /** 458 - * successful operation 359 + * Success. 459 360 */ 460 - 200: { 461 - [key: string]: number; 462 - }; 463 - }; 464 - }; 465 - }; 466 - '/store/order': { 467 - post: { 468 - req: { 469 - body?: Order; 470 - }; 471 - res: { 361 + 200: SpecialEventResponse; 472 362 /** 473 - * successful operation 363 + * Bad request. 474 364 */ 475 - 200: Order; 365 + 400: Error; 476 366 /** 477 - * Invalid input 367 + * Not found. 478 368 */ 479 - 405: unknown; 369 + 404: Error; 480 370 }; 481 371 }; 482 - }; 483 - '/store/order/{orderId}': { 484 - get: { 485 - req: { 486 - path: { 487 - /** 488 - * ID of order that needs to be fetched 489 - */ 490 - orderId: number; 491 - }; 492 - }; 372 + patch: { 373 + req: DeleteSpecialEventData; 493 374 res: { 494 375 /** 495 - * successful operation 376 + * Success. 496 377 */ 497 - 200: Order; 378 + 200: SpecialEventResponse; 498 379 /** 499 - * Invalid ID supplied 380 + * Bad request. 500 381 */ 501 - 400: unknown; 382 + 400: Error; 502 383 /** 503 - * Order not found 384 + * Not found. 504 385 */ 505 - 404: unknown; 386 + 404: Error; 506 387 }; 507 388 }; 508 389 delete: { 509 - req: { 510 - path: { 511 - /** 512 - * ID of the order that needs to be deleted 513 - */ 514 - orderId: number; 515 - }; 516 - }; 390 + req: DeleteSpecialEventData; 517 391 res: { 518 392 /** 519 - * Invalid ID supplied 393 + * Success - no content. 520 394 */ 521 - 400: unknown; 395 + 204: void; 522 396 /** 523 - * Order not found 397 + * Bad request. 524 398 */ 525 - 404: unknown; 526 - }; 527 - }; 528 - }; 529 - '/user': { 530 - post: { 531 - req: { 399 + 400: Error; 532 400 /** 533 - * Created user object 401 + * Unauthorized. 534 402 */ 535 - body?: User; 536 - }; 537 - res: { 403 + 401: Error; 538 404 /** 539 - * successful operation 405 + * Not found. 540 406 */ 541 - default: User; 407 + 404: Error; 542 408 }; 543 409 }; 544 410 }; 545 - '/user/createWithList': { 411 + '/tickets': { 546 412 post: { 547 - req: { 548 - body?: Array<User>; 549 - }; 550 - res: { 551 - /** 552 - * Successful operation 553 - */ 554 - 200: User; 555 - /** 556 - * successful operation 557 - */ 558 - default: unknown; 559 - }; 560 - }; 561 - }; 562 - '/user/login': { 563 - get: { 564 - req: { 565 - query?: { 566 - /** 567 - * The password for login in clear text 568 - */ 569 - password?: string; 570 - /** 571 - * The user name for login 572 - */ 573 - username?: string; 574 - }; 575 - }; 413 + req: BuyMuseumTicketsData; 576 414 res: { 577 415 /** 578 - * successful operation 416 + * Success. 579 417 */ 580 - 200: string; 418 + 200: BuyMuseumTicketsResponse; 581 419 /** 582 - * Invalid username/password supplied 420 + * Bad request. 583 421 */ 584 - 400: unknown; 585 - }; 586 - }; 587 - }; 588 - '/user/logout': { 589 - get: { 590 - res: { 422 + 400: Error; 591 423 /** 592 - * successful operation 424 + * Not found. 593 425 */ 594 - default: unknown; 426 + 404: Error; 595 427 }; 596 428 }; 597 429 }; 598 - '/user/{username}': { 430 + '/tickets/{ticketId}/qr': { 599 431 get: { 600 - req: { 601 - path: { 602 - /** 603 - * The name that needs to be fetched. Use user1 for testing. 604 - */ 605 - username: string; 606 - }; 607 - }; 432 + req: GetTicketCodeData; 608 433 res: { 609 434 /** 610 - * successful operation 435 + * Scannable event ticket in image format. 611 436 */ 612 - 200: User; 437 + 200: GetTicketCodeResponse; 613 438 /** 614 - * Invalid username supplied 615 - */ 616 - 400: unknown; 617 - /** 618 - * User not found 619 - */ 620 - 404: unknown; 621 - }; 622 - }; 623 - put: { 624 - req: { 625 - /** 626 - * Update an existent user in the store 627 - */ 628 - body?: User; 629 - path: { 630 - /** 631 - * name that needs to be updated 632 - */ 633 - username: string; 634 - }; 635 - }; 636 - res: { 637 - /** 638 - * successful operation 639 - */ 640 - default: unknown; 641 - }; 642 - }; 643 - delete: { 644 - req: { 645 - path: { 646 - /** 647 - * The name that needs to be deleted 648 - */ 649 - username: string; 650 - }; 651 - }; 652 - res: { 653 - /** 654 - * Invalid username supplied 439 + * Bad request. 655 440 */ 656 - 400: unknown; 441 + 400: Error; 657 442 /** 658 - * User not found 443 + * Not found. 659 444 */ 660 - 404: unknown; 445 + 404: Error; 661 446 }; 662 447 }; 663 448 };
-458
examples/openapi-ts-fetch/src/client_old/services.gen.ts
··· 1 - // This file is auto-generated by @hey-api/openapi-ts 2 - 3 - import type { CancelablePromise } from '@hey-api/client-fetch'; 4 - import { OpenAPI } from '@hey-api/client-fetch'; 5 - import { request as __request } from '@hey-api/client-fetch'; 6 - 7 - import type { 8 - AddPetData, 9 - AddPetResponse, 10 - CreateUserData, 11 - CreateUserResponse, 12 - CreateUsersWithListInputData, 13 - CreateUsersWithListInputResponse, 14 - DeleteOrderData, 15 - DeletePetData, 16 - DeleteUserData, 17 - FindPetsByStatusData, 18 - FindPetsByStatusResponse, 19 - FindPetsByTagsData, 20 - FindPetsByTagsResponse, 21 - GetInventoryResponse, 22 - GetOrderByIdData, 23 - GetOrderByIdResponse, 24 - GetPetByIdData, 25 - GetPetByIdResponse, 26 - GetUserByNameData, 27 - GetUserByNameResponse, 28 - LoginUserData, 29 - LoginUserResponse, 30 - LogoutUserResponse, 31 - PlaceOrderData, 32 - PlaceOrderResponse, 33 - UpdatePetData, 34 - UpdatePetResponse, 35 - UpdatePetWithFormData, 36 - UpdateUserData, 37 - UpdateUserResponse, 38 - UploadFileData, 39 - UploadFileResponse, 40 - } from './types.gen'; 41 - 42 - export class PetService { 43 - /** 44 - * Add a new pet to the store 45 - * Add a new pet to the store 46 - * @param data The data for the request. 47 - * @param data.requestBody Create a new pet in the store 48 - * @returns Pet Successful operation 49 - * @throws ApiError 50 - */ 51 - public static addPet(data: AddPetData): CancelablePromise<AddPetResponse> { 52 - return __request(OpenAPI, { 53 - body: data.requestBody, 54 - errors: { 55 - 405: 'Invalid input', 56 - }, 57 - mediaType: 'application/json', 58 - method: 'POST', 59 - url: '/pet', 60 - }); 61 - } 62 - 63 - /** 64 - * Update an existing pet 65 - * Update an existing pet by Id 66 - * @param data The data for the request. 67 - * @param data.requestBody Update an existent pet in the store 68 - * @returns Pet Successful operation 69 - * @throws ApiError 70 - */ 71 - public static updatePet( 72 - data: UpdatePetData, 73 - ): CancelablePromise<UpdatePetResponse> { 74 - return __request(OpenAPI, { 75 - body: data.requestBody, 76 - errors: { 77 - 400: 'Invalid ID supplied', 78 - 404: 'Pet not found', 79 - 405: 'Validation exception', 80 - }, 81 - mediaType: 'application/json', 82 - method: 'PUT', 83 - url: '/pet', 84 - }); 85 - } 86 - 87 - /** 88 - * Finds Pets by status 89 - * Multiple status values can be provided with comma separated strings 90 - * @param data The data for the request. 91 - * @param data.status Status values that need to be considered for filter 92 - * @returns Pet successful operation 93 - * @throws ApiError 94 - */ 95 - public static findPetsByStatus( 96 - data: FindPetsByStatusData = {}, 97 - ): CancelablePromise<FindPetsByStatusResponse> { 98 - return __request(OpenAPI, { 99 - errors: { 100 - 400: 'Invalid status value', 101 - }, 102 - method: 'GET', 103 - query: { 104 - status: data.status, 105 - }, 106 - url: '/pet/findByStatus', 107 - }); 108 - } 109 - 110 - /** 111 - * Finds Pets by tags 112 - * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. 113 - * @param data The data for the request. 114 - * @param data.tags Tags to filter by 115 - * @returns Pet successful operation 116 - * @throws ApiError 117 - */ 118 - public static findPetsByTags( 119 - data: FindPetsByTagsData = {}, 120 - ): CancelablePromise<FindPetsByTagsResponse> { 121 - return __request(OpenAPI, { 122 - errors: { 123 - 400: 'Invalid tag value', 124 - }, 125 - method: 'GET', 126 - query: { 127 - tags: data.tags, 128 - }, 129 - url: '/pet/findByTags', 130 - }); 131 - } 132 - 133 - /** 134 - * Find pet by ID 135 - * Returns a single pet 136 - * @param data The data for the request. 137 - * @param data.petId ID of pet to return 138 - * @returns Pet successful operation 139 - * @throws ApiError 140 - */ 141 - public static getPetById( 142 - data: GetPetByIdData, 143 - ): CancelablePromise<GetPetByIdResponse> { 144 - return __request(OpenAPI, { 145 - errors: { 146 - 400: 'Invalid ID supplied', 147 - 404: 'Pet not found', 148 - }, 149 - method: 'GET', 150 - path: { 151 - petId: data.petId, 152 - }, 153 - url: '/pet/{petId}', 154 - }); 155 - } 156 - 157 - /** 158 - * Updates a pet in the store with form data 159 - * @param data The data for the request. 160 - * @param data.petId ID of pet that needs to be updated 161 - * @param data.name Name of pet that needs to be updated 162 - * @param data.status Status of pet that needs to be updated 163 - * @throws ApiError 164 - */ 165 - public static updatePetWithForm( 166 - data: UpdatePetWithFormData, 167 - ): CancelablePromise<void> { 168 - return __request(OpenAPI, { 169 - errors: { 170 - 405: 'Invalid input', 171 - }, 172 - method: 'POST', 173 - path: { 174 - petId: data.petId, 175 - }, 176 - query: { 177 - name: data.name, 178 - status: data.status, 179 - }, 180 - url: '/pet/{petId}', 181 - }); 182 - } 183 - 184 - /** 185 - * Deletes a pet 186 - * @param data The data for the request. 187 - * @param data.petId Pet id to delete 188 - * @param data.apiKey 189 - * @throws ApiError 190 - */ 191 - public static deletePet(data: DeletePetData): CancelablePromise<void> { 192 - return __request(OpenAPI, { 193 - errors: { 194 - 400: 'Invalid pet value', 195 - }, 196 - headers: { 197 - api_key: data.apiKey, 198 - }, 199 - method: 'DELETE', 200 - path: { 201 - petId: data.petId, 202 - }, 203 - url: '/pet/{petId}', 204 - }); 205 - } 206 - 207 - /** 208 - * uploads an image 209 - * @param data The data for the request. 210 - * @param data.petId ID of pet to update 211 - * @param data.additionalMetadata Additional Metadata 212 - * @param data.requestBody 213 - * @returns ApiResponse successful operation 214 - * @throws ApiError 215 - */ 216 - public static uploadFile( 217 - data: UploadFileData, 218 - ): CancelablePromise<UploadFileResponse> { 219 - return __request(OpenAPI, { 220 - body: data.requestBody, 221 - mediaType: 'application/octet-stream', 222 - method: 'POST', 223 - path: { 224 - petId: data.petId, 225 - }, 226 - query: { 227 - additionalMetadata: data.additionalMetadata, 228 - }, 229 - url: '/pet/{petId}/uploadImage', 230 - }); 231 - } 232 - } 233 - 234 - export class StoreService { 235 - /** 236 - * Returns pet inventories by status 237 - * Returns a map of status codes to quantities 238 - * @returns number successful operation 239 - * @throws ApiError 240 - */ 241 - public static getInventory(): CancelablePromise<GetInventoryResponse> { 242 - return __request(OpenAPI, { 243 - method: 'GET', 244 - url: '/store/inventory', 245 - }); 246 - } 247 - 248 - /** 249 - * Place an order for a pet 250 - * Place a new order in the store 251 - * @param data The data for the request. 252 - * @param data.requestBody 253 - * @returns Order successful operation 254 - * @throws ApiError 255 - */ 256 - public static placeOrder( 257 - data: PlaceOrderData = {}, 258 - ): CancelablePromise<PlaceOrderResponse> { 259 - return __request(OpenAPI, { 260 - body: data.requestBody, 261 - errors: { 262 - 405: 'Invalid input', 263 - }, 264 - mediaType: 'application/json', 265 - method: 'POST', 266 - url: '/store/order', 267 - }); 268 - } 269 - 270 - /** 271 - * Find purchase order by ID 272 - * For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions. 273 - * @param data The data for the request. 274 - * @param data.orderId ID of order that needs to be fetched 275 - * @returns Order successful operation 276 - * @throws ApiError 277 - */ 278 - public static getOrderById( 279 - data: GetOrderByIdData, 280 - ): CancelablePromise<GetOrderByIdResponse> { 281 - return __request(OpenAPI, { 282 - errors: { 283 - 400: 'Invalid ID supplied', 284 - 404: 'Order not found', 285 - }, 286 - method: 'GET', 287 - path: { 288 - orderId: data.orderId, 289 - }, 290 - url: '/store/order/{orderId}', 291 - }); 292 - } 293 - 294 - /** 295 - * Delete purchase order by ID 296 - * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors 297 - * @param data The data for the request. 298 - * @param data.orderId ID of the order that needs to be deleted 299 - * @throws ApiError 300 - */ 301 - public static deleteOrder(data: DeleteOrderData): CancelablePromise<void> { 302 - return __request(OpenAPI, { 303 - errors: { 304 - 400: 'Invalid ID supplied', 305 - 404: 'Order not found', 306 - }, 307 - method: 'DELETE', 308 - path: { 309 - orderId: data.orderId, 310 - }, 311 - url: '/store/order/{orderId}', 312 - }); 313 - } 314 - } 315 - 316 - export class UserService { 317 - /** 318 - * Create user 319 - * This can only be done by the logged in user. 320 - * @param data The data for the request. 321 - * @param data.requestBody Created user object 322 - * @returns User successful operation 323 - * @throws ApiError 324 - */ 325 - public static createUser( 326 - data: CreateUserData = {}, 327 - ): CancelablePromise<CreateUserResponse> { 328 - return __request(OpenAPI, { 329 - body: data.requestBody, 330 - mediaType: 'application/json', 331 - method: 'POST', 332 - url: '/user', 333 - }); 334 - } 335 - 336 - /** 337 - * Creates list of users with given input array 338 - * Creates list of users with given input array 339 - * @param data The data for the request. 340 - * @param data.requestBody 341 - * @returns User Successful operation 342 - * @returns unknown successful operation 343 - * @throws ApiError 344 - */ 345 - public static createUsersWithListInput( 346 - data: CreateUsersWithListInputData = {}, 347 - ): CancelablePromise<CreateUsersWithListInputResponse> { 348 - return __request(OpenAPI, { 349 - body: data.requestBody, 350 - mediaType: 'application/json', 351 - method: 'POST', 352 - url: '/user/createWithList', 353 - }); 354 - } 355 - 356 - /** 357 - * Logs user into the system 358 - * @param data The data for the request. 359 - * @param data.username The user name for login 360 - * @param data.password The password for login in clear text 361 - * @returns string successful operation 362 - * @throws ApiError 363 - */ 364 - public static loginUser( 365 - data: LoginUserData = {}, 366 - ): CancelablePromise<LoginUserResponse> { 367 - return __request(OpenAPI, { 368 - errors: { 369 - 400: 'Invalid username/password supplied', 370 - }, 371 - method: 'GET', 372 - query: { 373 - password: data.password, 374 - username: data.username, 375 - }, 376 - url: '/user/login', 377 - }); 378 - } 379 - 380 - /** 381 - * Logs out current logged in user session 382 - * @returns unknown successful operation 383 - * @throws ApiError 384 - */ 385 - public static logoutUser(): CancelablePromise<LogoutUserResponse> { 386 - return __request(OpenAPI, { 387 - method: 'GET', 388 - url: '/user/logout', 389 - }); 390 - } 391 - 392 - /** 393 - * Get user by user name 394 - * @param data The data for the request. 395 - * @param data.username The name that needs to be fetched. Use user1 for testing. 396 - * @returns User successful operation 397 - * @throws ApiError 398 - */ 399 - public static getUserByName( 400 - data: GetUserByNameData, 401 - ): CancelablePromise<GetUserByNameResponse> { 402 - return __request(OpenAPI, { 403 - errors: { 404 - 400: 'Invalid username supplied', 405 - 404: 'User not found', 406 - }, 407 - method: 'GET', 408 - path: { 409 - username: data.username, 410 - }, 411 - url: '/user/{username}', 412 - }); 413 - } 414 - 415 - /** 416 - * Update user 417 - * This can only be done by the logged in user. 418 - * @param data The data for the request. 419 - * @param data.username name that needs to be updated 420 - * @param data.requestBody Update an existent user in the store 421 - * @returns unknown successful operation 422 - * @throws ApiError 423 - */ 424 - public static updateUser( 425 - data: UpdateUserData, 426 - ): CancelablePromise<UpdateUserResponse> { 427 - return __request(OpenAPI, { 428 - body: data.requestBody, 429 - mediaType: 'application/json', 430 - method: 'PUT', 431 - path: { 432 - username: data.username, 433 - }, 434 - url: '/user/{username}', 435 - }); 436 - } 437 - 438 - /** 439 - * Delete user 440 - * This can only be done by the logged in user. 441 - * @param data The data for the request. 442 - * @param data.username The name that needs to be deleted 443 - * @throws ApiError 444 - */ 445 - public static deleteUser(data: DeleteUserData): CancelablePromise<void> { 446 - return __request(OpenAPI, { 447 - errors: { 448 - 400: 'Invalid username supplied', 449 - 404: 'User not found', 450 - }, 451 - method: 'DELETE', 452 - path: { 453 - username: data.username, 454 - }, 455 - url: '/user/{username}', 456 - }); 457 - } 458 - }
-604
examples/openapi-ts-fetch/src/client_old/types.gen.ts
··· 1 - // This file is auto-generated by @hey-api/openapi-ts 2 - 3 - export type Order = { 4 - id?: number; 5 - petId?: number; 6 - quantity?: number; 7 - shipDate?: string; 8 - /** 9 - * Order Status 10 - */ 11 - status?: 'placed' | 'approved' | 'delivered'; 12 - complete?: boolean; 13 - }; 14 - 15 - export type Customer = { 16 - id?: number; 17 - username?: string; 18 - address?: Array<Address>; 19 - }; 20 - 21 - export type Address = { 22 - street?: string; 23 - city?: string; 24 - state?: string; 25 - zip?: string; 26 - }; 27 - 28 - export type Category = { 29 - id?: number; 30 - name?: string; 31 - }; 32 - 33 - export type User = { 34 - id?: number; 35 - username?: string; 36 - firstName?: string; 37 - lastName?: string; 38 - email?: string; 39 - password?: string; 40 - phone?: string; 41 - /** 42 - * User Status 43 - */ 44 - userStatus?: number; 45 - }; 46 - 47 - export type Tag = { 48 - id?: number; 49 - name?: string; 50 - }; 51 - 52 - export type Pet = { 53 - id?: number; 54 - name: string; 55 - category?: Category; 56 - photoUrls: Array<string>; 57 - tags?: Array<Tag>; 58 - /** 59 - * pet status in the store 60 - */ 61 - status?: 'available' | 'pending' | 'sold'; 62 - }; 63 - 64 - export type ApiResponse = { 65 - code?: number; 66 - type?: string; 67 - message?: string; 68 - }; 69 - 70 - export type AddPetData = { 71 - /** 72 - * Create a new pet in the store 73 - */ 74 - requestBody: Pet; 75 - }; 76 - 77 - export type AddPetResponse = Pet; 78 - 79 - export type UpdatePetData = { 80 - /** 81 - * Update an existent pet in the store 82 - */ 83 - requestBody: Pet; 84 - }; 85 - 86 - export type UpdatePetResponse = Pet; 87 - 88 - export type FindPetsByStatusData = { 89 - /** 90 - * Status values that need to be considered for filter 91 - */ 92 - status?: 'available' | 'pending' | 'sold'; 93 - }; 94 - 95 - export type FindPetsByStatusResponse = Array<Pet>; 96 - 97 - export type FindPetsByTagsData = { 98 - /** 99 - * Tags to filter by 100 - */ 101 - tags?: Array<string>; 102 - }; 103 - 104 - export type FindPetsByTagsResponse = Array<Pet>; 105 - 106 - export type GetPetByIdData = { 107 - /** 108 - * ID of pet to return 109 - */ 110 - petId: number; 111 - }; 112 - 113 - export type GetPetByIdResponse = Pet; 114 - 115 - export type UpdatePetWithFormData = { 116 - /** 117 - * Name of pet that needs to be updated 118 - */ 119 - name?: string; 120 - /** 121 - * ID of pet that needs to be updated 122 - */ 123 - petId: number; 124 - /** 125 - * Status of pet that needs to be updated 126 - */ 127 - status?: string; 128 - }; 129 - 130 - export type DeletePetData = { 131 - apiKey?: string; 132 - /** 133 - * Pet id to delete 134 - */ 135 - petId: number; 136 - }; 137 - 138 - export type UploadFileData = { 139 - /** 140 - * Additional Metadata 141 - */ 142 - additionalMetadata?: string; 143 - /** 144 - * ID of pet to update 145 - */ 146 - petId: number; 147 - requestBody?: Blob | File; 148 - }; 149 - 150 - export type UploadFileResponse = ApiResponse; 151 - 152 - export type GetInventoryResponse = { 153 - [key: string]: number; 154 - }; 155 - 156 - export type PlaceOrderData = { 157 - requestBody?: Order; 158 - }; 159 - 160 - export type PlaceOrderResponse = Order; 161 - 162 - export type GetOrderByIdData = { 163 - /** 164 - * ID of order that needs to be fetched 165 - */ 166 - orderId: number; 167 - }; 168 - 169 - export type GetOrderByIdResponse = Order; 170 - 171 - export type DeleteOrderData = { 172 - /** 173 - * ID of the order that needs to be deleted 174 - */ 175 - orderId: number; 176 - }; 177 - 178 - export type CreateUserData = { 179 - /** 180 - * Created user object 181 - */ 182 - requestBody?: User; 183 - }; 184 - 185 - export type CreateUserResponse = User; 186 - 187 - export type CreateUsersWithListInputData = { 188 - requestBody?: Array<User>; 189 - }; 190 - 191 - export type CreateUsersWithListInputResponse = User | unknown; 192 - 193 - export type LoginUserData = { 194 - /** 195 - * The password for login in clear text 196 - */ 197 - password?: string; 198 - /** 199 - * The user name for login 200 - */ 201 - username?: string; 202 - }; 203 - 204 - export type LoginUserResponse = string; 205 - 206 - export type LogoutUserResponse = unknown; 207 - 208 - export type GetUserByNameData = { 209 - /** 210 - * The name that needs to be fetched. Use user1 for testing. 211 - */ 212 - username: string; 213 - }; 214 - 215 - export type GetUserByNameResponse = User; 216 - 217 - export type UpdateUserData = { 218 - /** 219 - * Update an existent user in the store 220 - */ 221 - requestBody?: User; 222 - /** 223 - * name that needs to be updated 224 - */ 225 - username: string; 226 - }; 227 - 228 - export type UpdateUserResponse = unknown; 229 - 230 - export type DeleteUserData = { 231 - /** 232 - * The name that needs to be deleted 233 - */ 234 - username: string; 235 - }; 236 - 237 - export type $OpenApiTs = { 238 - '/pet': { 239 - post: { 240 - req: { 241 - /** 242 - * Create a new pet in the store 243 - */ 244 - requestBody: Pet; 245 - }; 246 - res: { 247 - /** 248 - * Successful operation 249 - */ 250 - 200: Pet; 251 - /** 252 - * Invalid input 253 - */ 254 - 405: unknown; 255 - }; 256 - }; 257 - put: { 258 - req: { 259 - /** 260 - * Update an existent pet in the store 261 - */ 262 - requestBody: Pet; 263 - }; 264 - res: { 265 - /** 266 - * Successful operation 267 - */ 268 - 200: Pet; 269 - /** 270 - * Invalid ID supplied 271 - */ 272 - 400: unknown; 273 - /** 274 - * Pet not found 275 - */ 276 - 404: unknown; 277 - /** 278 - * Validation exception 279 - */ 280 - 405: unknown; 281 - }; 282 - }; 283 - }; 284 - '/pet/findByStatus': { 285 - get: { 286 - req: { 287 - /** 288 - * Status values that need to be considered for filter 289 - */ 290 - status?: 'available' | 'pending' | 'sold'; 291 - }; 292 - res: { 293 - /** 294 - * successful operation 295 - */ 296 - 200: Array<Pet>; 297 - /** 298 - * Invalid status value 299 - */ 300 - 400: unknown; 301 - }; 302 - }; 303 - }; 304 - '/pet/findByTags': { 305 - get: { 306 - req: { 307 - /** 308 - * Tags to filter by 309 - */ 310 - tags?: Array<string>; 311 - }; 312 - res: { 313 - /** 314 - * successful operation 315 - */ 316 - 200: Array<Pet>; 317 - /** 318 - * Invalid tag value 319 - */ 320 - 400: unknown; 321 - }; 322 - }; 323 - }; 324 - '/pet/{petId}': { 325 - get: { 326 - req: { 327 - /** 328 - * ID of pet to return 329 - */ 330 - petId: number; 331 - }; 332 - res: { 333 - /** 334 - * successful operation 335 - */ 336 - 200: Pet; 337 - /** 338 - * Invalid ID supplied 339 - */ 340 - 400: unknown; 341 - /** 342 - * Pet not found 343 - */ 344 - 404: unknown; 345 - }; 346 - }; 347 - post: { 348 - req: { 349 - /** 350 - * Name of pet that needs to be updated 351 - */ 352 - name?: string; 353 - /** 354 - * ID of pet that needs to be updated 355 - */ 356 - petId: number; 357 - /** 358 - * Status of pet that needs to be updated 359 - */ 360 - status?: string; 361 - }; 362 - res: { 363 - /** 364 - * Invalid input 365 - */ 366 - 405: unknown; 367 - }; 368 - }; 369 - delete: { 370 - req: { 371 - apiKey?: string; 372 - /** 373 - * Pet id to delete 374 - */ 375 - petId: number; 376 - }; 377 - res: { 378 - /** 379 - * Invalid pet value 380 - */ 381 - 400: unknown; 382 - }; 383 - }; 384 - }; 385 - '/pet/{petId}/uploadImage': { 386 - post: { 387 - req: { 388 - /** 389 - * Additional Metadata 390 - */ 391 - additionalMetadata?: string; 392 - /** 393 - * ID of pet to update 394 - */ 395 - petId: number; 396 - requestBody?: Blob | File; 397 - }; 398 - res: { 399 - /** 400 - * successful operation 401 - */ 402 - 200: ApiResponse; 403 - }; 404 - }; 405 - }; 406 - '/store/inventory': { 407 - get: { 408 - res: { 409 - /** 410 - * successful operation 411 - */ 412 - 200: { 413 - [key: string]: number; 414 - }; 415 - }; 416 - }; 417 - }; 418 - '/store/order': { 419 - post: { 420 - req: { 421 - requestBody?: Order; 422 - }; 423 - res: { 424 - /** 425 - * successful operation 426 - */ 427 - 200: Order; 428 - /** 429 - * Invalid input 430 - */ 431 - 405: unknown; 432 - }; 433 - }; 434 - }; 435 - '/store/order/{orderId}': { 436 - get: { 437 - req: { 438 - /** 439 - * ID of order that needs to be fetched 440 - */ 441 - orderId: number; 442 - }; 443 - res: { 444 - /** 445 - * successful operation 446 - */ 447 - 200: Order; 448 - /** 449 - * Invalid ID supplied 450 - */ 451 - 400: unknown; 452 - /** 453 - * Order not found 454 - */ 455 - 404: unknown; 456 - }; 457 - }; 458 - delete: { 459 - req: { 460 - /** 461 - * ID of the order that needs to be deleted 462 - */ 463 - orderId: number; 464 - }; 465 - res: { 466 - /** 467 - * Invalid ID supplied 468 - */ 469 - 400: unknown; 470 - /** 471 - * Order not found 472 - */ 473 - 404: unknown; 474 - }; 475 - }; 476 - }; 477 - '/user': { 478 - post: { 479 - req: { 480 - /** 481 - * Created user object 482 - */ 483 - requestBody?: User; 484 - }; 485 - res: { 486 - /** 487 - * successful operation 488 - */ 489 - default: User; 490 - }; 491 - }; 492 - }; 493 - '/user/createWithList': { 494 - post: { 495 - req: { 496 - requestBody?: Array<User>; 497 - }; 498 - res: { 499 - /** 500 - * Successful operation 501 - */ 502 - 200: User; 503 - /** 504 - * successful operation 505 - */ 506 - default: unknown; 507 - }; 508 - }; 509 - }; 510 - '/user/login': { 511 - get: { 512 - req: { 513 - /** 514 - * The password for login in clear text 515 - */ 516 - password?: string; 517 - /** 518 - * The user name for login 519 - */ 520 - username?: string; 521 - }; 522 - res: { 523 - /** 524 - * successful operation 525 - */ 526 - 200: string; 527 - /** 528 - * Invalid username/password supplied 529 - */ 530 - 400: unknown; 531 - }; 532 - }; 533 - }; 534 - '/user/logout': { 535 - get: { 536 - res: { 537 - /** 538 - * successful operation 539 - */ 540 - default: unknown; 541 - }; 542 - }; 543 - }; 544 - '/user/{username}': { 545 - get: { 546 - req: { 547 - /** 548 - * The name that needs to be fetched. Use user1 for testing. 549 - */ 550 - username: string; 551 - }; 552 - res: { 553 - /** 554 - * successful operation 555 - */ 556 - 200: User; 557 - /** 558 - * Invalid username supplied 559 - */ 560 - 400: unknown; 561 - /** 562 - * User not found 563 - */ 564 - 404: unknown; 565 - }; 566 - }; 567 - put: { 568 - req: { 569 - /** 570 - * Update an existent user in the store 571 - */ 572 - requestBody?: User; 573 - /** 574 - * name that needs to be updated 575 - */ 576 - username: string; 577 - }; 578 - res: { 579 - /** 580 - * successful operation 581 - */ 582 - default: unknown; 583 - }; 584 - }; 585 - delete: { 586 - req: { 587 - /** 588 - * The name that needs to be deleted 589 - */ 590 - username: string; 591 - }; 592 - res: { 593 - /** 594 - * Invalid username supplied 595 - */ 596 - 400: unknown; 597 - /** 598 - * User not found 599 - */ 600 - 404: unknown; 601 - }; 602 - }; 603 - }; 604 - };
+67 -33
packages/openapi-ts/src/utils/write/types.ts
··· 204 204 type ResMap = Map<number | 'default', Model>; 205 205 type MethodMap = Map<'req' | 'res', ResMap | OperationParameter[]>; 206 206 type MethodKey = Service['operations'][number]['method']; 207 - type PathMap = Map<MethodKey, MethodMap>; 207 + type PathMap = Map<MethodKey | '$ref', MethodMap | string>; 208 208 209 209 const pathsMap = new Map<string, PathMap>(); 210 210 ··· 222 222 pathsMap.set(operation.path, new Map()); 223 223 pathMap = pathsMap.get(operation.path)!; 224 224 } 225 + pathMap.set('$ref', operation.name); 225 226 226 227 let methodMap = pathMap.get(operation.method); 227 228 if (!methodMap) { 228 229 pathMap.set(operation.method, new Map()); 229 230 methodMap = pathMap.get(operation.method)!; 231 + } 232 + 233 + if (typeof methodMap === 'string') { 234 + return; 230 235 } 231 236 232 237 if (hasReq) { ··· 375 380 }); 376 381 377 382 const properties = Array.from(pathsMap).map(([path, pathMap]) => { 378 - const pathParameters = Array.from(pathMap).map(([method, methodMap]) => { 379 - const methodParameters = Array.from(methodMap).map( 380 - ([name, baseOrResMap]) => { 381 - const reqResParameters = Array.isArray(baseOrResMap) 382 - ? baseOrResMap 383 - : Array.from(baseOrResMap).map(([code, base]) => { 384 - // TODO: move query params into separate query key 385 - const value: Model = { 386 - ...emptyModel, 387 - ...base, 388 - isRequired: true, 389 - name: String(code), 390 - }; 391 - return value; 383 + const pathParameters = Array.from(pathMap) 384 + .map(([method, methodMap]) => { 385 + if (method === '$ref' || typeof methodMap === 'string') { 386 + return; 387 + } 388 + 389 + const methodParameters = Array.from(methodMap).map( 390 + ([name, baseOrResMap]) => { 391 + if (name === 'req') { 392 + const operationName = pathMap.get('$ref') as string; 393 + const { name: base } = uniqueTypeName({ 394 + client, 395 + meta: { 396 + // TODO: this should be exact ref to operation for consistency, 397 + // but name should work too as operation ID is unique 398 + $ref: operationName, 399 + name: operationName, 400 + }, 401 + nameTransformer: operationDataTypeName, 392 402 }); 403 + const reqKey: Model = { 404 + ...emptyModel, 405 + base, 406 + export: 'reference', 407 + isRequired: true, 408 + name, 409 + properties: [], 410 + type: base, 411 + }; 412 + return reqKey; 413 + } 414 + const reqResParameters = Array.isArray(baseOrResMap) 415 + ? baseOrResMap 416 + : Array.from(baseOrResMap).map(([code, base]) => { 417 + // TODO: move query params into separate query key 418 + const value: Model = { 419 + ...emptyModel, 420 + ...base, 421 + isRequired: true, 422 + name: String(code), 423 + }; 424 + return value; 425 + }); 393 426 394 - const reqResKey: Model = { 395 - ...emptyModel, 396 - isRequired: true, 397 - name, 398 - properties: reqResParameters, 399 - }; 400 - return reqResKey; 401 - }, 402 - ); 403 - const methodKey: Model = { 404 - ...emptyModel, 405 - isRequired: true, 406 - name: method.toLocaleLowerCase(), 407 - properties: methodParameters, 408 - }; 409 - return methodKey; 410 - }); 427 + const reqResKey: Model = { 428 + ...emptyModel, 429 + isRequired: true, 430 + name, 431 + properties: reqResParameters, 432 + }; 433 + return reqResKey; 434 + }, 435 + ); 436 + const methodKey: Model = { 437 + ...emptyModel, 438 + isRequired: true, 439 + name: method.toLocaleLowerCase(), 440 + properties: methodParameters, 441 + }; 442 + return methodKey; 443 + }) 444 + .filter(Boolean); 411 445 const pathKey: Model = { 412 446 ...emptyModel, 413 447 isRequired: true, 414 448 name: `'${path}'`, 415 - properties: pathParameters, 449 + properties: pathParameters as Model[], 416 450 }; 417 451 return pathKey; 418 452 });
+37 -2
pnpm-lock.yaml
··· 181 181 version: 5.4.5 182 182 vite: 183 183 specifier: 5.2.11 184 - version: 5.2.11(@types/node@20.12.8) 184 + version: 5.2.11 185 185 186 186 packages/client-axios: 187 187 dependencies: ··· 4018 4018 '@babel/plugin-transform-react-jsx-source': 7.24.1(@babel/core@7.24.0) 4019 4019 '@types/babel__core': 7.20.5 4020 4020 react-refresh: 0.14.0 4021 - vite: 5.2.11(@types/node@20.12.8) 4021 + vite: 5.2.11 4022 4022 transitivePeerDependencies: 4023 4023 - supports-color 4024 4024 dev: true ··· 10670 10670 optional: true 10671 10671 dependencies: 10672 10672 '@types/node': 20.12.8 10673 + esbuild: 0.20.2 10674 + postcss: 8.4.38 10675 + rollup: 4.17.2 10676 + optionalDependencies: 10677 + fsevents: 2.3.3 10678 + dev: true 10679 + 10680 + /vite@5.2.11: 10681 + resolution: {integrity: sha512-HndV31LWW05i1BLPMUCE1B9E9GFbOu1MbenhS58FuK6owSO5qHm7GiCotrNY1YE5rMeQSFBGmT5ZaLEjFizgiQ==} 10682 + engines: {node: ^18.0.0 || >=20.0.0} 10683 + hasBin: true 10684 + peerDependencies: 10685 + '@types/node': ^18.0.0 || >=20.0.0 10686 + less: '*' 10687 + lightningcss: ^1.21.0 10688 + sass: '*' 10689 + stylus: '*' 10690 + sugarss: '*' 10691 + terser: ^5.4.0 10692 + peerDependenciesMeta: 10693 + '@types/node': 10694 + optional: true 10695 + less: 10696 + optional: true 10697 + lightningcss: 10698 + optional: true 10699 + sass: 10700 + optional: true 10701 + stylus: 10702 + optional: true 10703 + sugarss: 10704 + optional: true 10705 + terser: 10706 + optional: true 10707 + dependencies: 10673 10708 esbuild: 0.20.2 10674 10709 postcss: 8.4.38 10675 10710 rollup: 4.17.2