From 2444f8aa3ff64bcd6a5c11bf6932799427ca88be Mon Sep 17 00:00:00 2001 From: Lubos Date: Sat, 27 Apr 2024 16:18:02 +0100 Subject: [PATCH] fix: export operation data and response types --- .changeset/small-wolves-train.md | 5 + .../src/client/services.gen.ts | 114 +++-- .../openapi-ts-fetch/src/client/types.gen.ts | 179 ++++++- .../src/openApi/common/interfaces/client.ts | 2 +- .../common/parser/__tests__/operation.spec.ts | 2 +- .../src/openApi/common/parser/operation.ts | 11 +- .../src/openApi/v2/parser/getOperation.ts | 2 +- .../openApi/v2/parser/getOperationResponse.ts | 8 +- .../v2/parser/getOperationResponses.ts | 2 +- .../openApi/v3/parser/getOperationResponse.ts | 8 +- .../v3/parser/getOperationResponses.ts | 2 +- .../openApi/v3/parser/getOperationResults.ts | 29 -- .../src/openApi/v3/parser/operation.ts | 2 +- .../operation.ts} | 7 +- .../openapi-ts/src/utils/write/services.ts | 58 ++- packages/openapi-ts/src/utils/write/types.ts | 41 +- .../test/generated/v2/services.gen.ts.snap | 52 +- .../test/generated/v2/types.gen.ts.snap | 314 +++++++++++- .../test/generated/v3/services.gen.ts.snap | 78 +-- .../test/generated/v3/types.gen.ts.snap | 450 +++++++++++++++++- .../generated/v3_angular/services.gen.ts.snap | 78 +-- .../generated/v3_angular/types.gen.ts.snap | 450 +++++++++++++++++- .../generated/v3_client/services.gen.ts.snap | 78 +-- .../generated/v3_client/types.gen.ts.snap | 450 +++++++++++++++++- .../v3_enums_typescript/services.gen.ts.snap | 78 +-- .../v3_enums_typescript/types.gen.ts.snap | 450 +++++++++++++++++- .../services.gen.ts.snap | 8 +- .../types.gen.ts.snap | 81 ++++ .../generated/v3_options/services.gen.ts.snap | 8 +- .../generated/v3_options/types.gen.ts.snap | 81 ++++ .../v3_services_name/services.gen.ts.snap | 12 +- packages/openapi-ts/test/sample.cjs | 4 +- 32 files changed, 2794 insertions(+), 350 deletions(-) create mode 100644 .changeset/small-wolves-train.md delete mode 100644 packages/openapi-ts/src/openApi/v3/parser/getOperationResults.ts rename packages/openapi-ts/src/{openApi/v2/parser/getOperationResults.ts => utils/operation.ts} (82%) diff --git a/.changeset/small-wolves-train.md b/.changeset/small-wolves-train.md new file mode 100644 index 000000000..d55ba2f74 --- /dev/null +++ b/.changeset/small-wolves-train.md @@ -0,0 +1,5 @@ +--- +"@hey-api/openapi-ts": patch +--- + +fix: export operation data and response types diff --git a/examples/openapi-ts-fetch/src/client/services.gen.ts b/examples/openapi-ts-fetch/src/client/services.gen.ts index 0ba53b385..a1b27cc91 100644 --- a/examples/openapi-ts-fetch/src/client/services.gen.ts +++ b/examples/openapi-ts-fetch/src/client/services.gen.ts @@ -4,7 +4,40 @@ import type { CancelablePromise } from '@hey-api/client-fetch'; import { OpenAPI } from '@hey-api/client-fetch'; import { request as __request } from '@hey-api/client-fetch'; -import type { $OpenApiTs } from './types.gen'; +import type { + PetAddPetData, + PetAddPetResponse, + PetDeletePetData, + PetFindPetsByStatusData, + PetFindPetsByStatusResponse, + PetFindPetsByTagsData, + PetFindPetsByTagsResponse, + PetGetPetByIdData, + PetGetPetByIdResponse, + PetUpdatePetData, + PetUpdatePetResponse, + PetUpdatePetWithFormData, + PetUploadFileData, + PetUploadFileResponse, + StoreDeleteOrderData, + StoreGetInventoryResponse, + StoreGetOrderByIdData, + StoreGetOrderByIdResponse, + StorePlaceOrderData, + StorePlaceOrderResponse, + UserCreateUserData, + UserCreateUserResponse, + UserCreateUsersWithListInputData, + UserCreateUsersWithListInputResponse, + UserDeleteUserData, + UserGetUserByNameData, + UserGetUserByNameResponse, + UserLoginUserData, + UserLoginUserResponse, + UserLogoutUserResponse, + UserUpdateUserData, + UserUpdateUserResponse, +} from './types.gen'; export class PetService { /** @@ -16,8 +49,8 @@ export class PetService { * @throws ApiError */ public static addPet( - data: $OpenApiTs['/pet']['post']['req'], - ): CancelablePromise<$OpenApiTs['/pet']['post']['res'][200]> { + data: PetAddPetData, + ): CancelablePromise { return __request(OpenAPI, { body: data.requestBody, errors: { @@ -38,8 +71,8 @@ export class PetService { * @throws ApiError */ public static updatePet( - data: $OpenApiTs['/pet']['put']['req'], - ): CancelablePromise<$OpenApiTs['/pet']['put']['res'][200]> { + data: PetUpdatePetData, + ): CancelablePromise { return __request(OpenAPI, { body: data.requestBody, errors: { @@ -62,8 +95,8 @@ export class PetService { * @throws ApiError */ public static findPetsByStatus( - data: $OpenApiTs['/pet/findByStatus']['get']['req'] = {}, - ): CancelablePromise<$OpenApiTs['/pet/findByStatus']['get']['res'][200]> { + data: PetFindPetsByStatusData = {}, + ): CancelablePromise { return __request(OpenAPI, { errors: { 400: 'Invalid status value', @@ -85,8 +118,8 @@ export class PetService { * @throws ApiError */ public static findPetsByTags( - data: $OpenApiTs['/pet/findByTags']['get']['req'] = {}, - ): CancelablePromise<$OpenApiTs['/pet/findByTags']['get']['res'][200]> { + data: PetFindPetsByTagsData = {}, + ): CancelablePromise { return __request(OpenAPI, { errors: { 400: 'Invalid tag value', @@ -108,8 +141,8 @@ export class PetService { * @throws ApiError */ public static getPetById( - data: $OpenApiTs['/pet/{petId}']['get']['req'], - ): CancelablePromise<$OpenApiTs['/pet/{petId}']['get']['res'][200]> { + data: PetGetPetByIdData, + ): CancelablePromise { return __request(OpenAPI, { errors: { 400: 'Invalid ID supplied', @@ -132,7 +165,7 @@ export class PetService { * @throws ApiError */ public static updatePetWithForm( - data: $OpenApiTs['/pet/{petId}']['post']['req'], + data: PetUpdatePetWithFormData, ): CancelablePromise { return __request(OpenAPI, { errors: { @@ -157,9 +190,7 @@ export class PetService { * @param data.apiKey * @throws ApiError */ - public static deletePet( - data: $OpenApiTs['/pet/{petId}']['delete']['req'], - ): CancelablePromise { + public static deletePet(data: PetDeletePetData): CancelablePromise { return __request(OpenAPI, { errors: { 400: 'Invalid pet value', @@ -185,10 +216,8 @@ export class PetService { * @throws ApiError */ public static uploadFile( - data: $OpenApiTs['/pet/{petId}/uploadImage']['post']['req'], - ): CancelablePromise< - $OpenApiTs['/pet/{petId}/uploadImage']['post']['res'][200] - > { + data: PetUploadFileData, + ): CancelablePromise { return __request(OpenAPI, { body: data.requestBody, mediaType: 'application/octet-stream', @@ -211,9 +240,7 @@ export class StoreService { * @returns number successful operation * @throws ApiError */ - public static getInventory(): CancelablePromise< - $OpenApiTs['/store/inventory']['get']['res'][200] - > { + public static getInventory(): CancelablePromise { return __request(OpenAPI, { method: 'GET', url: '/store/inventory', @@ -229,8 +256,8 @@ export class StoreService { * @throws ApiError */ public static placeOrder( - data: $OpenApiTs['/store/order']['post']['req'] = {}, - ): CancelablePromise<$OpenApiTs['/store/order']['post']['res'][200]> { + data: StorePlaceOrderData = {}, + ): CancelablePromise { return __request(OpenAPI, { body: data.requestBody, errors: { @@ -251,10 +278,8 @@ export class StoreService { * @throws ApiError */ public static getOrderById( - data: $OpenApiTs['/store/order/{orderId}']['get']['req'], - ): CancelablePromise< - $OpenApiTs['/store/order/{orderId}']['get']['res'][200] - > { + data: StoreGetOrderByIdData, + ): CancelablePromise { return __request(OpenAPI, { errors: { 400: 'Invalid ID supplied', @@ -276,7 +301,7 @@ export class StoreService { * @throws ApiError */ public static deleteOrder( - data: $OpenApiTs['/store/order/{orderId}']['delete']['req'], + data: StoreDeleteOrderData, ): CancelablePromise { return __request(OpenAPI, { errors: { @@ -302,8 +327,8 @@ export class UserService { * @throws ApiError */ public static createUser( - data: $OpenApiTs['/user']['post']['req'] = {}, - ): CancelablePromise<$OpenApiTs['/user']['post']['res'][200]> { + data: UserCreateUserData = {}, + ): CancelablePromise { return __request(OpenAPI, { body: data.requestBody, mediaType: 'application/json', @@ -322,11 +347,8 @@ export class UserService { * @throws ApiError */ public static createUsersWithListInput( - data: $OpenApiTs['/user/createWithList']['post']['req'] = {}, - ): CancelablePromise< - | $OpenApiTs['/user/createWithList']['post']['res'][200] - | $OpenApiTs['/user/createWithList']['post']['res'][200] - > { + data: UserCreateUsersWithListInputData = {}, + ): CancelablePromise { return __request(OpenAPI, { body: data.requestBody, mediaType: 'application/json', @@ -344,8 +366,8 @@ export class UserService { * @throws ApiError */ public static loginUser( - data: $OpenApiTs['/user/login']['get']['req'] = {}, - ): CancelablePromise<$OpenApiTs['/user/login']['get']['res'][200]> { + data: UserLoginUserData = {}, + ): CancelablePromise { return __request(OpenAPI, { errors: { 400: 'Invalid username/password supplied', @@ -364,9 +386,7 @@ export class UserService { * @returns unknown successful operation * @throws ApiError */ - public static logoutUser(): CancelablePromise< - $OpenApiTs['/user/logout']['get']['res'][200] - > { + public static logoutUser(): CancelablePromise { return __request(OpenAPI, { method: 'GET', url: '/user/logout', @@ -381,8 +401,8 @@ export class UserService { * @throws ApiError */ public static getUserByName( - data: $OpenApiTs['/user/{username}']['get']['req'], - ): CancelablePromise<$OpenApiTs['/user/{username}']['get']['res'][200]> { + data: UserGetUserByNameData, + ): CancelablePromise { return __request(OpenAPI, { errors: { 400: 'Invalid username supplied', @@ -406,8 +426,8 @@ export class UserService { * @throws ApiError */ public static updateUser( - data: $OpenApiTs['/user/{username}']['put']['req'], - ): CancelablePromise<$OpenApiTs['/user/{username}']['put']['res'][200]> { + data: UserUpdateUserData, + ): CancelablePromise { return __request(OpenAPI, { body: data.requestBody, mediaType: 'application/json', @@ -426,9 +446,7 @@ export class UserService { * @param data.username The name that needs to be deleted * @throws ApiError */ - public static deleteUser( - data: $OpenApiTs['/user/{username}']['delete']['req'], - ): CancelablePromise { + public static deleteUser(data: UserDeleteUserData): CancelablePromise { return __request(OpenAPI, { errors: { 400: 'Invalid username supplied', diff --git a/examples/openapi-ts-fetch/src/client/types.gen.ts b/examples/openapi-ts-fetch/src/client/types.gen.ts index fccba9e78..41dcf806a 100644 --- a/examples/openapi-ts-fetch/src/client/types.gen.ts +++ b/examples/openapi-ts-fetch/src/client/types.gen.ts @@ -72,6 +72,173 @@ export type ApiResponse = { message?: string; }; +export type PetAddPetData = { + /** + * Create a new pet in the store + */ + requestBody: Pet; +}; + +export type PetAddPetResponse = Pet; + +export type PetUpdatePetData = { + /** + * Update an existent pet in the store + */ + requestBody: Pet; +}; + +export type PetUpdatePetResponse = Pet; + +export type PetFindPetsByStatusData = { + /** + * Status values that need to be considered for filter + */ + status?: 'available' | 'pending' | 'sold'; +}; + +export type PetFindPetsByStatusResponse = Array; + +export type PetFindPetsByTagsData = { + /** + * Tags to filter by + */ + tags?: Array; +}; + +export type PetFindPetsByTagsResponse = Array; + +export type PetGetPetByIdData = { + /** + * ID of pet to return + */ + petId: number; +}; + +export type PetGetPetByIdResponse = Pet; + +export type PetUpdatePetWithFormData = { + /** + * Name of pet that needs to be updated + */ + name?: string; + /** + * ID of pet that needs to be updated + */ + petId: number; + /** + * Status of pet that needs to be updated + */ + status?: string; +}; + +export type PetDeletePetData = { + apiKey?: string; + /** + * Pet id to delete + */ + petId: number; +}; + +export type PetUploadFileData = { + /** + * Additional Metadata + */ + additionalMetadata?: string; + /** + * ID of pet to update + */ + petId: number; + requestBody?: Blob | File; +}; + +export type PetUploadFileResponse = ApiResponse; + +export type StoreGetInventoryResponse = { + [key: string]: number; +}; + +export type StorePlaceOrderData = { + requestBody?: Order; +}; + +export type StorePlaceOrderResponse = Order; + +export type StoreGetOrderByIdData = { + /** + * ID of order that needs to be fetched + */ + orderId: number; +}; + +export type StoreGetOrderByIdResponse = Order; + +export type StoreDeleteOrderData = { + /** + * ID of the order that needs to be deleted + */ + orderId: number; +}; + +export type UserCreateUserData = { + /** + * Created user object + */ + requestBody?: User; +}; + +export type UserCreateUserResponse = User; + +export type UserCreateUsersWithListInputData = { + requestBody?: Array; +}; + +export type UserCreateUsersWithListInputResponse = User | unknown; + +export type UserLoginUserData = { + /** + * The password for login in clear text + */ + password?: string; + /** + * The user name for login + */ + username?: string; +}; + +export type UserLoginUserResponse = string; + +export type UserLogoutUserResponse = unknown; + +export type UserGetUserByNameData = { + /** + * The name that needs to be fetched. Use user1 for testing. + */ + username: string; +}; + +export type UserGetUserByNameResponse = User; + +export type UserUpdateUserData = { + /** + * Update an existent user in the store + */ + requestBody?: User; + /** + * name that needs to be updated + */ + username: string; +}; + +export type UserUpdateUserResponse = unknown; + +export type UserDeleteUserData = { + /** + * The name that needs to be deleted + */ + username: string; +}; + export type $OpenApiTs = { '/pet': { post: { @@ -324,7 +491,7 @@ export type $OpenApiTs = { /** * successful operation */ - 200: User; + default: User; }; }; }; @@ -334,10 +501,14 @@ export type $OpenApiTs = { requestBody?: Array; }; res: { + /** + * Successful operation + */ + 200: User; /** * successful operation */ - 200: unknown; + default: unknown; }; }; }; @@ -371,7 +542,7 @@ export type $OpenApiTs = { /** * successful operation */ - 200: unknown; + default: unknown; }; }; }; @@ -413,7 +584,7 @@ export type $OpenApiTs = { /** * successful operation */ - 200: unknown; + default: unknown; }; }; delete: { diff --git a/packages/openapi-ts/src/openApi/common/interfaces/client.ts b/packages/openapi-ts/src/openApi/common/interfaces/client.ts index 49e1a849a..7ce8f89ee 100644 --- a/packages/openapi-ts/src/openApi/common/interfaces/client.ts +++ b/packages/openapi-ts/src/openApi/common/interfaces/client.ts @@ -28,7 +28,7 @@ export interface OperationParameters extends Pick { export interface OperationResponse extends Model { in: 'response' | 'header'; - code: number; + code: number | 'default'; } export interface Operation extends OperationParameters { diff --git a/packages/openapi-ts/src/openApi/common/parser/__tests__/operation.spec.ts b/packages/openapi-ts/src/openApi/common/parser/__tests__/operation.spec.ts index 1f1c55b10..6f7451d80 100644 --- a/packages/openapi-ts/src/openApi/common/parser/__tests__/operation.spec.ts +++ b/packages/openapi-ts/src/openApi/common/parser/__tests__/operation.spec.ts @@ -251,7 +251,7 @@ describe('getOperationParameterName', () => { describe('getOperationResponseCode', () => { it.each([ { expected: null, input: '' }, - { expected: 200, input: 'default' }, + { expected: 'default', input: 'default' }, { expected: 200, input: '200' }, { expected: 300, input: '300' }, { expected: 400, input: '400' }, diff --git a/packages/openapi-ts/src/openApi/common/parser/operation.ts b/packages/openapi-ts/src/openApi/common/parser/operation.ts index ff6c2309e..6b4869281 100644 --- a/packages/openapi-ts/src/openApi/common/parser/operation.ts +++ b/packages/openapi-ts/src/openApi/common/parser/operation.ts @@ -55,15 +55,14 @@ export const getOperationResponseHeader = ( export const getOperationResponseCode = ( value: string | 'default', -): number | null => { - // You can specify a "default" response, this is treated as HTTP code 200 +): number | 'default' | null => { if (value === 'default') { - return 200; + return 'default'; } // Check if we can parse the code and return of successful. if (/[0-9]+/g.test(value)) { - const code = parseInt(value); + const code = Number.parseInt(value); if (Number.isInteger(code)) { return Math.abs(code); } @@ -76,6 +75,6 @@ export const getOperationErrors = ( operationResponses: OperationResponse[], ): OperationResponse[] => operationResponses.filter( - (operationResponse) => - operationResponse.code >= 300 && operationResponse.description, + ({ code, description }) => + typeof code === 'number' && code >= 300 && description, ); diff --git a/packages/openapi-ts/src/openApi/v2/parser/getOperation.ts b/packages/openapi-ts/src/openApi/v2/parser/getOperation.ts index ee5c7fa0f..8c1d6a593 100644 --- a/packages/openapi-ts/src/openApi/v2/parser/getOperation.ts +++ b/packages/openapi-ts/src/openApi/v2/parser/getOperation.ts @@ -1,3 +1,4 @@ +import { getOperationResults } from '../../../utils/operation'; import type { Operation, OperationParameters, @@ -13,7 +14,6 @@ import type { OpenApi } from '../interfaces/OpenApi'; import type { OpenApiOperation } from '../interfaces/OpenApiOperation'; import { getOperationParameters } from './getOperationParameters'; import { getOperationResponses } from './getOperationResponses'; -import { getOperationResults } from './getOperationResults'; export const getOperation = ( openApi: OpenApi, diff --git a/packages/openapi-ts/src/openApi/v2/parser/getOperationResponse.ts b/packages/openapi-ts/src/openApi/v2/parser/getOperationResponse.ts index 48eca8636..1e30ace28 100644 --- a/packages/openapi-ts/src/openApi/v2/parser/getOperationResponse.ts +++ b/packages/openapi-ts/src/openApi/v2/parser/getOperationResponse.ts @@ -10,12 +10,12 @@ import { getModel } from './getModel'; export const getOperationResponse = ( openApi: OpenApi, response: OpenApiResponse, - responseCode: number, + code: number | 'default', ): OperationResponse => { const operationResponse: OperationResponse = { $refs: [], - base: responseCode !== 204 ? 'unknown' : 'void', - code: responseCode, + base: code !== 204 ? 'unknown' : 'void', + code, description: response.description || null, enum: [], enums: [], @@ -30,7 +30,7 @@ export const getOperationResponse = ( name: '', properties: [], template: null, - type: responseCode !== 204 ? 'unknown' : 'void', + type: code !== 204 ? 'unknown' : 'void', }; // If this response has a schema, then we need to check two things: diff --git a/packages/openapi-ts/src/openApi/v2/parser/getOperationResponses.ts b/packages/openapi-ts/src/openApi/v2/parser/getOperationResponses.ts index d55f8ef3e..e1d4d89ae 100644 --- a/packages/openapi-ts/src/openApi/v2/parser/getOperationResponses.ts +++ b/packages/openapi-ts/src/openApi/v2/parser/getOperationResponses.ts @@ -31,7 +31,7 @@ export const getOperationResponses = ( } } - // Sort the responses to 2XX success codes come before 4XX and 5XX error codes. + // Sort the responses to 2xx success codes come before 4xx and 5xx error codes. return operationResponses.sort((a, b): number => a.code < b.code ? -1 : a.code > b.code ? 1 : 0, ); diff --git a/packages/openapi-ts/src/openApi/v3/parser/getOperationResponse.ts b/packages/openapi-ts/src/openApi/v3/parser/getOperationResponse.ts index 10096a45e..cadac557b 100644 --- a/packages/openapi-ts/src/openApi/v3/parser/getOperationResponse.ts +++ b/packages/openapi-ts/src/openApi/v3/parser/getOperationResponse.ts @@ -11,12 +11,12 @@ import { getModel } from './getModel'; export const getOperationResponse = ( openApi: OpenApi, response: OpenApiResponse, - responseCode: number, + code: number | 'default', ): OperationResponse => { const operationResponse: OperationResponse = { $refs: [], - base: responseCode !== 204 ? 'unknown' : 'void', - code: responseCode, + base: code !== 204 ? 'unknown' : 'void', + code, description: response.description || null, enum: [], enums: [], @@ -31,7 +31,7 @@ export const getOperationResponse = ( name: '', properties: [], template: null, - type: responseCode !== 204 ? 'unknown' : 'void', + type: code !== 204 ? 'unknown' : 'void', }; if (response.content) { diff --git a/packages/openapi-ts/src/openApi/v3/parser/getOperationResponses.ts b/packages/openapi-ts/src/openApi/v3/parser/getOperationResponses.ts index d55f8ef3e..e1d4d89ae 100644 --- a/packages/openapi-ts/src/openApi/v3/parser/getOperationResponses.ts +++ b/packages/openapi-ts/src/openApi/v3/parser/getOperationResponses.ts @@ -31,7 +31,7 @@ export const getOperationResponses = ( } } - // Sort the responses to 2XX success codes come before 4XX and 5XX error codes. + // Sort the responses to 2xx success codes come before 4xx and 5xx error codes. return operationResponses.sort((a, b): number => a.code < b.code ? -1 : a.code > b.code ? 1 : 0, ); diff --git a/packages/openapi-ts/src/openApi/v3/parser/getOperationResults.ts b/packages/openapi-ts/src/openApi/v3/parser/getOperationResults.ts deleted file mode 100644 index f48c83e29..000000000 --- a/packages/openapi-ts/src/openApi/v3/parser/getOperationResults.ts +++ /dev/null @@ -1,29 +0,0 @@ -import type { Model, OperationResponse } from '../../common/interfaces/client'; - -const areEqual = (a: Model, b: Model): boolean => { - const equal = - a.type === b.type && a.base === b.base && a.template === b.template; - if (equal && a.link && b.link) { - return areEqual(a.link, b.link); - } - return equal; -}; - -export const getOperationResults = ( - operationResponses: OperationResponse[], -): OperationResponse[] => { - const operationResults: OperationResponse[] = []; - - // Filter out success response codes - operationResponses.forEach((operationResponse) => { - const { code } = operationResponse; - if (code && code >= 200 && code < 300) { - operationResults.push(operationResponse); - } - }); - - return operationResults.filter( - (operationResult, index, arr) => - arr.findIndex((item) => areEqual(item, operationResult)) === index, - ); -}; diff --git a/packages/openapi-ts/src/openApi/v3/parser/operation.ts b/packages/openapi-ts/src/openApi/v3/parser/operation.ts index 821359f30..7a6292ea6 100644 --- a/packages/openapi-ts/src/openApi/v3/parser/operation.ts +++ b/packages/openapi-ts/src/openApi/v3/parser/operation.ts @@ -1,3 +1,4 @@ +import { getOperationResults } from '../../../utils/operation'; import type { Operation, OperationParameter, @@ -17,7 +18,6 @@ import type { OpenApiRequestBody } from '../interfaces/OpenApiRequestBody'; import { getOperationParameters } from './getOperationParameters'; import { getOperationRequestBody } from './getOperationRequestBody'; import { getOperationResponses } from './getOperationResponses'; -import { getOperationResults } from './getOperationResults'; // add global path parameters, skip duplicate names const mergeParameters = ( diff --git a/packages/openapi-ts/src/openApi/v2/parser/getOperationResults.ts b/packages/openapi-ts/src/utils/operation.ts similarity index 82% rename from packages/openapi-ts/src/openApi/v2/parser/getOperationResults.ts rename to packages/openapi-ts/src/utils/operation.ts index f48c83e29..670597938 100644 --- a/packages/openapi-ts/src/openApi/v2/parser/getOperationResults.ts +++ b/packages/openapi-ts/src/utils/operation.ts @@ -1,4 +1,7 @@ -import type { Model, OperationResponse } from '../../common/interfaces/client'; +import type { + Model, + OperationResponse, +} from '../openApi/common/interfaces/client'; const areEqual = (a: Model, b: Model): boolean => { const equal = @@ -17,7 +20,7 @@ export const getOperationResults = ( // Filter out success response codes operationResponses.forEach((operationResponse) => { const { code } = operationResponse; - if (code && code >= 200 && code < 300) { + if (code && (code === 'default' || (code >= 200 && code < 300))) { operationResults.push(operationResponse); } }); diff --git a/packages/openapi-ts/src/utils/write/services.ts b/packages/openapi-ts/src/utils/write/services.ts index ba15f36d7..cf95deeba 100644 --- a/packages/openapi-ts/src/utils/write/services.ts +++ b/packages/openapi-ts/src/utils/write/services.ts @@ -1,3 +1,5 @@ +import camelcase from 'camelcase'; + import { ClassElement, compiler, @@ -12,28 +14,49 @@ import { modelIsRequired } from '../required'; import { transformServiceName } from '../transform'; import { unique } from '../unique'; -export const serviceExportedNamespace = () => '$OpenApiTs'; +type OnImport = (importedType: string) => void; + +export const operationDataTypeName = (operation: Operation) => + `${camelcase(operation.service, { + pascalCase: true, + })}${camelcase(operation.name, { + pascalCase: true, + })}Data`; -const toOperationParamType = (operation: Operation): FunctionParameter[] => { +export const operationResponseTypeName = (operation: Operation) => + `${camelcase(operation.service, { + pascalCase: true, + })}${camelcase(operation.name, { + pascalCase: true, + })}Response`; + +const toOperationParamType = ( + operation: Operation, + onImport: OnImport, +): FunctionParameter[] => { const config = getConfig(); - const baseTypePath = `${serviceExportedNamespace()}['${operation.path}']['${operation.method.toLocaleLowerCase()}']['req']`; + + const importedType = operationDataTypeName(operation); + if (!operation.parameters.length) { return []; } + onImport(importedType); + if (config.useOptions) { const isOptional = operation.parameters.every((p) => !p.isRequired); return [ { default: isOptional ? {} : undefined, name: 'data', - type: baseTypePath, + type: importedType, }, ]; } return operation.parameters.map((p) => { - const typePath = `${baseTypePath}['${p.name}']`; + const typePath = `${importedType}['${p.name}']`; return { default: p?.default, isRequired: modelIsRequired(p) === '', @@ -43,19 +66,17 @@ const toOperationParamType = (operation: Operation): FunctionParameter[] => { }); }; -const toOperationReturnType = (operation: Operation) => { +const toOperationReturnType = (operation: Operation, onImport: OnImport) => { const config = getConfig(); - const baseTypePath = `${serviceExportedNamespace()}['${operation.path}']['${operation.method.toLocaleLowerCase()}']['res']`; const results = operation.results; // TODO: we should return nothing when results don't exist // can't remove this logic without removing request/name config // as it complicates things let returnType = compiler.typedef.basic('void'); if (results.length) { - const types = results.map( - (result) => `${baseTypePath}[${String(result.code)}]`, - ); - returnType = compiler.typedef.union(types); + const importedType = operationResponseTypeName(operation); + onImport(importedType); + returnType = compiler.typedef.union([importedType]); } if (config.useOptions && config.services.response === 'response') { returnType = compiler.typedef.basic('ApiResult', [returnType]); @@ -162,7 +183,7 @@ const toRequestOptions = (operation: Operation) => { obj.responseHeader = operation.responseHeader; } if (operation.errors.length) { - const errors: Record = {}; + const errors: Record = {}; operation.errors.forEach((err) => { errors[err.code] = escapeDescription(err.description ?? ''); }); @@ -206,7 +227,7 @@ const toOperationStatements = (operation: Operation) => { return statements; }; -export const processService = (service: Service) => { +export const processService = (service: Service, onImport: OnImport) => { const config = getConfig(); const members: ClassElement[] = service.operations.map((operation) => { const node = compiler.class.method({ @@ -214,8 +235,8 @@ export const processService = (service: Service) => { comment: toOperationComment(operation), isStatic: config.name === undefined && config.client !== 'angular', name: operation.name, - parameters: toOperationParamType(operation), - returnType: toOperationReturnType(operation), + parameters: toOperationParamType(operation, onImport), + returnType: toOperationReturnType(operation, onImport), statements: toOperationStatements(operation), }); return node; @@ -280,9 +301,10 @@ export const processServices = async ({ let imports: string[] = []; for (const service of client.services) { - file.add(processService(service)); - const exported = serviceExportedNamespace(); - imports = [...imports, exported]; + const serviceClass = processService(service, (importedType) => { + imports = [...imports, importedType]; + }); + file.add(serviceClass); } // Import required packages and core files. diff --git a/packages/openapi-ts/src/utils/write/types.ts b/packages/openapi-ts/src/utils/write/types.ts index df2bb21b7..900e06b4f 100644 --- a/packages/openapi-ts/src/utils/write/types.ts +++ b/packages/openapi-ts/src/utils/write/types.ts @@ -13,11 +13,13 @@ import { enumKey, enumName, enumUnionType, enumValue } from '../enum'; import { escapeComment } from '../escape'; import { sortByName } from '../sort'; import { transformTypeName } from '../transform'; -import { serviceExportedNamespace } from './services'; +import { operationDataTypeName, operationResponseTypeName } from './services'; import { toType } from './type'; type OnNode = (node: Node) => void; +const serviceExportedNamespace = () => '$OpenApiTs'; + const emptyModel: Model = { $refs: [], base: '', @@ -128,7 +130,7 @@ const processModel = (client: Client, model: Model, onNode: OnNode) => { }; const processServiceTypes = (services: Service[], onNode: OnNode) => { - type ResMap = Map; + type ResMap = Map; type MethodMap = Map<'req' | 'res', ResMap | OperationParameter[]>; type MethodKey = Service['operations'][number]['method']; type PathMap = Map; @@ -156,6 +158,19 @@ const processServiceTypes = (services: Service[], onNode: OnNode) => { if (hasReq) { methodMap.set('req', sortByName([...operation.parameters])); + + // create type export for operation data + const type = toType({ + ...emptyModel, + export: 'interface', + isRequired: true, + properties: sortByName([...operation.parameters]), + }); + const node = compiler.typedef.alias( + operationDataTypeName(operation), + type, + ); + onNode(node); } if (hasRes) { @@ -172,6 +187,28 @@ const processServiceTypes = (services: Service[], onNode: OnNode) => { operation.results.forEach((result) => { resMap.set(result.code, result); }); + + // create type export for operation response + let responseProperties: Model[] = []; + operation.results.map((result) => { + if ( + result.code === 'default' || + (result.code >= 200 && result.code < 300) + ) { + responseProperties = [...responseProperties, result]; + } + }); + const type = toType({ + ...emptyModel, + export: 'any-of', + isRequired: true, + properties: responseProperties, + }); + const node = compiler.typedef.alias( + operationResponseTypeName(operation), + type, + ); + onNode(node); } if (hasErr) { diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v2/services.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v2/services.gen.ts.snap index eae0d9049..c4aeaec96 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v2/services.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v2/services.gen.ts.snap @@ -3,7 +3,7 @@ import type { CancelablePromise } from './core/CancelablePromise'; import { OpenAPI } from './core/OpenAPI'; import { request as __request } from './core/request'; -import type { $OpenApiTs } from './types.gen'; +import type { DescriptionsCallWithDescriptionsData, ParametersCallWithParametersData, ParametersCallWithWeirdParameterNamesData, DefaultsCallWithDefaultParametersData, DefaultsCallWithDefaultOptionalParametersData, DefaultsCallToTestOrderOfParamsData, NoContentCallWithNoContentResponseResponse, NoContentCallWithResponseAndNoContentResponseResponse, ResponseCallWithResponseAndNoContentResponseResponse, ResponseCallWithResponseResponse, ResponseCallWithDuplicateResponsesResponse, ResponseCallWithResponsesResponse, MultipleTags1DummyAResponse, MultipleTags1DummyBResponse, MultipleTags2DummyAResponse, MultipleTags2DummyBResponse, MultipleTags3DummyBResponse, CollectionFormatCollectionFormatData, TypesTypesData, TypesTypesResponse, ComplexComplexTypesData, ComplexComplexTypesResponse, HeaderCallWithResultFromHeaderResponse, ErrorTestErrorCodeData, ErrorTestErrorCodeResponse, NonAsciiÆøåÆøÅöôêÊNonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiÆøåÆøÅöôêÊNonAsciiæøåÆøÅöôêÊ字符串Response } from './types.gen'; export class DefaultService { /** @@ -105,7 +105,7 @@ export class DescriptionsService { * @param data.parameterWithReservedCharacters Testing reserved characters in string: * inline * and ** inline ** should work * @throws ApiError */ - public static callWithDescriptions(data: $OpenApiTs['/api/v{api-version}/descriptions/']['post']['req'] = {}): CancelablePromise { + public static callWithDescriptions(data: DescriptionsCallWithDescriptionsData = {}): CancelablePromise { return __request(OpenAPI, { method: 'POST', url: '/api/v{api-version}/descriptions/', @@ -132,7 +132,7 @@ export class ParametersService { * @param data.parameterPath This is the parameter that goes into the path * @throws ApiError */ - public static callWithParameters(data: $OpenApiTs['/api/v{api-version}/parameters/{parameterPath}']['post']['req']): CancelablePromise { + public static callWithParameters(data: ParametersCallWithParametersData): CancelablePromise { return __request(OpenAPI, { method: 'POST', url: '/api/v{api-version}/parameters/{parameterPath}', @@ -164,7 +164,7 @@ export class ParametersService { * @param data._default This is the parameter with a reserved keyword * @throws ApiError */ - public static callWithWeirdParameterNames(data: $OpenApiTs['/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}']['post']['req']): CancelablePromise { + public static callWithWeirdParameterNames(data: ParametersCallWithWeirdParameterNamesData): CancelablePromise { return __request(OpenAPI, { method: 'POST', url: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}', @@ -199,7 +199,7 @@ export class DefaultsService { * @param data.parameterModel This is a simple model with default value * @throws ApiError */ - public static callWithDefaultParameters(data: $OpenApiTs['/api/v{api-version}/defaults']['get']['req']): CancelablePromise { + public static callWithDefaultParameters(data: DefaultsCallWithDefaultParametersData): CancelablePromise { return __request(OpenAPI, { method: 'GET', url: '/api/v{api-version}/defaults', @@ -222,7 +222,7 @@ export class DefaultsService { * @param data.parameterModel This is a simple model that is optional with default value * @throws ApiError */ - public static callWithDefaultOptionalParameters(data: $OpenApiTs['/api/v{api-version}/defaults']['post']['req'] = {}): CancelablePromise { + public static callWithDefaultOptionalParameters(data: DefaultsCallWithDefaultOptionalParametersData = {}): CancelablePromise { return __request(OpenAPI, { method: 'POST', url: '/api/v{api-version}/defaults', @@ -248,7 +248,7 @@ export class DefaultsService { * @param data.parameterStringNullableWithDefault This is a string that can be null with default * @throws ApiError */ - public static callToTestOrderOfParams(data: $OpenApiTs['/api/v{api-version}/defaults']['put']['req']): CancelablePromise { + public static callToTestOrderOfParams(data: DefaultsCallToTestOrderOfParamsData): CancelablePromise { return __request(OpenAPI, { method: 'PUT', url: '/api/v{api-version}/defaults', @@ -315,7 +315,7 @@ export class NoContentService { * @returns void Success * @throws ApiError */ - public static callWithNoContentResponse(): CancelablePromise<$OpenApiTs['/api/v{api-version}/no-content']['get']['res'][204]> { + public static callWithNoContentResponse(): CancelablePromise { return __request(OpenAPI, { method: 'GET', url: '/api/v{api-version}/no-content' @@ -327,7 +327,7 @@ export class NoContentService { * @returns void Success * @throws ApiError */ - public static callWithResponseAndNoContentResponse(): CancelablePromise<$OpenApiTs['/api/v{api-version}/multiple-tags/response-and-no-content']['get']['res'][200] | $OpenApiTs['/api/v{api-version}/multiple-tags/response-and-no-content']['get']['res'][204]> { + public static callWithResponseAndNoContentResponse(): CancelablePromise { return __request(OpenAPI, { method: 'GET', url: '/api/v{api-version}/multiple-tags/response-and-no-content' @@ -342,7 +342,7 @@ export class ResponseService { * @returns void Success * @throws ApiError */ - public static callWithResponseAndNoContentResponse(): CancelablePromise<$OpenApiTs['/api/v{api-version}/multiple-tags/response-and-no-content']['get']['res'][200] | $OpenApiTs['/api/v{api-version}/multiple-tags/response-and-no-content']['get']['res'][204]> { + public static callWithResponseAndNoContentResponse(): CancelablePromise { return __request(OpenAPI, { method: 'GET', url: '/api/v{api-version}/multiple-tags/response-and-no-content' @@ -353,7 +353,7 @@ export class ResponseService { * @returns ModelWithString Message for default response * @throws ApiError */ - public static callWithResponse(): CancelablePromise<$OpenApiTs['/api/v{api-version}/response']['get']['res'][200]> { + public static callWithResponse(): CancelablePromise { return __request(OpenAPI, { method: 'GET', url: '/api/v{api-version}/response' @@ -361,10 +361,10 @@ export class ResponseService { } /** - * @returns ModelWithString Message for default response + * @returns ModelWithString Message for 201 response * @throws ApiError */ - public static callWithDuplicateResponses(): CancelablePromise<$OpenApiTs['/api/v{api-version}/response']['post']['res'][200]> { + public static callWithDuplicateResponses(): CancelablePromise { return __request(OpenAPI, { method: 'POST', url: '/api/v{api-version}/response', @@ -378,12 +378,12 @@ export class ResponseService { /** * @returns unknown Message for 200 response - * @returns ModelWithString Message for default response * @returns ModelThatExtends Message for 201 response * @returns ModelThatExtendsExtends Message for 202 response + * @returns ModelWithString Message for default response * @throws ApiError */ - public static callWithResponses(): CancelablePromise<$OpenApiTs['/api/v{api-version}/response']['put']['res'][200] | $OpenApiTs['/api/v{api-version}/response']['put']['res'][200] | $OpenApiTs['/api/v{api-version}/response']['put']['res'][201] | $OpenApiTs['/api/v{api-version}/response']['put']['res'][202]> { + public static callWithResponses(): CancelablePromise { return __request(OpenAPI, { method: 'PUT', url: '/api/v{api-version}/response', @@ -402,7 +402,7 @@ export class MultipleTags1Service { * @returns void Success * @throws ApiError */ - public static dummyA(): CancelablePromise<$OpenApiTs['/api/v{api-version}/multiple-tags/a']['get']['res'][204]> { + public static dummyA(): CancelablePromise { return __request(OpenAPI, { method: 'GET', url: '/api/v{api-version}/multiple-tags/a' @@ -413,7 +413,7 @@ export class MultipleTags1Service { * @returns void Success * @throws ApiError */ - public static dummyB(): CancelablePromise<$OpenApiTs['/api/v{api-version}/multiple-tags/b']['get']['res'][204]> { + public static dummyB(): CancelablePromise { return __request(OpenAPI, { method: 'GET', url: '/api/v{api-version}/multiple-tags/b' @@ -427,7 +427,7 @@ export class MultipleTags2Service { * @returns void Success * @throws ApiError */ - public static dummyA(): CancelablePromise<$OpenApiTs['/api/v{api-version}/multiple-tags/a']['get']['res'][204]> { + public static dummyA(): CancelablePromise { return __request(OpenAPI, { method: 'GET', url: '/api/v{api-version}/multiple-tags/a' @@ -438,7 +438,7 @@ export class MultipleTags2Service { * @returns void Success * @throws ApiError */ - public static dummyB(): CancelablePromise<$OpenApiTs['/api/v{api-version}/multiple-tags/b']['get']['res'][204]> { + public static dummyB(): CancelablePromise { return __request(OpenAPI, { method: 'GET', url: '/api/v{api-version}/multiple-tags/b' @@ -452,7 +452,7 @@ export class MultipleTags3Service { * @returns void Success * @throws ApiError */ - public static dummyB(): CancelablePromise<$OpenApiTs['/api/v{api-version}/multiple-tags/b']['get']['res'][204]> { + public static dummyB(): CancelablePromise { return __request(OpenAPI, { method: 'GET', url: '/api/v{api-version}/multiple-tags/b' @@ -471,7 +471,7 @@ export class CollectionFormatService { * @param data.parameterArrayMulti This is an array parameter that is sent as multi format (multiple parameter instances) * @throws ApiError */ - public static collectionFormat(data: $OpenApiTs['/api/v{api-version}/collectionFormat']['get']['req']): CancelablePromise { + public static collectionFormat(data: CollectionFormatCollectionFormatData): CancelablePromise { return __request(OpenAPI, { method: 'GET', url: '/api/v{api-version}/collectionFormat', @@ -504,7 +504,7 @@ export class TypesService { * @returns unknown Response is a simple object * @throws ApiError */ - public static types(data: $OpenApiTs['/api/v{api-version}/types']['get']['req']): CancelablePromise<$OpenApiTs['/api/v{api-version}/types']['get']['res'][200] | $OpenApiTs['/api/v{api-version}/types']['get']['res'][201] | $OpenApiTs['/api/v{api-version}/types']['get']['res'][202] | $OpenApiTs['/api/v{api-version}/types']['get']['res'][203]> { + public static types(data: TypesTypesData): CancelablePromise { return __request(OpenAPI, { method: 'GET', url: '/api/v{api-version}/types', @@ -533,7 +533,7 @@ export class ComplexService { * @returns ModelWithString Successful response * @throws ApiError */ - public static complexTypes(data: $OpenApiTs['/api/v{api-version}/complex']['get']['req']): CancelablePromise<$OpenApiTs['/api/v{api-version}/complex']['get']['res'][200]> { + public static complexTypes(data: ComplexComplexTypesData): CancelablePromise { return __request(OpenAPI, { method: 'GET', url: '/api/v{api-version}/complex', @@ -555,7 +555,7 @@ export class HeaderService { * @returns string Successful response * @throws ApiError */ - public static callWithResultFromHeader(): CancelablePromise<$OpenApiTs['/api/v{api-version}/header']['post']['res'][200]> { + public static callWithResultFromHeader(): CancelablePromise { return __request(OpenAPI, { method: 'POST', url: '/api/v{api-version}/header', @@ -576,7 +576,7 @@ export class ErrorService { * @returns unknown Custom message: Successful response * @throws ApiError */ - public static testErrorCode(data: $OpenApiTs['/api/v{api-version}/error']['post']['req']): CancelablePromise<$OpenApiTs['/api/v{api-version}/error']['post']['res'][200]> { + public static testErrorCode(data: ErrorTestErrorCodeData): CancelablePromise { return __request(OpenAPI, { method: 'POST', url: '/api/v{api-version}/error', @@ -601,7 +601,7 @@ export class NonAsciiÆøåÆøÅöôêÊService { * @returns NonAsciiStringæøåÆØÅöôêÊ字符串 Successful response * @throws ApiError */ - public static nonAsciiæøåÆøÅöôêÊ字符串(data: $OpenApiTs['/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串']['post']['req']): CancelablePromise<$OpenApiTs['/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串']['post']['res'][200]> { + public static nonAsciiæøåÆøÅöôêÊ字符串(data: NonAsciiÆøåÆøÅöôêÊNonAsciiæøåÆøÅöôêÊ字符串Data): CancelablePromise { return __request(OpenAPI, { method: 'POST', url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串', diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v2/types.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v2/types.gen.ts.snap index a0b35f501..fb38c8238 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v2/types.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v2/types.gen.ts.snap @@ -397,6 +397,302 @@ export type ModelWithPattern = { patternWithBacktick?: string; }; +export type DescriptionsCallWithDescriptionsData = { + /** + * Testing backticks in string: `backticks` and ```multiple backticks``` should work + */ + parameterWithBackticks?: string; + /** + * Testing multiline comments in string: First line + * Second line + * + * Fourth line + */ + parameterWithBreaks?: string; + /** + * Testing expression placeholders in string: ${expression} should work + */ + parameterWithExpressionPlaceholders?: string; + /** + * Testing quotes in string: 'single quote''' and "double quotes""" should work + */ + parameterWithQuotes?: string; + /** + * Testing reserved characters in string: * inline * and ** inline ** should work + */ + parameterWithReservedCharacters?: string; + /** + * Testing slashes in string: \backwards\\\ and /forwards/// should work + */ + parameterWithSlashes?: string; +}; + +export type ParametersCallWithParametersData = { + /** + * This is the parameter that is sent as request body + */ + parameterBody: string; + /** + * This is the parameter that goes into the form data + */ + parameterForm: string; + /** + * This is the parameter that goes into the header + */ + parameterHeader: string; + /** + * This is the parameter that goes into the path + */ + parameterPath: string; + /** + * This is the parameter that goes into the query params + */ + parameterQuery: string; +}; + +export type ParametersCallWithWeirdParameterNamesData = { + /** + * This is the parameter with a reserved keyword + */ + _default?: string; + /** + * This is the parameter that is sent as request body + */ + parameterBody: string; + /** + * This is the parameter that goes into the request form data + */ + parameterForm: string; + /** + * This is the parameter that goes into the request header + */ + parameterHeader: string; + /** + * This is the parameter that goes into the path + */ + parameterPath1?: string; + /** + * This is the parameter that goes into the path + */ + parameterPath2?: string; + /** + * This is the parameter that goes into the path + */ + parameterPath3?: string; + /** + * This is the parameter that goes into the request query params + */ + parameterQuery: string; +}; + +export type DefaultsCallWithDefaultParametersData = { + /** + * This is a simple boolean with default value + */ + parameterBoolean: boolean; + /** + * This is a simple enum with default value + */ + parameterEnum: 'Success' | 'Warning' | 'Error'; + /** + * This is a simple model with default value + */ + parameterModel: ModelWithString; + /** + * This is a simple number with default value + */ + parameterNumber: number; + /** + * This is a simple string with default value + */ + parameterString: string; +}; + +export type DefaultsCallWithDefaultOptionalParametersData = { + /** + * This is a simple boolean that is optional with default value + */ + parameterBoolean?: boolean; + /** + * This is a simple enum that is optional with default value + */ + parameterEnum?: 'Success' | 'Warning' | 'Error'; + /** + * This is a simple model that is optional with default value + */ + parameterModel?: ModelWithString; + /** + * This is a simple number that is optional with default value + */ + parameterNumber?: number; + /** + * This is a simple string that is optional with default value + */ + parameterString?: string; +}; + +export type DefaultsCallToTestOrderOfParamsData = { + /** + * This is a optional string with default + */ + parameterOptionalStringWithDefault?: string; + /** + * This is a optional string with empty default + */ + parameterOptionalStringWithEmptyDefault?: string; + /** + * This is a optional string with no default + */ + parameterOptionalStringWithNoDefault?: string; + /** + * This is a string that can be null with default + */ + parameterStringNullableWithDefault?: string | null; + /** + * This is a string that can be null with no default + */ + parameterStringNullableWithNoDefault?: string | null; + /** + * This is a string with default + */ + parameterStringWithDefault: string; + /** + * This is a string with empty default + */ + parameterStringWithEmptyDefault: string; + /** + * This is a string with no default + */ + parameterStringWithNoDefault: string; +}; + +export type NoContentCallWithNoContentResponseResponse = void; + +export type NoContentCallWithResponseAndNoContentResponseResponse = unknown | void; + +export type ResponseCallWithResponseAndNoContentResponseResponse = unknown | void; + +export type ResponseCallWithResponseResponse = ModelWithString; + +export type ResponseCallWithDuplicateResponsesResponse = ModelWithString; + +export type ResponseCallWithResponsesResponse = { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; +} | ModelThatExtends | ModelThatExtendsExtends | ModelWithString; + +export type MultipleTags1DummyAResponse = void; + +export type MultipleTags1DummyBResponse = void; + +export type MultipleTags2DummyAResponse = void; + +export type MultipleTags2DummyBResponse = void; + +export type MultipleTags3DummyBResponse = void; + +export type CollectionFormatCollectionFormatData = { + /** + * This is an array parameter that is sent as csv format (comma-separated values) + */ + parameterArrayCsv: Array; + /** + * This is an array parameter that is sent as multi format (multiple parameter instances) + */ + parameterArrayMulti: Array; + /** + * This is an array parameter that is sent as pipes format (pipe-separated values) + */ + parameterArrayPipes: Array; + /** + * This is an array parameter that is sent as ssv format (space-separated values) + */ + parameterArraySsv: Array; + /** + * This is an array parameter that is sent as tsv format (tab-separated values) + */ + parameterArrayTsv: Array; +}; + +export type TypesTypesData = { + /** + * This is a number parameter + */ + id?: number; + /** + * This is an array parameter + */ + parameterArray: Array; + /** + * This is a boolean parameter + */ + parameterBoolean: boolean; + /** + * This is a dictionary parameter + */ + parameterDictionary: { + [key: string]: string; + }; + /** + * This is an enum parameter + */ + parameterEnum: 'Success' | 'Warning' | 'Error'; + /** + * This is a number parameter + */ + parameterNumber: number; + /** + * This is an object parameter + */ + parameterObject: unknown; + /** + * This is a string parameter + */ + parameterString: string; +}; + +export type TypesTypesResponse = number | string | boolean | unknown; + +export type ComplexComplexTypesData = { + /** + * Parameter containing object + */ + parameterObject: { + first?: { + second?: { + third?: string; + }; + }; + }; + /** + * Parameter containing reference + */ + parameterReference: ModelWithString; +}; + +export type ComplexComplexTypesResponse = Array; + +export type HeaderCallWithResultFromHeaderResponse = string; + +export type ErrorTestErrorCodeData = { + /** + * Status code to return + */ + status: string; +}; + +export type ErrorTestErrorCodeResponse = unknown; + +export type NonAsciiÆøåÆøÅöôêÊNonAsciiæøåÆøÅöôêÊ字符串Data = { + /** + * Dummy input param + */ + nonAsciiParamæøåÆøÅöôêÊ: number; +}; + +export type NonAsciiÆøåÆøÅöôêÊNonAsciiæøåÆøÅöôêÊ字符串Response = NonAsciiStringæøåÆØÅöôêÊ字符串; + export type $OpenApiTs = { '/api/v{api-version}/descriptions/': { post: { @@ -611,15 +907,15 @@ export type $OpenApiTs = { /** * Message for default response */ - 200: ModelWithString; + default: ModelWithString; }; }; post: { res: { /** - * Message for default response + * Message for 201 response */ - 200: ModelWithString; + 201: ModelWithString; /** * Message for 500 error */ @@ -637,9 +933,13 @@ export type $OpenApiTs = { put: { res: { /** - * Message for default response + * Message for 200 response */ - 200: ModelWithString; + 200: { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; + }; /** * Message for 201 response */ @@ -648,6 +948,10 @@ export type $OpenApiTs = { * Message for 202 response */ 202: ModelThatExtendsExtends; + /** + * Message for default response + */ + default: ModelWithString; /** * Message for 500 error */ diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3/services.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3/services.gen.ts.snap index 3f671329f..35ccb0463 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3/services.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3/services.gen.ts.snap @@ -3,7 +3,7 @@ import type { CancelablePromise } from './core/CancelablePromise'; import { OpenAPI } from './core/OpenAPI'; import { request as __request } from './core/request'; -import type { $OpenApiTs } from './types.gen'; +import type { DefaultPostServiceWithEmptyTagData, DefaultPostServiceWithEmptyTagResponse, SimpleApiVversionOdataControllerCountResponse, ParametersDeleteFooData, ParametersCallWithParametersData, ParametersCallWithWeirdParameterNamesData, ParametersGetCallWithOptionalParamData, ParametersPostCallWithOptionalParamData, DescriptionsCallWithDescriptionsData, DeprecatedDeprecatedCallData, RequestBodyPostApiRequestBodyData, FormDataPostApiFormDataData, DefaultsCallWithDefaultParametersData, DefaultsCallWithDefaultOptionalParametersData, DefaultsCallToTestOrderOfParamsData, NoContentCallWithNoContentResponseResponse, NoContentCallWithResponseAndNoContentResponseResponse, ResponseCallWithResponseAndNoContentResponseResponse, ResponseCallWithResponseResponse, ResponseCallWithDuplicateResponsesResponse, ResponseCallWithResponsesResponse, MultipleTags1DummyAResponse, MultipleTags1DummyBResponse, MultipleTags2DummyAResponse, MultipleTags2DummyBResponse, MultipleTags3DummyBResponse, CollectionFormatCollectionFormatData, TypesTypesData, TypesTypesResponse, UploadUploadFileData, UploadUploadFileResponse, FileResponseFileResponseData, FileResponseFileResponseResponse, ComplexComplexTypesData, ComplexComplexTypesResponse, ComplexComplexParamsData, ComplexComplexParamsResponse, MultipartMultipartRequestData, MultipartMultipartResponseResponse, HeaderCallWithResultFromHeaderResponse, ErrorTestErrorCodeData, ErrorTestErrorCodeResponse, NonAsciiÆøåÆøÅöôêÊNonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiÆøåÆøÅöôêÊNonAsciiæøåÆøÅöôêÊ字符串Response } from './types.gen'; export class DefaultService { /** @@ -22,7 +22,7 @@ export class DefaultService { * @returns ModelWithReadOnlyAndWriteOnly * @throws ApiError */ - public static postServiceWithEmptyTag(data: $OpenApiTs['/api/v{api-version}/no-tag']['post']['req']): CancelablePromise<$OpenApiTs['/api/v{api-version}/no-tag']['post']['res'][200]> { + public static postServiceWithEmptyTag(data: DefaultPostServiceWithEmptyTagData): CancelablePromise { return __request(OpenAPI, { method: 'POST', url: '/api/v{api-version}/no-tag', @@ -38,7 +38,7 @@ export class SimpleService { * @returns Model_From_Zendesk Success * @throws ApiError */ - public static apiVVersionOdataControllerCount(): CancelablePromise<$OpenApiTs['/api/v{api-version}/simple/$count']['get']['res'][200]> { + public static apiVVersionOdataControllerCount(): CancelablePromise { return __request(OpenAPI, { method: 'GET', url: '/api/v{api-version}/simple/$count' @@ -124,7 +124,7 @@ export class ParametersService { * @param data.bar bar in method * @throws ApiError */ - public static deleteFoo(data: $OpenApiTs['/api/v{api-version}/foo/{foo}/bar/{bar}']['delete']['req']): CancelablePromise { + public static deleteFoo(data: ParametersDeleteFooData): CancelablePromise { return __request(OpenAPI, { method: 'DELETE', url: '/api/v{api-version}/foo/{foo}/bar/{bar}', @@ -147,7 +147,7 @@ export class ParametersService { * @param data.fooRefEnum * @throws ApiError */ - public static callWithParameters(data: $OpenApiTs['/api/v{api-version}/parameters/{parameterPath}']['post']['req']): CancelablePromise { + public static callWithParameters(data: ParametersCallWithParametersData): CancelablePromise { return __request(OpenAPI, { method: 'POST', url: '/api/v{api-version}/parameters/{parameterPath}', @@ -186,7 +186,7 @@ export class ParametersService { * @param data._default This is the parameter with a reserved keyword * @throws ApiError */ - public static callWithWeirdParameterNames(data: $OpenApiTs['/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}']['post']['req']): CancelablePromise { + public static callWithWeirdParameterNames(data: ParametersCallWithWeirdParameterNamesData): CancelablePromise { return __request(OpenAPI, { method: 'POST', url: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}', @@ -219,7 +219,7 @@ export class ParametersService { * @param data.parameter This is an optional parameter * @throws ApiError */ - public static getCallWithOptionalParam(data: $OpenApiTs['/api/v{api-version}/parameters/']['get']['req']): CancelablePromise { + public static getCallWithOptionalParam(data: ParametersGetCallWithOptionalParamData): CancelablePromise { return __request(OpenAPI, { method: 'GET', url: '/api/v{api-version}/parameters/', @@ -237,7 +237,7 @@ export class ParametersService { * @param data.requestBody This is an optional parameter * @throws ApiError */ - public static postCallWithOptionalParam(data: $OpenApiTs['/api/v{api-version}/parameters/']['post']['req']): CancelablePromise { + public static postCallWithOptionalParam(data: ParametersPostCallWithOptionalParamData): CancelablePromise { return __request(OpenAPI, { method: 'POST', url: '/api/v{api-version}/parameters/', @@ -265,7 +265,7 @@ export class DescriptionsService { * @param data.parameterWithReservedCharacters Testing reserved characters in string: * inline * and ** inline ** should work * @throws ApiError */ - public static callWithDescriptions(data: $OpenApiTs['/api/v{api-version}/descriptions/']['post']['req'] = {}): CancelablePromise { + public static callWithDescriptions(data: DescriptionsCallWithDescriptionsData = {}): CancelablePromise { return __request(OpenAPI, { method: 'POST', url: '/api/v{api-version}/descriptions/', @@ -289,7 +289,7 @@ export class DeprecatedService { * @param data.parameter This parameter is deprecated * @throws ApiError */ - public static deprecatedCall(data: $OpenApiTs['/api/v{api-version}/parameters/deprecated']['post']['req']): CancelablePromise { + public static deprecatedCall(data: DeprecatedDeprecatedCallData): CancelablePromise { return __request(OpenAPI, { method: 'POST', url: '/api/v{api-version}/parameters/deprecated', @@ -308,7 +308,7 @@ export class RequestBodyService { * @param data.foo A reusable request body * @throws ApiError */ - public static postApiRequestBody(data: $OpenApiTs['/api/v{api-version}/requestBody/']['post']['req'] = {}): CancelablePromise { + public static postApiRequestBody(data: RequestBodyPostApiRequestBodyData = {}): CancelablePromise { return __request(OpenAPI, { method: 'POST', url: '/api/v{api-version}/requestBody/', @@ -329,7 +329,7 @@ export class FormDataService { * @param data.formData A reusable request body * @throws ApiError */ - public static postApiFormData(data: $OpenApiTs['/api/v{api-version}/formData/']['post']['req'] = {}): CancelablePromise { + public static postApiFormData(data: FormDataPostApiFormDataData = {}): CancelablePromise { return __request(OpenAPI, { method: 'POST', url: '/api/v{api-version}/formData/', @@ -353,7 +353,7 @@ export class DefaultsService { * @param data.parameterModel This is a simple model with default value * @throws ApiError */ - public static callWithDefaultParameters(data: $OpenApiTs['/api/v{api-version}/defaults']['get']['req'] = {}): CancelablePromise { + public static callWithDefaultParameters(data: DefaultsCallWithDefaultParametersData = {}): CancelablePromise { return __request(OpenAPI, { method: 'GET', url: '/api/v{api-version}/defaults', @@ -376,7 +376,7 @@ export class DefaultsService { * @param data.parameterModel This is a simple model that is optional with default value * @throws ApiError */ - public static callWithDefaultOptionalParameters(data: $OpenApiTs['/api/v{api-version}/defaults']['post']['req'] = {}): CancelablePromise { + public static callWithDefaultOptionalParameters(data: DefaultsCallWithDefaultOptionalParametersData = {}): CancelablePromise { return __request(OpenAPI, { method: 'POST', url: '/api/v{api-version}/defaults', @@ -402,7 +402,7 @@ export class DefaultsService { * @param data.parameterStringNullableWithDefault This is a string that can be null with default * @throws ApiError */ - public static callToTestOrderOfParams(data: $OpenApiTs['/api/v{api-version}/defaults']['put']['req']): CancelablePromise { + public static callToTestOrderOfParams(data: DefaultsCallToTestOrderOfParamsData): CancelablePromise { return __request(OpenAPI, { method: 'PUT', url: '/api/v{api-version}/defaults', @@ -469,7 +469,7 @@ export class NoContentService { * @returns void Success * @throws ApiError */ - public static callWithNoContentResponse(): CancelablePromise<$OpenApiTs['/api/v{api-version}/no-content']['get']['res'][204]> { + public static callWithNoContentResponse(): CancelablePromise { return __request(OpenAPI, { method: 'GET', url: '/api/v{api-version}/no-content' @@ -481,7 +481,7 @@ export class NoContentService { * @returns void Success * @throws ApiError */ - public static callWithResponseAndNoContentResponse(): CancelablePromise<$OpenApiTs['/api/v{api-version}/multiple-tags/response-and-no-content']['get']['res'][200] | $OpenApiTs['/api/v{api-version}/multiple-tags/response-and-no-content']['get']['res'][204]> { + public static callWithResponseAndNoContentResponse(): CancelablePromise { return __request(OpenAPI, { method: 'GET', url: '/api/v{api-version}/multiple-tags/response-and-no-content' @@ -496,7 +496,7 @@ export class ResponseService { * @returns void Success * @throws ApiError */ - public static callWithResponseAndNoContentResponse(): CancelablePromise<$OpenApiTs['/api/v{api-version}/multiple-tags/response-and-no-content']['get']['res'][200] | $OpenApiTs['/api/v{api-version}/multiple-tags/response-and-no-content']['get']['res'][204]> { + public static callWithResponseAndNoContentResponse(): CancelablePromise { return __request(OpenAPI, { method: 'GET', url: '/api/v{api-version}/multiple-tags/response-and-no-content' @@ -507,7 +507,7 @@ export class ResponseService { * @returns ModelWithString * @throws ApiError */ - public static callWithResponse(): CancelablePromise<$OpenApiTs['/api/v{api-version}/response']['get']['res'][200]> { + public static callWithResponse(): CancelablePromise { return __request(OpenAPI, { method: 'GET', url: '/api/v{api-version}/response' @@ -515,10 +515,10 @@ export class ResponseService { } /** - * @returns ModelWithString Message for default response + * @returns ModelWithString Message for 201 response * @throws ApiError */ - public static callWithDuplicateResponses(): CancelablePromise<$OpenApiTs['/api/v{api-version}/response']['post']['res'][200]> { + public static callWithDuplicateResponses(): CancelablePromise { return __request(OpenAPI, { method: 'POST', url: '/api/v{api-version}/response', @@ -532,12 +532,12 @@ export class ResponseService { /** * @returns unknown Message for 200 response - * @returns ModelWithString Message for default response * @returns ModelThatExtends Message for 201 response * @returns ModelThatExtendsExtends Message for 202 response + * @returns ModelWithString Message for default response * @throws ApiError */ - public static callWithResponses(): CancelablePromise<$OpenApiTs['/api/v{api-version}/response']['put']['res'][200] | $OpenApiTs['/api/v{api-version}/response']['put']['res'][200] | $OpenApiTs['/api/v{api-version}/response']['put']['res'][201] | $OpenApiTs['/api/v{api-version}/response']['put']['res'][202]> { + public static callWithResponses(): CancelablePromise { return __request(OpenAPI, { method: 'PUT', url: '/api/v{api-version}/response', @@ -556,7 +556,7 @@ export class MultipleTags1Service { * @returns void Success * @throws ApiError */ - public static dummyA(): CancelablePromise<$OpenApiTs['/api/v{api-version}/multiple-tags/a']['get']['res'][204]> { + public static dummyA(): CancelablePromise { return __request(OpenAPI, { method: 'GET', url: '/api/v{api-version}/multiple-tags/a' @@ -567,7 +567,7 @@ export class MultipleTags1Service { * @returns void Success * @throws ApiError */ - public static dummyB(): CancelablePromise<$OpenApiTs['/api/v{api-version}/multiple-tags/b']['get']['res'][204]> { + public static dummyB(): CancelablePromise { return __request(OpenAPI, { method: 'GET', url: '/api/v{api-version}/multiple-tags/b' @@ -581,7 +581,7 @@ export class MultipleTags2Service { * @returns void Success * @throws ApiError */ - public static dummyA(): CancelablePromise<$OpenApiTs['/api/v{api-version}/multiple-tags/a']['get']['res'][204]> { + public static dummyA(): CancelablePromise { return __request(OpenAPI, { method: 'GET', url: '/api/v{api-version}/multiple-tags/a' @@ -592,7 +592,7 @@ export class MultipleTags2Service { * @returns void Success * @throws ApiError */ - public static dummyB(): CancelablePromise<$OpenApiTs['/api/v{api-version}/multiple-tags/b']['get']['res'][204]> { + public static dummyB(): CancelablePromise { return __request(OpenAPI, { method: 'GET', url: '/api/v{api-version}/multiple-tags/b' @@ -606,7 +606,7 @@ export class MultipleTags3Service { * @returns void Success * @throws ApiError */ - public static dummyB(): CancelablePromise<$OpenApiTs['/api/v{api-version}/multiple-tags/b']['get']['res'][204]> { + public static dummyB(): CancelablePromise { return __request(OpenAPI, { method: 'GET', url: '/api/v{api-version}/multiple-tags/b' @@ -625,7 +625,7 @@ export class CollectionFormatService { * @param data.parameterArrayMulti This is an array parameter that is sent as multi format (multiple parameter instances) * @throws ApiError */ - public static collectionFormat(data: $OpenApiTs['/api/v{api-version}/collectionFormat']['get']['req']): CancelablePromise { + public static collectionFormat(data: CollectionFormatCollectionFormatData): CancelablePromise { return __request(OpenAPI, { method: 'GET', url: '/api/v{api-version}/collectionFormat', @@ -658,7 +658,7 @@ export class TypesService { * @returns unknown Response is a simple object * @throws ApiError */ - public static types(data: $OpenApiTs['/api/v{api-version}/types']['get']['req']): CancelablePromise<$OpenApiTs['/api/v{api-version}/types']['get']['res'][200] | $OpenApiTs['/api/v{api-version}/types']['get']['res'][201] | $OpenApiTs['/api/v{api-version}/types']['get']['res'][202] | $OpenApiTs['/api/v{api-version}/types']['get']['res'][203]> { + public static types(data: TypesTypesData): CancelablePromise { return __request(OpenAPI, { method: 'GET', url: '/api/v{api-version}/types', @@ -686,7 +686,7 @@ export class UploadService { * @returns boolean * @throws ApiError */ - public static uploadFile(data: $OpenApiTs['/api/v{api-version}/upload']['post']['req']): CancelablePromise<$OpenApiTs['/api/v{api-version}/upload']['post']['res'][200]> { + public static uploadFile(data: UploadUploadFileData): CancelablePromise { return __request(OpenAPI, { method: 'POST', url: '/api/v{api-version}/upload', @@ -705,7 +705,7 @@ export class FileResponseService { * @returns binary Success * @throws ApiError */ - public static fileResponse(data: $OpenApiTs['/api/v{api-version}/file/{id}']['get']['req']): CancelablePromise<$OpenApiTs['/api/v{api-version}/file/{id}']['get']['res'][200]> { + public static fileResponse(data: FileResponseFileResponseData): CancelablePromise { return __request(OpenAPI, { method: 'GET', url: '/api/v{api-version}/file/{id}', @@ -725,7 +725,7 @@ export class ComplexService { * @returns ModelWithString Successful response * @throws ApiError */ - public static complexTypes(data: $OpenApiTs['/api/v{api-version}/complex']['get']['req']): CancelablePromise<$OpenApiTs['/api/v{api-version}/complex']['get']['res'][200]> { + public static complexTypes(data: ComplexComplexTypesData): CancelablePromise { return __request(OpenAPI, { method: 'GET', url: '/api/v{api-version}/complex', @@ -747,7 +747,7 @@ export class ComplexService { * @returns ModelWithString Success * @throws ApiError */ - public static complexParams(data: $OpenApiTs['/api/v{api-version}/complex/{id}']['put']['req']): CancelablePromise<$OpenApiTs['/api/v{api-version}/complex/{id}']['put']['res'][200]> { + public static complexParams(data: ComplexComplexParamsData): CancelablePromise { return __request(OpenAPI, { method: 'PUT', url: '/api/v{api-version}/complex/{id}', @@ -767,7 +767,7 @@ export class MultipartService { * @param data.formData * @throws ApiError */ - public static multipartRequest(data: $OpenApiTs['/api/v{api-version}/multipart']['post']['req'] = {}): CancelablePromise { + public static multipartRequest(data: MultipartMultipartRequestData = {}): CancelablePromise { return __request(OpenAPI, { method: 'POST', url: '/api/v{api-version}/multipart', @@ -780,7 +780,7 @@ export class MultipartService { * @returns unknown OK * @throws ApiError */ - public static multipartResponse(): CancelablePromise<$OpenApiTs['/api/v{api-version}/multipart']['get']['res'][200]> { + public static multipartResponse(): CancelablePromise { return __request(OpenAPI, { method: 'GET', url: '/api/v{api-version}/multipart' @@ -794,7 +794,7 @@ export class HeaderService { * @returns string Successful response * @throws ApiError */ - public static callWithResultFromHeader(): CancelablePromise<$OpenApiTs['/api/v{api-version}/header']['post']['res'][200]> { + public static callWithResultFromHeader(): CancelablePromise { return __request(OpenAPI, { method: 'POST', url: '/api/v{api-version}/header', @@ -815,7 +815,7 @@ export class ErrorService { * @returns unknown Custom message: Successful response * @throws ApiError */ - public static testErrorCode(data: $OpenApiTs['/api/v{api-version}/error']['post']['req']): CancelablePromise<$OpenApiTs['/api/v{api-version}/error']['post']['res'][200]> { + public static testErrorCode(data: ErrorTestErrorCodeData): CancelablePromise { return __request(OpenAPI, { method: 'POST', url: '/api/v{api-version}/error', @@ -840,7 +840,7 @@ export class NonAsciiÆøåÆøÅöôêÊService { * @returns NonAsciiStringæøåÆØÅöôêÊ字符串 Successful response * @throws ApiError */ - public static nonAsciiæøåÆøÅöôêÊ字符串(data: $OpenApiTs['/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串']['post']['req']): CancelablePromise<$OpenApiTs['/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串']['post']['res'][200]> { + public static nonAsciiæøåÆøÅöôêÊ字符串(data: NonAsciiÆøåÆøÅöôêÊNonAsciiæøåÆøÅöôêÊ字符串Data): CancelablePromise { return __request(OpenAPI, { method: 'POST', url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串', diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3/types.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3/types.gen.ts.snap index 5df8aa391..8f051c403 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3/types.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3/types.gen.ts.snap @@ -839,6 +839,436 @@ export type SimpleParameter = string; */ export type x_Foo_Bar = string; +export type DefaultPostServiceWithEmptyTagData = { + requestBody: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; +}; + +export type DefaultPostServiceWithEmptyTagResponse = ModelWithReadOnlyAndWriteOnly; + +export type SimpleApiVversionOdataControllerCountResponse = Model_From_Zendesk; + +export type ParametersDeleteFooData = { + /** + * bar in method + */ + bar: string; + /** + * foo in method + */ + foo: string; +}; + +export type ParametersCallWithParametersData = { + fooAllOfEnum: ModelWithNestedArrayEnumsDataFoo; + fooRefEnum?: ModelWithNestedArrayEnumsDataFoo; + /** + * This is the parameter that goes into the cookie + */ + parameterCookie: string | null; + /** + * This is the parameter that goes into the form data + */ + parameterForm: string | null; + /** + * This is the parameter that goes into the header + */ + parameterHeader: string | null; + /** + * This is the parameter that goes into the path + */ + parameterPath: string | null; + /** + * This is the parameter that goes into the query params + */ + parameterQuery: string | null; + /** + * This is the parameter that goes into the body + */ + requestBody: ModelWithString | null; +}; + +export type ParametersCallWithWeirdParameterNamesData = { + /** + * This is the parameter with a reserved keyword + */ + _default?: string; + /** + * This is the parameter that goes into the cookie + */ + parameterCookie: string | null; + /** + * This is the parameter that goes into the request form data + */ + parameterForm: string | null; + /** + * This is the parameter that goes into the request header + */ + parameterHeader: string | null; + /** + * This is the parameter that goes into the path + */ + parameterPath1?: string; + /** + * This is the parameter that goes into the path + */ + parameterPath2?: string; + /** + * This is the parameter that goes into the path + */ + parameterPath3?: string; + /** + * This is the parameter that goes into the request query params + */ + parameterQuery: string | null; + /** + * This is the parameter that goes into the body + */ + requestBody: ModelWithString | null; +}; + +export type ParametersGetCallWithOptionalParamData = { + /** + * This is an optional parameter + */ + parameter?: string; + /** + * This is a required parameter + */ + requestBody: ModelWithOneOfEnum; +}; + +export type ParametersPostCallWithOptionalParamData = { + /** + * This is a required parameter + */ + parameter: Pageable; + /** + * This is an optional parameter + */ + requestBody?: ModelWithString; +}; + +export type DescriptionsCallWithDescriptionsData = { + /** + * Testing backticks in string: `backticks` and ```multiple backticks``` should work + */ + parameterWithBackticks?: unknown; + /** + * Testing multiline comments in string: First line + * Second line + * + * Fourth line + */ + parameterWithBreaks?: unknown; + /** + * Testing expression placeholders in string: ${expression} should work + */ + parameterWithExpressionPlaceholders?: unknown; + /** + * Testing quotes in string: 'single quote''' and "double quotes""" should work + */ + parameterWithQuotes?: unknown; + /** + * Testing reserved characters in string: * inline * and ** inline ** should work + */ + parameterWithReservedCharacters?: unknown; + /** + * Testing slashes in string: \backwards\\\ and /forwards/// should work + */ + parameterWithSlashes?: unknown; +}; + +export type DeprecatedDeprecatedCallData = { + /** + * This parameter is deprecated + * @deprecated + */ + parameter: DeprecatedModel | null; +}; + +export type RequestBodyPostApiRequestBodyData = { + /** + * A reusable request body + */ + foo?: ModelWithString; + /** + * This is a reusable parameter + */ + parameter?: string; +}; + +export type FormDataPostApiFormDataData = { + /** + * A reusable request body + */ + formData?: ModelWithString; + /** + * This is a reusable parameter + */ + parameter?: string; +}; + +export type DefaultsCallWithDefaultParametersData = { + /** + * This is a simple boolean with default value + */ + parameterBoolean?: boolean | null; + /** + * This is a simple enum with default value + */ + parameterEnum?: 'Success' | 'Warning' | 'Error'; + /** + * This is a simple model with default value + */ + parameterModel?: ModelWithString | null; + /** + * This is a simple number with default value + */ + parameterNumber?: number | null; + /** + * This is a simple string with default value + */ + parameterString?: string | null; +}; + +export type DefaultsCallWithDefaultOptionalParametersData = { + /** + * This is a simple boolean that is optional with default value + */ + parameterBoolean?: boolean; + /** + * This is a simple enum that is optional with default value + */ + parameterEnum?: 'Success' | 'Warning' | 'Error'; + /** + * This is a simple model that is optional with default value + */ + parameterModel?: ModelWithString; + /** + * This is a simple number that is optional with default value + */ + parameterNumber?: number; + /** + * This is a simple string that is optional with default value + */ + parameterString?: string; +}; + +export type DefaultsCallToTestOrderOfParamsData = { + /** + * This is a optional string with default + */ + parameterOptionalStringWithDefault?: string; + /** + * This is a optional string with empty default + */ + parameterOptionalStringWithEmptyDefault?: string; + /** + * This is a optional string with no default + */ + parameterOptionalStringWithNoDefault?: string; + /** + * This is a string that can be null with default + */ + parameterStringNullableWithDefault?: string | null; + /** + * This is a string that can be null with no default + */ + parameterStringNullableWithNoDefault?: string | null; + /** + * This is a string with default + */ + parameterStringWithDefault: string; + /** + * This is a string with empty default + */ + parameterStringWithEmptyDefault: string; + /** + * This is a string with no default + */ + parameterStringWithNoDefault: string; +}; + +export type NoContentCallWithNoContentResponseResponse = void; + +export type NoContentCallWithResponseAndNoContentResponseResponse = number | void; + +export type ResponseCallWithResponseAndNoContentResponseResponse = number | void; + +export type ResponseCallWithResponseResponse = ModelWithString; + +export type ResponseCallWithDuplicateResponsesResponse = ModelWithString; + +export type ResponseCallWithResponsesResponse = { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; +} | ModelThatExtends | ModelThatExtendsExtends | ModelWithString; + +export type MultipleTags1DummyAResponse = void; + +export type MultipleTags1DummyBResponse = void; + +export type MultipleTags2DummyAResponse = void; + +export type MultipleTags2DummyBResponse = void; + +export type MultipleTags3DummyBResponse = void; + +export type CollectionFormatCollectionFormatData = { + /** + * This is an array parameter that is sent as csv format (comma-separated values) + */ + parameterArrayCsv: Array<(string)> | null; + /** + * This is an array parameter that is sent as multi format (multiple parameter instances) + */ + parameterArrayMulti: Array<(string)> | null; + /** + * This is an array parameter that is sent as pipes format (pipe-separated values) + */ + parameterArrayPipes: Array<(string)> | null; + /** + * This is an array parameter that is sent as ssv format (space-separated values) + */ + parameterArraySsv: Array<(string)> | null; + /** + * This is an array parameter that is sent as tsv format (tab-separated values) + */ + parameterArrayTsv: Array<(string)> | null; +}; + +export type TypesTypesData = { + /** + * This is a number parameter + */ + id?: number; + /** + * This is an array parameter + */ + parameterArray: Array<(string)> | null; + /** + * This is a boolean parameter + */ + parameterBoolean: boolean | null; + /** + * This is a dictionary parameter + */ + parameterDictionary: { + [key: string]: unknown; + } | null; + /** + * This is an enum parameter + */ + parameterEnum: 'Success' | 'Warning' | 'Error' | null; + /** + * This is a number parameter + */ + parameterNumber: number; + /** + * This is an object parameter + */ + parameterObject: { + [key: string]: unknown; + } | null; + /** + * This is a string parameter + */ + parameterString: string | null; +}; + +export type TypesTypesResponse = number | string | boolean | { + [key: string]: unknown; +}; + +export type UploadUploadFileData = { + /** + * Supply a file reference for upload + */ + file: (Blob | File); +}; + +export type UploadUploadFileResponse = boolean; + +export type FileResponseFileResponseData = { + id: string; +}; + +export type FileResponseFileResponseResponse = (Blob | File); + +export type ComplexComplexTypesData = { + /** + * Parameter containing object + */ + parameterObject: { + first?: { + second?: { + third?: string; + }; + }; + }; + /** + * Parameter containing reference + */ + parameterReference: ModelWithString; +}; + +export type ComplexComplexTypesResponse = Array; + +export type ComplexComplexParamsData = { + id: number; + requestBody?: { + readonly key: string | null; + name: string | null; + enabled?: boolean; + readonly type: 'Monkey' | 'Horse' | 'Bird'; + listOfModels?: Array | null; + listOfStrings?: Array<(string)> | null; + parameters: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; + readonly user?: { + readonly id?: number; + readonly name?: string | null; + }; + }; +}; + +export type ComplexComplexParamsResponse = ModelWithString; + +export type MultipartMultipartRequestData = { + formData?: { + content?: (Blob | File); + data?: ModelWithString | null; + }; +}; + +export type MultipartMultipartResponseResponse = { + file?: (Blob | File); + metadata?: { + foo?: string; + bar?: string; + }; +}; + +export type HeaderCallWithResultFromHeaderResponse = string; + +export type ErrorTestErrorCodeData = { + /** + * Status code to return + */ + status: number; +}; + +export type ErrorTestErrorCodeResponse = unknown; + +export type NonAsciiÆøåÆøÅöôêÊNonAsciiæøåÆøÅöôêÊ字符串Data = { + /** + * Dummy input param + */ + nonAsciiParamæøåÆøÅöôêÊ: number; +}; + +export type NonAsciiÆøåÆøÅöôêÊNonAsciiæøåÆøÅöôêÊ字符串Response = Array; + export type $OpenApiTs = { '/api/v{api-version}/no-tag': { post: { @@ -846,7 +1276,7 @@ export type $OpenApiTs = { requestBody: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; }; res: { - 200: ModelWithReadOnlyAndWriteOnly; + default: ModelWithReadOnlyAndWriteOnly; }; }; }; @@ -1159,15 +1589,15 @@ export type $OpenApiTs = { '/api/v{api-version}/response': { get: { res: { - 200: ModelWithString; + default: ModelWithString; }; }; post: { res: { /** - * Message for default response + * Message for 201 response */ - 200: ModelWithString; + 201: ModelWithString; /** * Message for 500 error */ @@ -1185,9 +1615,13 @@ export type $OpenApiTs = { put: { res: { /** - * Message for default response + * Message for 200 response */ - 200: ModelWithString; + 200: { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; + }; /** * Message for 201 response */ @@ -1196,6 +1630,10 @@ export type $OpenApiTs = { * Message for 202 response */ 202: ModelThatExtendsExtends; + /** + * Message for default response + */ + default: ModelWithString; /** * Message for 500 error */ diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/services.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/services.gen.ts.snap index 9717503b0..c672ae0be 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/services.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/services.gen.ts.snap @@ -5,7 +5,7 @@ import { HttpClient } from '@angular/common/http'; import type { Observable } from 'rxjs'; import { OpenAPI } from './core/OpenAPI'; import { request as __request } from './core/request'; -import type { $OpenApiTs } from './types.gen'; +import type { DefaultPostServiceWithEmptyTagData, DefaultPostServiceWithEmptyTagResponse, SimpleApiVversionOdataControllerCountResponse, ParametersDeleteFooData, ParametersCallWithParametersData, ParametersCallWithWeirdParameterNamesData, ParametersGetCallWithOptionalParamData, ParametersPostCallWithOptionalParamData, DescriptionsCallWithDescriptionsData, DeprecatedDeprecatedCallData, RequestBodyPostApiRequestBodyData, FormDataPostApiFormDataData, DefaultsCallWithDefaultParametersData, DefaultsCallWithDefaultOptionalParametersData, DefaultsCallToTestOrderOfParamsData, NoContentCallWithNoContentResponseResponse, NoContentCallWithResponseAndNoContentResponseResponse, ResponseCallWithResponseAndNoContentResponseResponse, ResponseCallWithResponseResponse, ResponseCallWithDuplicateResponsesResponse, ResponseCallWithResponsesResponse, MultipleTags1DummyAResponse, MultipleTags1DummyBResponse, MultipleTags2DummyAResponse, MultipleTags2DummyBResponse, MultipleTags3DummyBResponse, CollectionFormatCollectionFormatData, TypesTypesData, TypesTypesResponse, UploadUploadFileData, UploadUploadFileResponse, FileResponseFileResponseData, FileResponseFileResponseResponse, ComplexComplexTypesData, ComplexComplexTypesResponse, ComplexComplexParamsData, ComplexComplexParamsResponse, MultipartMultipartRequestData, MultipartMultipartResponseResponse, HeaderCallWithResultFromHeaderResponse, ErrorTestErrorCodeData, ErrorTestErrorCodeResponse, NonAsciiÆøåÆøÅöôêÊNonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiÆøåÆøÅöôêÊNonAsciiæøåÆøÅöôêÊ字符串Response } from './types.gen'; @Injectable({ providedIn: 'root' @@ -29,7 +29,7 @@ export class DefaultService { * @returns ModelWithReadOnlyAndWriteOnly * @throws ApiError */ - public postServiceWithEmptyTag(data: $OpenApiTs['/api/v{api-version}/no-tag']['post']['req']): Observable<$OpenApiTs['/api/v{api-version}/no-tag']['post']['res'][200]> { + public postServiceWithEmptyTag(data: DefaultPostServiceWithEmptyTagData): Observable { return __request(OpenAPI, this.http, { method: 'POST', url: '/api/v{api-version}/no-tag', @@ -50,7 +50,7 @@ export class SimpleService { * @returns Model_From_Zendesk Success * @throws ApiError */ - public apiVVersionOdataControllerCount(): Observable<$OpenApiTs['/api/v{api-version}/simple/$count']['get']['res'][200]> { + public apiVVersionOdataControllerCount(): Observable { return __request(OpenAPI, this.http, { method: 'GET', url: '/api/v{api-version}/simple/$count' @@ -141,7 +141,7 @@ export class ParametersService { * @param data.bar bar in method * @throws ApiError */ - public deleteFoo(data: $OpenApiTs['/api/v{api-version}/foo/{foo}/bar/{bar}']['delete']['req']): Observable { + public deleteFoo(data: ParametersDeleteFooData): Observable { return __request(OpenAPI, this.http, { method: 'DELETE', url: '/api/v{api-version}/foo/{foo}/bar/{bar}', @@ -164,7 +164,7 @@ export class ParametersService { * @param data.fooRefEnum * @throws ApiError */ - public callWithParameters(data: $OpenApiTs['/api/v{api-version}/parameters/{parameterPath}']['post']['req']): Observable { + public callWithParameters(data: ParametersCallWithParametersData): Observable { return __request(OpenAPI, this.http, { method: 'POST', url: '/api/v{api-version}/parameters/{parameterPath}', @@ -203,7 +203,7 @@ export class ParametersService { * @param data._default This is the parameter with a reserved keyword * @throws ApiError */ - public callWithWeirdParameterNames(data: $OpenApiTs['/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}']['post']['req']): Observable { + public callWithWeirdParameterNames(data: ParametersCallWithWeirdParameterNamesData): Observable { return __request(OpenAPI, this.http, { method: 'POST', url: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}', @@ -236,7 +236,7 @@ export class ParametersService { * @param data.parameter This is an optional parameter * @throws ApiError */ - public getCallWithOptionalParam(data: $OpenApiTs['/api/v{api-version}/parameters/']['get']['req']): Observable { + public getCallWithOptionalParam(data: ParametersGetCallWithOptionalParamData): Observable { return __request(OpenAPI, this.http, { method: 'GET', url: '/api/v{api-version}/parameters/', @@ -254,7 +254,7 @@ export class ParametersService { * @param data.requestBody This is an optional parameter * @throws ApiError */ - public postCallWithOptionalParam(data: $OpenApiTs['/api/v{api-version}/parameters/']['post']['req']): Observable { + public postCallWithOptionalParam(data: ParametersPostCallWithOptionalParamData): Observable { return __request(OpenAPI, this.http, { method: 'POST', url: '/api/v{api-version}/parameters/', @@ -287,7 +287,7 @@ export class DescriptionsService { * @param data.parameterWithReservedCharacters Testing reserved characters in string: * inline * and ** inline ** should work * @throws ApiError */ - public callWithDescriptions(data: $OpenApiTs['/api/v{api-version}/descriptions/']['post']['req'] = {}): Observable { + public callWithDescriptions(data: DescriptionsCallWithDescriptionsData = {}): Observable { return __request(OpenAPI, this.http, { method: 'POST', url: '/api/v{api-version}/descriptions/', @@ -316,7 +316,7 @@ export class DeprecatedService { * @param data.parameter This parameter is deprecated * @throws ApiError */ - public deprecatedCall(data: $OpenApiTs['/api/v{api-version}/parameters/deprecated']['post']['req']): Observable { + public deprecatedCall(data: DeprecatedDeprecatedCallData): Observable { return __request(OpenAPI, this.http, { method: 'POST', url: '/api/v{api-version}/parameters/deprecated', @@ -340,7 +340,7 @@ export class RequestBodyService { * @param data.foo A reusable request body * @throws ApiError */ - public postApiRequestBody(data: $OpenApiTs['/api/v{api-version}/requestBody/']['post']['req'] = {}): Observable { + public postApiRequestBody(data: RequestBodyPostApiRequestBodyData = {}): Observable { return __request(OpenAPI, this.http, { method: 'POST', url: '/api/v{api-version}/requestBody/', @@ -366,7 +366,7 @@ export class FormDataService { * @param data.formData A reusable request body * @throws ApiError */ - public postApiFormData(data: $OpenApiTs['/api/v{api-version}/formData/']['post']['req'] = {}): Observable { + public postApiFormData(data: FormDataPostApiFormDataData = {}): Observable { return __request(OpenAPI, this.http, { method: 'POST', url: '/api/v{api-version}/formData/', @@ -395,7 +395,7 @@ export class DefaultsService { * @param data.parameterModel This is a simple model with default value * @throws ApiError */ - public callWithDefaultParameters(data: $OpenApiTs['/api/v{api-version}/defaults']['get']['req'] = {}): Observable { + public callWithDefaultParameters(data: DefaultsCallWithDefaultParametersData = {}): Observable { return __request(OpenAPI, this.http, { method: 'GET', url: '/api/v{api-version}/defaults', @@ -418,7 +418,7 @@ export class DefaultsService { * @param data.parameterModel This is a simple model that is optional with default value * @throws ApiError */ - public callWithDefaultOptionalParameters(data: $OpenApiTs['/api/v{api-version}/defaults']['post']['req'] = {}): Observable { + public callWithDefaultOptionalParameters(data: DefaultsCallWithDefaultOptionalParametersData = {}): Observable { return __request(OpenAPI, this.http, { method: 'POST', url: '/api/v{api-version}/defaults', @@ -444,7 +444,7 @@ export class DefaultsService { * @param data.parameterStringNullableWithDefault This is a string that can be null with default * @throws ApiError */ - public callToTestOrderOfParams(data: $OpenApiTs['/api/v{api-version}/defaults']['put']['req']): Observable { + public callToTestOrderOfParams(data: DefaultsCallToTestOrderOfParamsData): Observable { return __request(OpenAPI, this.http, { method: 'PUT', url: '/api/v{api-version}/defaults', @@ -521,7 +521,7 @@ export class NoContentService { * @returns void Success * @throws ApiError */ - public callWithNoContentResponse(): Observable<$OpenApiTs['/api/v{api-version}/no-content']['get']['res'][204]> { + public callWithNoContentResponse(): Observable { return __request(OpenAPI, this.http, { method: 'GET', url: '/api/v{api-version}/no-content' @@ -533,7 +533,7 @@ export class NoContentService { * @returns void Success * @throws ApiError */ - public callWithResponseAndNoContentResponse(): Observable<$OpenApiTs['/api/v{api-version}/multiple-tags/response-and-no-content']['get']['res'][200] | $OpenApiTs['/api/v{api-version}/multiple-tags/response-and-no-content']['get']['res'][204]> { + public callWithResponseAndNoContentResponse(): Observable { return __request(OpenAPI, this.http, { method: 'GET', url: '/api/v{api-version}/multiple-tags/response-and-no-content' @@ -553,7 +553,7 @@ export class ResponseService { * @returns void Success * @throws ApiError */ - public callWithResponseAndNoContentResponse(): Observable<$OpenApiTs['/api/v{api-version}/multiple-tags/response-and-no-content']['get']['res'][200] | $OpenApiTs['/api/v{api-version}/multiple-tags/response-and-no-content']['get']['res'][204]> { + public callWithResponseAndNoContentResponse(): Observable { return __request(OpenAPI, this.http, { method: 'GET', url: '/api/v{api-version}/multiple-tags/response-and-no-content' @@ -564,7 +564,7 @@ export class ResponseService { * @returns ModelWithString * @throws ApiError */ - public callWithResponse(): Observable<$OpenApiTs['/api/v{api-version}/response']['get']['res'][200]> { + public callWithResponse(): Observable { return __request(OpenAPI, this.http, { method: 'GET', url: '/api/v{api-version}/response' @@ -572,10 +572,10 @@ export class ResponseService { } /** - * @returns ModelWithString Message for default response + * @returns ModelWithString Message for 201 response * @throws ApiError */ - public callWithDuplicateResponses(): Observable<$OpenApiTs['/api/v{api-version}/response']['post']['res'][200]> { + public callWithDuplicateResponses(): Observable { return __request(OpenAPI, this.http, { method: 'POST', url: '/api/v{api-version}/response', @@ -589,12 +589,12 @@ export class ResponseService { /** * @returns unknown Message for 200 response - * @returns ModelWithString Message for default response * @returns ModelThatExtends Message for 201 response * @returns ModelThatExtendsExtends Message for 202 response + * @returns ModelWithString Message for default response * @throws ApiError */ - public callWithResponses(): Observable<$OpenApiTs['/api/v{api-version}/response']['put']['res'][200] | $OpenApiTs['/api/v{api-version}/response']['put']['res'][200] | $OpenApiTs['/api/v{api-version}/response']['put']['res'][201] | $OpenApiTs['/api/v{api-version}/response']['put']['res'][202]> { + public callWithResponses(): Observable { return __request(OpenAPI, this.http, { method: 'PUT', url: '/api/v{api-version}/response', @@ -618,7 +618,7 @@ export class MultipleTags1Service { * @returns void Success * @throws ApiError */ - public dummyA(): Observable<$OpenApiTs['/api/v{api-version}/multiple-tags/a']['get']['res'][204]> { + public dummyA(): Observable { return __request(OpenAPI, this.http, { method: 'GET', url: '/api/v{api-version}/multiple-tags/a' @@ -629,7 +629,7 @@ export class MultipleTags1Service { * @returns void Success * @throws ApiError */ - public dummyB(): Observable<$OpenApiTs['/api/v{api-version}/multiple-tags/b']['get']['res'][204]> { + public dummyB(): Observable { return __request(OpenAPI, this.http, { method: 'GET', url: '/api/v{api-version}/multiple-tags/b' @@ -648,7 +648,7 @@ export class MultipleTags2Service { * @returns void Success * @throws ApiError */ - public dummyA(): Observable<$OpenApiTs['/api/v{api-version}/multiple-tags/a']['get']['res'][204]> { + public dummyA(): Observable { return __request(OpenAPI, this.http, { method: 'GET', url: '/api/v{api-version}/multiple-tags/a' @@ -659,7 +659,7 @@ export class MultipleTags2Service { * @returns void Success * @throws ApiError */ - public dummyB(): Observable<$OpenApiTs['/api/v{api-version}/multiple-tags/b']['get']['res'][204]> { + public dummyB(): Observable { return __request(OpenAPI, this.http, { method: 'GET', url: '/api/v{api-version}/multiple-tags/b' @@ -678,7 +678,7 @@ export class MultipleTags3Service { * @returns void Success * @throws ApiError */ - public dummyB(): Observable<$OpenApiTs['/api/v{api-version}/multiple-tags/b']['get']['res'][204]> { + public dummyB(): Observable { return __request(OpenAPI, this.http, { method: 'GET', url: '/api/v{api-version}/multiple-tags/b' @@ -702,7 +702,7 @@ export class CollectionFormatService { * @param data.parameterArrayMulti This is an array parameter that is sent as multi format (multiple parameter instances) * @throws ApiError */ - public collectionFormat(data: $OpenApiTs['/api/v{api-version}/collectionFormat']['get']['req']): Observable { + public collectionFormat(data: CollectionFormatCollectionFormatData): Observable { return __request(OpenAPI, this.http, { method: 'GET', url: '/api/v{api-version}/collectionFormat', @@ -740,7 +740,7 @@ export class TypesService { * @returns unknown Response is a simple object * @throws ApiError */ - public types(data: $OpenApiTs['/api/v{api-version}/types']['get']['req']): Observable<$OpenApiTs['/api/v{api-version}/types']['get']['res'][200] | $OpenApiTs['/api/v{api-version}/types']['get']['res'][201] | $OpenApiTs['/api/v{api-version}/types']['get']['res'][202] | $OpenApiTs['/api/v{api-version}/types']['get']['res'][203]> { + public types(data: TypesTypesData): Observable { return __request(OpenAPI, this.http, { method: 'GET', url: '/api/v{api-version}/types', @@ -773,7 +773,7 @@ export class UploadService { * @returns boolean * @throws ApiError */ - public uploadFile(data: $OpenApiTs['/api/v{api-version}/upload']['post']['req']): Observable<$OpenApiTs['/api/v{api-version}/upload']['post']['res'][200]> { + public uploadFile(data: UploadUploadFileData): Observable { return __request(OpenAPI, this.http, { method: 'POST', url: '/api/v{api-version}/upload', @@ -797,7 +797,7 @@ export class FileResponseService { * @returns binary Success * @throws ApiError */ - public fileResponse(data: $OpenApiTs['/api/v{api-version}/file/{id}']['get']['req']): Observable<$OpenApiTs['/api/v{api-version}/file/{id}']['get']['res'][200]> { + public fileResponse(data: FileResponseFileResponseData): Observable { return __request(OpenAPI, this.http, { method: 'GET', url: '/api/v{api-version}/file/{id}', @@ -822,7 +822,7 @@ export class ComplexService { * @returns ModelWithString Successful response * @throws ApiError */ - public complexTypes(data: $OpenApiTs['/api/v{api-version}/complex']['get']['req']): Observable<$OpenApiTs['/api/v{api-version}/complex']['get']['res'][200]> { + public complexTypes(data: ComplexComplexTypesData): Observable { return __request(OpenAPI, this.http, { method: 'GET', url: '/api/v{api-version}/complex', @@ -844,7 +844,7 @@ export class ComplexService { * @returns ModelWithString Success * @throws ApiError */ - public complexParams(data: $OpenApiTs['/api/v{api-version}/complex/{id}']['put']['req']): Observable<$OpenApiTs['/api/v{api-version}/complex/{id}']['put']['res'][200]> { + public complexParams(data: ComplexComplexParamsData): Observable { return __request(OpenAPI, this.http, { method: 'PUT', url: '/api/v{api-version}/complex/{id}', @@ -869,7 +869,7 @@ export class MultipartService { * @param data.formData * @throws ApiError */ - public multipartRequest(data: $OpenApiTs['/api/v{api-version}/multipart']['post']['req'] = {}): Observable { + public multipartRequest(data: MultipartMultipartRequestData = {}): Observable { return __request(OpenAPI, this.http, { method: 'POST', url: '/api/v{api-version}/multipart', @@ -882,7 +882,7 @@ export class MultipartService { * @returns unknown OK * @throws ApiError */ - public multipartResponse(): Observable<$OpenApiTs['/api/v{api-version}/multipart']['get']['res'][200]> { + public multipartResponse(): Observable { return __request(OpenAPI, this.http, { method: 'GET', url: '/api/v{api-version}/multipart' @@ -901,7 +901,7 @@ export class HeaderService { * @returns string Successful response * @throws ApiError */ - public callWithResultFromHeader(): Observable<$OpenApiTs['/api/v{api-version}/header']['post']['res'][200]> { + public callWithResultFromHeader(): Observable { return __request(OpenAPI, this.http, { method: 'POST', url: '/api/v{api-version}/header', @@ -927,7 +927,7 @@ export class ErrorService { * @returns unknown Custom message: Successful response * @throws ApiError */ - public testErrorCode(data: $OpenApiTs['/api/v{api-version}/error']['post']['req']): Observable<$OpenApiTs['/api/v{api-version}/error']['post']['res'][200]> { + public testErrorCode(data: ErrorTestErrorCodeData): Observable { return __request(OpenAPI, this.http, { method: 'POST', url: '/api/v{api-version}/error', @@ -957,7 +957,7 @@ export class NonAsciiÆøåÆøÅöôêÊService { * @returns NonAsciiStringæøåÆØÅöôêÊ字符串 Successful response * @throws ApiError */ - public nonAsciiæøåÆøÅöôêÊ字符串(data: $OpenApiTs['/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串']['post']['req']): Observable<$OpenApiTs['/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串']['post']['res'][200]> { + public nonAsciiæøåÆøÅöôêÊ字符串(data: NonAsciiÆøåÆøÅöôêÊNonAsciiæøåÆøÅöôêÊ字符串Data): Observable { return __request(OpenAPI, this.http, { method: 'POST', url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串', diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/types.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/types.gen.ts.snap index 5df8aa391..8f051c403 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/types.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_angular/types.gen.ts.snap @@ -839,6 +839,436 @@ export type SimpleParameter = string; */ export type x_Foo_Bar = string; +export type DefaultPostServiceWithEmptyTagData = { + requestBody: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; +}; + +export type DefaultPostServiceWithEmptyTagResponse = ModelWithReadOnlyAndWriteOnly; + +export type SimpleApiVversionOdataControllerCountResponse = Model_From_Zendesk; + +export type ParametersDeleteFooData = { + /** + * bar in method + */ + bar: string; + /** + * foo in method + */ + foo: string; +}; + +export type ParametersCallWithParametersData = { + fooAllOfEnum: ModelWithNestedArrayEnumsDataFoo; + fooRefEnum?: ModelWithNestedArrayEnumsDataFoo; + /** + * This is the parameter that goes into the cookie + */ + parameterCookie: string | null; + /** + * This is the parameter that goes into the form data + */ + parameterForm: string | null; + /** + * This is the parameter that goes into the header + */ + parameterHeader: string | null; + /** + * This is the parameter that goes into the path + */ + parameterPath: string | null; + /** + * This is the parameter that goes into the query params + */ + parameterQuery: string | null; + /** + * This is the parameter that goes into the body + */ + requestBody: ModelWithString | null; +}; + +export type ParametersCallWithWeirdParameterNamesData = { + /** + * This is the parameter with a reserved keyword + */ + _default?: string; + /** + * This is the parameter that goes into the cookie + */ + parameterCookie: string | null; + /** + * This is the parameter that goes into the request form data + */ + parameterForm: string | null; + /** + * This is the parameter that goes into the request header + */ + parameterHeader: string | null; + /** + * This is the parameter that goes into the path + */ + parameterPath1?: string; + /** + * This is the parameter that goes into the path + */ + parameterPath2?: string; + /** + * This is the parameter that goes into the path + */ + parameterPath3?: string; + /** + * This is the parameter that goes into the request query params + */ + parameterQuery: string | null; + /** + * This is the parameter that goes into the body + */ + requestBody: ModelWithString | null; +}; + +export type ParametersGetCallWithOptionalParamData = { + /** + * This is an optional parameter + */ + parameter?: string; + /** + * This is a required parameter + */ + requestBody: ModelWithOneOfEnum; +}; + +export type ParametersPostCallWithOptionalParamData = { + /** + * This is a required parameter + */ + parameter: Pageable; + /** + * This is an optional parameter + */ + requestBody?: ModelWithString; +}; + +export type DescriptionsCallWithDescriptionsData = { + /** + * Testing backticks in string: `backticks` and ```multiple backticks``` should work + */ + parameterWithBackticks?: unknown; + /** + * Testing multiline comments in string: First line + * Second line + * + * Fourth line + */ + parameterWithBreaks?: unknown; + /** + * Testing expression placeholders in string: ${expression} should work + */ + parameterWithExpressionPlaceholders?: unknown; + /** + * Testing quotes in string: 'single quote''' and "double quotes""" should work + */ + parameterWithQuotes?: unknown; + /** + * Testing reserved characters in string: * inline * and ** inline ** should work + */ + parameterWithReservedCharacters?: unknown; + /** + * Testing slashes in string: \backwards\\\ and /forwards/// should work + */ + parameterWithSlashes?: unknown; +}; + +export type DeprecatedDeprecatedCallData = { + /** + * This parameter is deprecated + * @deprecated + */ + parameter: DeprecatedModel | null; +}; + +export type RequestBodyPostApiRequestBodyData = { + /** + * A reusable request body + */ + foo?: ModelWithString; + /** + * This is a reusable parameter + */ + parameter?: string; +}; + +export type FormDataPostApiFormDataData = { + /** + * A reusable request body + */ + formData?: ModelWithString; + /** + * This is a reusable parameter + */ + parameter?: string; +}; + +export type DefaultsCallWithDefaultParametersData = { + /** + * This is a simple boolean with default value + */ + parameterBoolean?: boolean | null; + /** + * This is a simple enum with default value + */ + parameterEnum?: 'Success' | 'Warning' | 'Error'; + /** + * This is a simple model with default value + */ + parameterModel?: ModelWithString | null; + /** + * This is a simple number with default value + */ + parameterNumber?: number | null; + /** + * This is a simple string with default value + */ + parameterString?: string | null; +}; + +export type DefaultsCallWithDefaultOptionalParametersData = { + /** + * This is a simple boolean that is optional with default value + */ + parameterBoolean?: boolean; + /** + * This is a simple enum that is optional with default value + */ + parameterEnum?: 'Success' | 'Warning' | 'Error'; + /** + * This is a simple model that is optional with default value + */ + parameterModel?: ModelWithString; + /** + * This is a simple number that is optional with default value + */ + parameterNumber?: number; + /** + * This is a simple string that is optional with default value + */ + parameterString?: string; +}; + +export type DefaultsCallToTestOrderOfParamsData = { + /** + * This is a optional string with default + */ + parameterOptionalStringWithDefault?: string; + /** + * This is a optional string with empty default + */ + parameterOptionalStringWithEmptyDefault?: string; + /** + * This is a optional string with no default + */ + parameterOptionalStringWithNoDefault?: string; + /** + * This is a string that can be null with default + */ + parameterStringNullableWithDefault?: string | null; + /** + * This is a string that can be null with no default + */ + parameterStringNullableWithNoDefault?: string | null; + /** + * This is a string with default + */ + parameterStringWithDefault: string; + /** + * This is a string with empty default + */ + parameterStringWithEmptyDefault: string; + /** + * This is a string with no default + */ + parameterStringWithNoDefault: string; +}; + +export type NoContentCallWithNoContentResponseResponse = void; + +export type NoContentCallWithResponseAndNoContentResponseResponse = number | void; + +export type ResponseCallWithResponseAndNoContentResponseResponse = number | void; + +export type ResponseCallWithResponseResponse = ModelWithString; + +export type ResponseCallWithDuplicateResponsesResponse = ModelWithString; + +export type ResponseCallWithResponsesResponse = { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; +} | ModelThatExtends | ModelThatExtendsExtends | ModelWithString; + +export type MultipleTags1DummyAResponse = void; + +export type MultipleTags1DummyBResponse = void; + +export type MultipleTags2DummyAResponse = void; + +export type MultipleTags2DummyBResponse = void; + +export type MultipleTags3DummyBResponse = void; + +export type CollectionFormatCollectionFormatData = { + /** + * This is an array parameter that is sent as csv format (comma-separated values) + */ + parameterArrayCsv: Array<(string)> | null; + /** + * This is an array parameter that is sent as multi format (multiple parameter instances) + */ + parameterArrayMulti: Array<(string)> | null; + /** + * This is an array parameter that is sent as pipes format (pipe-separated values) + */ + parameterArrayPipes: Array<(string)> | null; + /** + * This is an array parameter that is sent as ssv format (space-separated values) + */ + parameterArraySsv: Array<(string)> | null; + /** + * This is an array parameter that is sent as tsv format (tab-separated values) + */ + parameterArrayTsv: Array<(string)> | null; +}; + +export type TypesTypesData = { + /** + * This is a number parameter + */ + id?: number; + /** + * This is an array parameter + */ + parameterArray: Array<(string)> | null; + /** + * This is a boolean parameter + */ + parameterBoolean: boolean | null; + /** + * This is a dictionary parameter + */ + parameterDictionary: { + [key: string]: unknown; + } | null; + /** + * This is an enum parameter + */ + parameterEnum: 'Success' | 'Warning' | 'Error' | null; + /** + * This is a number parameter + */ + parameterNumber: number; + /** + * This is an object parameter + */ + parameterObject: { + [key: string]: unknown; + } | null; + /** + * This is a string parameter + */ + parameterString: string | null; +}; + +export type TypesTypesResponse = number | string | boolean | { + [key: string]: unknown; +}; + +export type UploadUploadFileData = { + /** + * Supply a file reference for upload + */ + file: (Blob | File); +}; + +export type UploadUploadFileResponse = boolean; + +export type FileResponseFileResponseData = { + id: string; +}; + +export type FileResponseFileResponseResponse = (Blob | File); + +export type ComplexComplexTypesData = { + /** + * Parameter containing object + */ + parameterObject: { + first?: { + second?: { + third?: string; + }; + }; + }; + /** + * Parameter containing reference + */ + parameterReference: ModelWithString; +}; + +export type ComplexComplexTypesResponse = Array; + +export type ComplexComplexParamsData = { + id: number; + requestBody?: { + readonly key: string | null; + name: string | null; + enabled?: boolean; + readonly type: 'Monkey' | 'Horse' | 'Bird'; + listOfModels?: Array | null; + listOfStrings?: Array<(string)> | null; + parameters: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; + readonly user?: { + readonly id?: number; + readonly name?: string | null; + }; + }; +}; + +export type ComplexComplexParamsResponse = ModelWithString; + +export type MultipartMultipartRequestData = { + formData?: { + content?: (Blob | File); + data?: ModelWithString | null; + }; +}; + +export type MultipartMultipartResponseResponse = { + file?: (Blob | File); + metadata?: { + foo?: string; + bar?: string; + }; +}; + +export type HeaderCallWithResultFromHeaderResponse = string; + +export type ErrorTestErrorCodeData = { + /** + * Status code to return + */ + status: number; +}; + +export type ErrorTestErrorCodeResponse = unknown; + +export type NonAsciiÆøåÆøÅöôêÊNonAsciiæøåÆøÅöôêÊ字符串Data = { + /** + * Dummy input param + */ + nonAsciiParamæøåÆøÅöôêÊ: number; +}; + +export type NonAsciiÆøåÆøÅöôêÊNonAsciiæøåÆøÅöôêÊ字符串Response = Array; + export type $OpenApiTs = { '/api/v{api-version}/no-tag': { post: { @@ -846,7 +1276,7 @@ export type $OpenApiTs = { requestBody: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; }; res: { - 200: ModelWithReadOnlyAndWriteOnly; + default: ModelWithReadOnlyAndWriteOnly; }; }; }; @@ -1159,15 +1589,15 @@ export type $OpenApiTs = { '/api/v{api-version}/response': { get: { res: { - 200: ModelWithString; + default: ModelWithString; }; }; post: { res: { /** - * Message for default response + * Message for 201 response */ - 200: ModelWithString; + 201: ModelWithString; /** * Message for 500 error */ @@ -1185,9 +1615,13 @@ export type $OpenApiTs = { put: { res: { /** - * Message for default response + * Message for 200 response */ - 200: ModelWithString; + 200: { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; + }; /** * Message for 201 response */ @@ -1196,6 +1630,10 @@ export type $OpenApiTs = { * Message for 202 response */ 202: ModelThatExtendsExtends; + /** + * Message for default response + */ + default: ModelWithString; /** * Message for 500 error */ diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/services.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/services.gen.ts.snap index 12a35cded..d4d9727c6 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/services.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/services.gen.ts.snap @@ -2,7 +2,7 @@ import type { CancelablePromise } from './core/CancelablePromise'; import type { BaseHttpRequest } from './core/BaseHttpRequest'; -import type { $OpenApiTs } from './types.gen'; +import type { DefaultPostServiceWithEmptyTagData, DefaultPostServiceWithEmptyTagResponse, SimpleApiVversionOdataControllerCountResponse, ParametersDeleteFooData, ParametersCallWithParametersData, ParametersCallWithWeirdParameterNamesData, ParametersGetCallWithOptionalParamData, ParametersPostCallWithOptionalParamData, DescriptionsCallWithDescriptionsData, DeprecatedDeprecatedCallData, RequestBodyPostApiRequestBodyData, FormDataPostApiFormDataData, DefaultsCallWithDefaultParametersData, DefaultsCallWithDefaultOptionalParametersData, DefaultsCallToTestOrderOfParamsData, NoContentCallWithNoContentResponseResponse, NoContentCallWithResponseAndNoContentResponseResponse, ResponseCallWithResponseAndNoContentResponseResponse, ResponseCallWithResponseResponse, ResponseCallWithDuplicateResponsesResponse, ResponseCallWithResponsesResponse, MultipleTags1DummyAResponse, MultipleTags1DummyBResponse, MultipleTags2DummyAResponse, MultipleTags2DummyBResponse, MultipleTags3DummyBResponse, CollectionFormatCollectionFormatData, TypesTypesData, TypesTypesResponse, UploadUploadFileData, UploadUploadFileResponse, FileResponseFileResponseData, FileResponseFileResponseResponse, ComplexComplexTypesData, ComplexComplexTypesResponse, ComplexComplexParamsData, ComplexComplexParamsResponse, MultipartMultipartRequestData, MultipartMultipartResponseResponse, HeaderCallWithResultFromHeaderResponse, ErrorTestErrorCodeData, ErrorTestErrorCodeResponse, NonAsciiÆøåÆøÅöôêÊNonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiÆøåÆøÅöôêÊNonAsciiæøåÆøÅöôêÊ字符串Response } from './types.gen'; export class DefaultService { constructor(public readonly httpRequest: BaseHttpRequest) { } @@ -23,7 +23,7 @@ export class DefaultService { * @returns ModelWithReadOnlyAndWriteOnly * @throws ApiError */ - public postServiceWithEmptyTag(data: $OpenApiTs['/api/v{api-version}/no-tag']['post']['req']): CancelablePromise<$OpenApiTs['/api/v{api-version}/no-tag']['post']['res'][200]> { + public postServiceWithEmptyTag(data: DefaultPostServiceWithEmptyTagData): CancelablePromise { return this.httpRequest.request({ method: 'POST', url: '/api/v{api-version}/no-tag', @@ -41,7 +41,7 @@ export class SimpleService { * @returns Model_From_Zendesk Success * @throws ApiError */ - public apiVVersionOdataControllerCount(): CancelablePromise<$OpenApiTs['/api/v{api-version}/simple/$count']['get']['res'][200]> { + public apiVVersionOdataControllerCount(): CancelablePromise { return this.httpRequest.request({ method: 'GET', url: '/api/v{api-version}/simple/$count' @@ -129,7 +129,7 @@ export class ParametersService { * @param data.bar bar in method * @throws ApiError */ - public deleteFoo(data: $OpenApiTs['/api/v{api-version}/foo/{foo}/bar/{bar}']['delete']['req']): CancelablePromise { + public deleteFoo(data: ParametersDeleteFooData): CancelablePromise { return this.httpRequest.request({ method: 'DELETE', url: '/api/v{api-version}/foo/{foo}/bar/{bar}', @@ -152,7 +152,7 @@ export class ParametersService { * @param data.fooRefEnum * @throws ApiError */ - public callWithParameters(data: $OpenApiTs['/api/v{api-version}/parameters/{parameterPath}']['post']['req']): CancelablePromise { + public callWithParameters(data: ParametersCallWithParametersData): CancelablePromise { return this.httpRequest.request({ method: 'POST', url: '/api/v{api-version}/parameters/{parameterPath}', @@ -191,7 +191,7 @@ export class ParametersService { * @param data._default This is the parameter with a reserved keyword * @throws ApiError */ - public callWithWeirdParameterNames(data: $OpenApiTs['/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}']['post']['req']): CancelablePromise { + public callWithWeirdParameterNames(data: ParametersCallWithWeirdParameterNamesData): CancelablePromise { return this.httpRequest.request({ method: 'POST', url: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}', @@ -224,7 +224,7 @@ export class ParametersService { * @param data.parameter This is an optional parameter * @throws ApiError */ - public getCallWithOptionalParam(data: $OpenApiTs['/api/v{api-version}/parameters/']['get']['req']): CancelablePromise { + public getCallWithOptionalParam(data: ParametersGetCallWithOptionalParamData): CancelablePromise { return this.httpRequest.request({ method: 'GET', url: '/api/v{api-version}/parameters/', @@ -242,7 +242,7 @@ export class ParametersService { * @param data.requestBody This is an optional parameter * @throws ApiError */ - public postCallWithOptionalParam(data: $OpenApiTs['/api/v{api-version}/parameters/']['post']['req']): CancelablePromise { + public postCallWithOptionalParam(data: ParametersPostCallWithOptionalParamData): CancelablePromise { return this.httpRequest.request({ method: 'POST', url: '/api/v{api-version}/parameters/', @@ -272,7 +272,7 @@ export class DescriptionsService { * @param data.parameterWithReservedCharacters Testing reserved characters in string: * inline * and ** inline ** should work * @throws ApiError */ - public callWithDescriptions(data: $OpenApiTs['/api/v{api-version}/descriptions/']['post']['req'] = {}): CancelablePromise { + public callWithDescriptions(data: DescriptionsCallWithDescriptionsData = {}): CancelablePromise { return this.httpRequest.request({ method: 'POST', url: '/api/v{api-version}/descriptions/', @@ -298,7 +298,7 @@ export class DeprecatedService { * @param data.parameter This parameter is deprecated * @throws ApiError */ - public deprecatedCall(data: $OpenApiTs['/api/v{api-version}/parameters/deprecated']['post']['req']): CancelablePromise { + public deprecatedCall(data: DeprecatedDeprecatedCallData): CancelablePromise { return this.httpRequest.request({ method: 'POST', url: '/api/v{api-version}/parameters/deprecated', @@ -319,7 +319,7 @@ export class RequestBodyService { * @param data.foo A reusable request body * @throws ApiError */ - public postApiRequestBody(data: $OpenApiTs['/api/v{api-version}/requestBody/']['post']['req'] = {}): CancelablePromise { + public postApiRequestBody(data: RequestBodyPostApiRequestBodyData = {}): CancelablePromise { return this.httpRequest.request({ method: 'POST', url: '/api/v{api-version}/requestBody/', @@ -342,7 +342,7 @@ export class FormDataService { * @param data.formData A reusable request body * @throws ApiError */ - public postApiFormData(data: $OpenApiTs['/api/v{api-version}/formData/']['post']['req'] = {}): CancelablePromise { + public postApiFormData(data: FormDataPostApiFormDataData = {}): CancelablePromise { return this.httpRequest.request({ method: 'POST', url: '/api/v{api-version}/formData/', @@ -368,7 +368,7 @@ export class DefaultsService { * @param data.parameterModel This is a simple model with default value * @throws ApiError */ - public callWithDefaultParameters(data: $OpenApiTs['/api/v{api-version}/defaults']['get']['req'] = {}): CancelablePromise { + public callWithDefaultParameters(data: DefaultsCallWithDefaultParametersData = {}): CancelablePromise { return this.httpRequest.request({ method: 'GET', url: '/api/v{api-version}/defaults', @@ -391,7 +391,7 @@ export class DefaultsService { * @param data.parameterModel This is a simple model that is optional with default value * @throws ApiError */ - public callWithDefaultOptionalParameters(data: $OpenApiTs['/api/v{api-version}/defaults']['post']['req'] = {}): CancelablePromise { + public callWithDefaultOptionalParameters(data: DefaultsCallWithDefaultOptionalParametersData = {}): CancelablePromise { return this.httpRequest.request({ method: 'POST', url: '/api/v{api-version}/defaults', @@ -417,7 +417,7 @@ export class DefaultsService { * @param data.parameterStringNullableWithDefault This is a string that can be null with default * @throws ApiError */ - public callToTestOrderOfParams(data: $OpenApiTs['/api/v{api-version}/defaults']['put']['req']): CancelablePromise { + public callToTestOrderOfParams(data: DefaultsCallToTestOrderOfParamsData): CancelablePromise { return this.httpRequest.request({ method: 'PUT', url: '/api/v{api-version}/defaults', @@ -488,7 +488,7 @@ export class NoContentService { * @returns void Success * @throws ApiError */ - public callWithNoContentResponse(): CancelablePromise<$OpenApiTs['/api/v{api-version}/no-content']['get']['res'][204]> { + public callWithNoContentResponse(): CancelablePromise { return this.httpRequest.request({ method: 'GET', url: '/api/v{api-version}/no-content' @@ -500,7 +500,7 @@ export class NoContentService { * @returns void Success * @throws ApiError */ - public callWithResponseAndNoContentResponse(): CancelablePromise<$OpenApiTs['/api/v{api-version}/multiple-tags/response-and-no-content']['get']['res'][200] | $OpenApiTs['/api/v{api-version}/multiple-tags/response-and-no-content']['get']['res'][204]> { + public callWithResponseAndNoContentResponse(): CancelablePromise { return this.httpRequest.request({ method: 'GET', url: '/api/v{api-version}/multiple-tags/response-and-no-content' @@ -517,7 +517,7 @@ export class ResponseService { * @returns void Success * @throws ApiError */ - public callWithResponseAndNoContentResponse(): CancelablePromise<$OpenApiTs['/api/v{api-version}/multiple-tags/response-and-no-content']['get']['res'][200] | $OpenApiTs['/api/v{api-version}/multiple-tags/response-and-no-content']['get']['res'][204]> { + public callWithResponseAndNoContentResponse(): CancelablePromise { return this.httpRequest.request({ method: 'GET', url: '/api/v{api-version}/multiple-tags/response-and-no-content' @@ -528,7 +528,7 @@ export class ResponseService { * @returns ModelWithString * @throws ApiError */ - public callWithResponse(): CancelablePromise<$OpenApiTs['/api/v{api-version}/response']['get']['res'][200]> { + public callWithResponse(): CancelablePromise { return this.httpRequest.request({ method: 'GET', url: '/api/v{api-version}/response' @@ -536,10 +536,10 @@ export class ResponseService { } /** - * @returns ModelWithString Message for default response + * @returns ModelWithString Message for 201 response * @throws ApiError */ - public callWithDuplicateResponses(): CancelablePromise<$OpenApiTs['/api/v{api-version}/response']['post']['res'][200]> { + public callWithDuplicateResponses(): CancelablePromise { return this.httpRequest.request({ method: 'POST', url: '/api/v{api-version}/response', @@ -553,12 +553,12 @@ export class ResponseService { /** * @returns unknown Message for 200 response - * @returns ModelWithString Message for default response * @returns ModelThatExtends Message for 201 response * @returns ModelThatExtendsExtends Message for 202 response + * @returns ModelWithString Message for default response * @throws ApiError */ - public callWithResponses(): CancelablePromise<$OpenApiTs['/api/v{api-version}/response']['put']['res'][200] | $OpenApiTs['/api/v{api-version}/response']['put']['res'][200] | $OpenApiTs['/api/v{api-version}/response']['put']['res'][201] | $OpenApiTs['/api/v{api-version}/response']['put']['res'][202]> { + public callWithResponses(): CancelablePromise { return this.httpRequest.request({ method: 'PUT', url: '/api/v{api-version}/response', @@ -579,7 +579,7 @@ export class MultipleTags1Service { * @returns void Success * @throws ApiError */ - public dummyA(): CancelablePromise<$OpenApiTs['/api/v{api-version}/multiple-tags/a']['get']['res'][204]> { + public dummyA(): CancelablePromise { return this.httpRequest.request({ method: 'GET', url: '/api/v{api-version}/multiple-tags/a' @@ -590,7 +590,7 @@ export class MultipleTags1Service { * @returns void Success * @throws ApiError */ - public dummyB(): CancelablePromise<$OpenApiTs['/api/v{api-version}/multiple-tags/b']['get']['res'][204]> { + public dummyB(): CancelablePromise { return this.httpRequest.request({ method: 'GET', url: '/api/v{api-version}/multiple-tags/b' @@ -606,7 +606,7 @@ export class MultipleTags2Service { * @returns void Success * @throws ApiError */ - public dummyA(): CancelablePromise<$OpenApiTs['/api/v{api-version}/multiple-tags/a']['get']['res'][204]> { + public dummyA(): CancelablePromise { return this.httpRequest.request({ method: 'GET', url: '/api/v{api-version}/multiple-tags/a' @@ -617,7 +617,7 @@ export class MultipleTags2Service { * @returns void Success * @throws ApiError */ - public dummyB(): CancelablePromise<$OpenApiTs['/api/v{api-version}/multiple-tags/b']['get']['res'][204]> { + public dummyB(): CancelablePromise { return this.httpRequest.request({ method: 'GET', url: '/api/v{api-version}/multiple-tags/b' @@ -633,7 +633,7 @@ export class MultipleTags3Service { * @returns void Success * @throws ApiError */ - public dummyB(): CancelablePromise<$OpenApiTs['/api/v{api-version}/multiple-tags/b']['get']['res'][204]> { + public dummyB(): CancelablePromise { return this.httpRequest.request({ method: 'GET', url: '/api/v{api-version}/multiple-tags/b' @@ -654,7 +654,7 @@ export class CollectionFormatService { * @param data.parameterArrayMulti This is an array parameter that is sent as multi format (multiple parameter instances) * @throws ApiError */ - public collectionFormat(data: $OpenApiTs['/api/v{api-version}/collectionFormat']['get']['req']): CancelablePromise { + public collectionFormat(data: CollectionFormatCollectionFormatData): CancelablePromise { return this.httpRequest.request({ method: 'GET', url: '/api/v{api-version}/collectionFormat', @@ -689,7 +689,7 @@ export class TypesService { * @returns unknown Response is a simple object * @throws ApiError */ - public types(data: $OpenApiTs['/api/v{api-version}/types']['get']['req']): CancelablePromise<$OpenApiTs['/api/v{api-version}/types']['get']['res'][200] | $OpenApiTs['/api/v{api-version}/types']['get']['res'][201] | $OpenApiTs['/api/v{api-version}/types']['get']['res'][202] | $OpenApiTs['/api/v{api-version}/types']['get']['res'][203]> { + public types(data: TypesTypesData): CancelablePromise { return this.httpRequest.request({ method: 'GET', url: '/api/v{api-version}/types', @@ -719,7 +719,7 @@ export class UploadService { * @returns boolean * @throws ApiError */ - public uploadFile(data: $OpenApiTs['/api/v{api-version}/upload']['post']['req']): CancelablePromise<$OpenApiTs['/api/v{api-version}/upload']['post']['res'][200]> { + public uploadFile(data: UploadUploadFileData): CancelablePromise { return this.httpRequest.request({ method: 'POST', url: '/api/v{api-version}/upload', @@ -740,7 +740,7 @@ export class FileResponseService { * @returns binary Success * @throws ApiError */ - public fileResponse(data: $OpenApiTs['/api/v{api-version}/file/{id}']['get']['req']): CancelablePromise<$OpenApiTs['/api/v{api-version}/file/{id}']['get']['res'][200]> { + public fileResponse(data: FileResponseFileResponseData): CancelablePromise { return this.httpRequest.request({ method: 'GET', url: '/api/v{api-version}/file/{id}', @@ -762,7 +762,7 @@ export class ComplexService { * @returns ModelWithString Successful response * @throws ApiError */ - public complexTypes(data: $OpenApiTs['/api/v{api-version}/complex']['get']['req']): CancelablePromise<$OpenApiTs['/api/v{api-version}/complex']['get']['res'][200]> { + public complexTypes(data: ComplexComplexTypesData): CancelablePromise { return this.httpRequest.request({ method: 'GET', url: '/api/v{api-version}/complex', @@ -784,7 +784,7 @@ export class ComplexService { * @returns ModelWithString Success * @throws ApiError */ - public complexParams(data: $OpenApiTs['/api/v{api-version}/complex/{id}']['put']['req']): CancelablePromise<$OpenApiTs['/api/v{api-version}/complex/{id}']['put']['res'][200]> { + public complexParams(data: ComplexComplexParamsData): CancelablePromise { return this.httpRequest.request({ method: 'PUT', url: '/api/v{api-version}/complex/{id}', @@ -806,7 +806,7 @@ export class MultipartService { * @param data.formData * @throws ApiError */ - public multipartRequest(data: $OpenApiTs['/api/v{api-version}/multipart']['post']['req'] = {}): CancelablePromise { + public multipartRequest(data: MultipartMultipartRequestData = {}): CancelablePromise { return this.httpRequest.request({ method: 'POST', url: '/api/v{api-version}/multipart', @@ -819,7 +819,7 @@ export class MultipartService { * @returns unknown OK * @throws ApiError */ - public multipartResponse(): CancelablePromise<$OpenApiTs['/api/v{api-version}/multipart']['get']['res'][200]> { + public multipartResponse(): CancelablePromise { return this.httpRequest.request({ method: 'GET', url: '/api/v{api-version}/multipart' @@ -835,7 +835,7 @@ export class HeaderService { * @returns string Successful response * @throws ApiError */ - public callWithResultFromHeader(): CancelablePromise<$OpenApiTs['/api/v{api-version}/header']['post']['res'][200]> { + public callWithResultFromHeader(): CancelablePromise { return this.httpRequest.request({ method: 'POST', url: '/api/v{api-version}/header', @@ -858,7 +858,7 @@ export class ErrorService { * @returns unknown Custom message: Successful response * @throws ApiError */ - public testErrorCode(data: $OpenApiTs['/api/v{api-version}/error']['post']['req']): CancelablePromise<$OpenApiTs['/api/v{api-version}/error']['post']['res'][200]> { + public testErrorCode(data: ErrorTestErrorCodeData): CancelablePromise { return this.httpRequest.request({ method: 'POST', url: '/api/v{api-version}/error', @@ -885,7 +885,7 @@ export class NonAsciiÆøåÆøÅöôêÊService { * @returns NonAsciiStringæøåÆØÅöôêÊ字符串 Successful response * @throws ApiError */ - public nonAsciiæøåÆøÅöôêÊ字符串(data: $OpenApiTs['/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串']['post']['req']): CancelablePromise<$OpenApiTs['/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串']['post']['res'][200]> { + public nonAsciiæøåÆøÅöôêÊ字符串(data: NonAsciiÆøåÆøÅöôêÊNonAsciiæøåÆøÅöôêÊ字符串Data): CancelablePromise { return this.httpRequest.request({ method: 'POST', url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串', diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/types.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/types.gen.ts.snap index 494f704f1..9b0a9f36d 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/types.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_client/types.gen.ts.snap @@ -839,6 +839,436 @@ export type SimpleParameter = string; */ export type x_Foo_Bar = string; +export type DefaultPostServiceWithEmptyTagData = { + requestBody: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; +}; + +export type DefaultPostServiceWithEmptyTagResponse = ModelWithReadOnlyAndWriteOnly; + +export type SimpleApiVversionOdataControllerCountResponse = Model_From_Zendesk; + +export type ParametersDeleteFooData = { + /** + * bar in method + */ + bar: string; + /** + * foo in method + */ + foo: string; +}; + +export type ParametersCallWithParametersData = { + fooAllOfEnum: ModelWithNestedArrayEnumsDataFoo; + fooRefEnum?: ModelWithNestedArrayEnumsDataFoo; + /** + * This is the parameter that goes into the cookie + */ + parameterCookie: string | null; + /** + * This is the parameter that goes into the form data + */ + parameterForm: string | null; + /** + * This is the parameter that goes into the header + */ + parameterHeader: string | null; + /** + * This is the parameter that goes into the path + */ + parameterPath: string | null; + /** + * This is the parameter that goes into the query params + */ + parameterQuery: string | null; + /** + * This is the parameter that goes into the body + */ + requestBody: ModelWithString | null; +}; + +export type ParametersCallWithWeirdParameterNamesData = { + /** + * This is the parameter with a reserved keyword + */ + _default?: string; + /** + * This is the parameter that goes into the cookie + */ + parameterCookie: string | null; + /** + * This is the parameter that goes into the request form data + */ + parameterForm: string | null; + /** + * This is the parameter that goes into the request header + */ + parameterHeader: string | null; + /** + * This is the parameter that goes into the path + */ + parameterPath1?: string; + /** + * This is the parameter that goes into the path + */ + parameterPath2?: string; + /** + * This is the parameter that goes into the path + */ + parameterPath3?: string; + /** + * This is the parameter that goes into the request query params + */ + parameterQuery: string | null; + /** + * This is the parameter that goes into the body + */ + requestBody: ModelWithString | null; +}; + +export type ParametersGetCallWithOptionalParamData = { + /** + * This is an optional parameter + */ + parameter?: string; + /** + * This is a required parameter + */ + requestBody: ModelWithOneOfEnum; +}; + +export type ParametersPostCallWithOptionalParamData = { + /** + * This is a required parameter + */ + parameter: Pageable; + /** + * This is an optional parameter + */ + requestBody?: ModelWithString; +}; + +export type DescriptionsCallWithDescriptionsData = { + /** + * Testing backticks in string: `backticks` and ```multiple backticks``` should work + */ + parameterWithBackticks?: unknown; + /** + * Testing multiline comments in string: First line + * Second line + * + * Fourth line + */ + parameterWithBreaks?: unknown; + /** + * Testing expression placeholders in string: ${expression} should work + */ + parameterWithExpressionPlaceholders?: unknown; + /** + * Testing quotes in string: 'single quote''' and "double quotes""" should work + */ + parameterWithQuotes?: unknown; + /** + * Testing reserved characters in string: * inline * and ** inline ** should work + */ + parameterWithReservedCharacters?: unknown; + /** + * Testing slashes in string: \backwards\\\ and /forwards/// should work + */ + parameterWithSlashes?: unknown; +}; + +export type DeprecatedDeprecatedCallData = { + /** + * This parameter is deprecated + * @deprecated + */ + parameter: DeprecatedModel | null; +}; + +export type RequestBodyPostApiRequestBodyData = { + /** + * A reusable request body + */ + foo?: ModelWithString; + /** + * This is a reusable parameter + */ + parameter?: string; +}; + +export type FormDataPostApiFormDataData = { + /** + * A reusable request body + */ + formData?: ModelWithString; + /** + * This is a reusable parameter + */ + parameter?: string; +}; + +export type DefaultsCallWithDefaultParametersData = { + /** + * This is a simple boolean with default value + */ + parameterBoolean?: boolean | null; + /** + * This is a simple enum with default value + */ + parameterEnum?: 'Success' | 'Warning' | 'Error'; + /** + * This is a simple model with default value + */ + parameterModel?: ModelWithString | null; + /** + * This is a simple number with default value + */ + parameterNumber?: number | null; + /** + * This is a simple string with default value + */ + parameterString?: string | null; +}; + +export type DefaultsCallWithDefaultOptionalParametersData = { + /** + * This is a simple boolean that is optional with default value + */ + parameterBoolean?: boolean; + /** + * This is a simple enum that is optional with default value + */ + parameterEnum?: 'Success' | 'Warning' | 'Error'; + /** + * This is a simple model that is optional with default value + */ + parameterModel?: ModelWithString; + /** + * This is a simple number that is optional with default value + */ + parameterNumber?: number; + /** + * This is a simple string that is optional with default value + */ + parameterString?: string; +}; + +export type DefaultsCallToTestOrderOfParamsData = { + /** + * This is a optional string with default + */ + parameterOptionalStringWithDefault?: string; + /** + * This is a optional string with empty default + */ + parameterOptionalStringWithEmptyDefault?: string; + /** + * This is a optional string with no default + */ + parameterOptionalStringWithNoDefault?: string; + /** + * This is a string that can be null with default + */ + parameterStringNullableWithDefault?: string | null; + /** + * This is a string that can be null with no default + */ + parameterStringNullableWithNoDefault?: string | null; + /** + * This is a string with default + */ + parameterStringWithDefault: string; + /** + * This is a string with empty default + */ + parameterStringWithEmptyDefault: string; + /** + * This is a string with no default + */ + parameterStringWithNoDefault: string; +}; + +export type NoContentCallWithNoContentResponseResponse = void; + +export type NoContentCallWithResponseAndNoContentResponseResponse = number | void; + +export type ResponseCallWithResponseAndNoContentResponseResponse = number | void; + +export type ResponseCallWithResponseResponse = ModelWithString; + +export type ResponseCallWithDuplicateResponsesResponse = ModelWithString; + +export type ResponseCallWithResponsesResponse = { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; +} | ModelThatExtends | ModelThatExtendsExtends | ModelWithString; + +export type MultipleTags1DummyAResponse = void; + +export type MultipleTags1DummyBResponse = void; + +export type MultipleTags2DummyAResponse = void; + +export type MultipleTags2DummyBResponse = void; + +export type MultipleTags3DummyBResponse = void; + +export type CollectionFormatCollectionFormatData = { + /** + * This is an array parameter that is sent as csv format (comma-separated values) + */ + parameterArrayCsv: Array<(string)> | null; + /** + * This is an array parameter that is sent as multi format (multiple parameter instances) + */ + parameterArrayMulti: Array<(string)> | null; + /** + * This is an array parameter that is sent as pipes format (pipe-separated values) + */ + parameterArrayPipes: Array<(string)> | null; + /** + * This is an array parameter that is sent as ssv format (space-separated values) + */ + parameterArraySsv: Array<(string)> | null; + /** + * This is an array parameter that is sent as tsv format (tab-separated values) + */ + parameterArrayTsv: Array<(string)> | null; +}; + +export type TypesTypesData = { + /** + * This is a number parameter + */ + id?: number; + /** + * This is an array parameter + */ + parameterArray: Array<(string)> | null; + /** + * This is a boolean parameter + */ + parameterBoolean: boolean | null; + /** + * This is a dictionary parameter + */ + parameterDictionary: { + [key: string]: unknown; + } | null; + /** + * This is an enum parameter + */ + parameterEnum: 'Success' | 'Warning' | 'Error' | null; + /** + * This is a number parameter + */ + parameterNumber: number; + /** + * This is an object parameter + */ + parameterObject: { + [key: string]: unknown; + } | null; + /** + * This is a string parameter + */ + parameterString: string | null; +}; + +export type TypesTypesResponse = number | string | boolean | { + [key: string]: unknown; +}; + +export type UploadUploadFileData = { + /** + * Supply a file reference for upload + */ + file: (Blob | File); +}; + +export type UploadUploadFileResponse = boolean; + +export type FileResponseFileResponseData = { + id: string; +}; + +export type FileResponseFileResponseResponse = (Blob | File); + +export type ComplexComplexTypesData = { + /** + * Parameter containing object + */ + parameterObject: { + first?: { + second?: { + third?: string; + }; + }; + }; + /** + * Parameter containing reference + */ + parameterReference: ModelWithString; +}; + +export type ComplexComplexTypesResponse = Array; + +export type ComplexComplexParamsData = { + id: number; + requestBody?: { + readonly key: string | null; + name: string | null; + enabled?: boolean; + readonly type: 'Monkey' | 'Horse' | 'Bird'; + listOfModels?: Array | null; + listOfStrings?: Array<(string)> | null; + parameters: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; + readonly user?: { + readonly id?: number; + readonly name?: string | null; + }; + }; +}; + +export type ComplexComplexParamsResponse = ModelWithString; + +export type MultipartMultipartRequestData = { + formData?: { + content?: (Blob | File); + data?: ModelWithString | null; + }; +}; + +export type MultipartMultipartResponseResponse = { + file?: (Blob | File); + metadata?: { + foo?: string; + bar?: string; + }; +}; + +export type HeaderCallWithResultFromHeaderResponse = string; + +export type ErrorTestErrorCodeData = { + /** + * Status code to return + */ + status: number; +}; + +export type ErrorTestErrorCodeResponse = unknown; + +export type NonAsciiÆøåÆøÅöôêÊNonAsciiæøåÆøÅöôêÊ字符串Data = { + /** + * Dummy input param + */ + nonAsciiParamæøåÆøÅöôêÊ: number; +}; + +export type NonAsciiÆøåÆøÅöôêÊNonAsciiæøåÆøÅöôêÊ字符串Response = Array; + export type $OpenApiTs = { '/api/v{api-version}/no-tag': { post: { @@ -846,7 +1276,7 @@ export type $OpenApiTs = { requestBody: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; }; res: { - 200: ModelWithReadOnlyAndWriteOnly; + default: ModelWithReadOnlyAndWriteOnly; }; }; }; @@ -1159,15 +1589,15 @@ export type $OpenApiTs = { '/api/v{api-version}/response': { get: { res: { - 200: ModelWithString; + default: ModelWithString; }; }; post: { res: { /** - * Message for default response + * Message for 201 response */ - 200: ModelWithString; + 201: ModelWithString; /** * Message for 500 error */ @@ -1185,9 +1615,13 @@ export type $OpenApiTs = { put: { res: { /** - * Message for default response + * Message for 200 response */ - 200: ModelWithString; + 200: { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; + }; /** * Message for 201 response */ @@ -1196,6 +1630,10 @@ export type $OpenApiTs = { * Message for 202 response */ 202: ModelThatExtendsExtends; + /** + * Message for default response + */ + default: ModelWithString; /** * Message for 500 error */ diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/services.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/services.gen.ts.snap index 3f671329f..35ccb0463 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/services.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/services.gen.ts.snap @@ -3,7 +3,7 @@ import type { CancelablePromise } from './core/CancelablePromise'; import { OpenAPI } from './core/OpenAPI'; import { request as __request } from './core/request'; -import type { $OpenApiTs } from './types.gen'; +import type { DefaultPostServiceWithEmptyTagData, DefaultPostServiceWithEmptyTagResponse, SimpleApiVversionOdataControllerCountResponse, ParametersDeleteFooData, ParametersCallWithParametersData, ParametersCallWithWeirdParameterNamesData, ParametersGetCallWithOptionalParamData, ParametersPostCallWithOptionalParamData, DescriptionsCallWithDescriptionsData, DeprecatedDeprecatedCallData, RequestBodyPostApiRequestBodyData, FormDataPostApiFormDataData, DefaultsCallWithDefaultParametersData, DefaultsCallWithDefaultOptionalParametersData, DefaultsCallToTestOrderOfParamsData, NoContentCallWithNoContentResponseResponse, NoContentCallWithResponseAndNoContentResponseResponse, ResponseCallWithResponseAndNoContentResponseResponse, ResponseCallWithResponseResponse, ResponseCallWithDuplicateResponsesResponse, ResponseCallWithResponsesResponse, MultipleTags1DummyAResponse, MultipleTags1DummyBResponse, MultipleTags2DummyAResponse, MultipleTags2DummyBResponse, MultipleTags3DummyBResponse, CollectionFormatCollectionFormatData, TypesTypesData, TypesTypesResponse, UploadUploadFileData, UploadUploadFileResponse, FileResponseFileResponseData, FileResponseFileResponseResponse, ComplexComplexTypesData, ComplexComplexTypesResponse, ComplexComplexParamsData, ComplexComplexParamsResponse, MultipartMultipartRequestData, MultipartMultipartResponseResponse, HeaderCallWithResultFromHeaderResponse, ErrorTestErrorCodeData, ErrorTestErrorCodeResponse, NonAsciiÆøåÆøÅöôêÊNonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiÆøåÆøÅöôêÊNonAsciiæøåÆøÅöôêÊ字符串Response } from './types.gen'; export class DefaultService { /** @@ -22,7 +22,7 @@ export class DefaultService { * @returns ModelWithReadOnlyAndWriteOnly * @throws ApiError */ - public static postServiceWithEmptyTag(data: $OpenApiTs['/api/v{api-version}/no-tag']['post']['req']): CancelablePromise<$OpenApiTs['/api/v{api-version}/no-tag']['post']['res'][200]> { + public static postServiceWithEmptyTag(data: DefaultPostServiceWithEmptyTagData): CancelablePromise { return __request(OpenAPI, { method: 'POST', url: '/api/v{api-version}/no-tag', @@ -38,7 +38,7 @@ export class SimpleService { * @returns Model_From_Zendesk Success * @throws ApiError */ - public static apiVVersionOdataControllerCount(): CancelablePromise<$OpenApiTs['/api/v{api-version}/simple/$count']['get']['res'][200]> { + public static apiVVersionOdataControllerCount(): CancelablePromise { return __request(OpenAPI, { method: 'GET', url: '/api/v{api-version}/simple/$count' @@ -124,7 +124,7 @@ export class ParametersService { * @param data.bar bar in method * @throws ApiError */ - public static deleteFoo(data: $OpenApiTs['/api/v{api-version}/foo/{foo}/bar/{bar}']['delete']['req']): CancelablePromise { + public static deleteFoo(data: ParametersDeleteFooData): CancelablePromise { return __request(OpenAPI, { method: 'DELETE', url: '/api/v{api-version}/foo/{foo}/bar/{bar}', @@ -147,7 +147,7 @@ export class ParametersService { * @param data.fooRefEnum * @throws ApiError */ - public static callWithParameters(data: $OpenApiTs['/api/v{api-version}/parameters/{parameterPath}']['post']['req']): CancelablePromise { + public static callWithParameters(data: ParametersCallWithParametersData): CancelablePromise { return __request(OpenAPI, { method: 'POST', url: '/api/v{api-version}/parameters/{parameterPath}', @@ -186,7 +186,7 @@ export class ParametersService { * @param data._default This is the parameter with a reserved keyword * @throws ApiError */ - public static callWithWeirdParameterNames(data: $OpenApiTs['/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}']['post']['req']): CancelablePromise { + public static callWithWeirdParameterNames(data: ParametersCallWithWeirdParameterNamesData): CancelablePromise { return __request(OpenAPI, { method: 'POST', url: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}', @@ -219,7 +219,7 @@ export class ParametersService { * @param data.parameter This is an optional parameter * @throws ApiError */ - public static getCallWithOptionalParam(data: $OpenApiTs['/api/v{api-version}/parameters/']['get']['req']): CancelablePromise { + public static getCallWithOptionalParam(data: ParametersGetCallWithOptionalParamData): CancelablePromise { return __request(OpenAPI, { method: 'GET', url: '/api/v{api-version}/parameters/', @@ -237,7 +237,7 @@ export class ParametersService { * @param data.requestBody This is an optional parameter * @throws ApiError */ - public static postCallWithOptionalParam(data: $OpenApiTs['/api/v{api-version}/parameters/']['post']['req']): CancelablePromise { + public static postCallWithOptionalParam(data: ParametersPostCallWithOptionalParamData): CancelablePromise { return __request(OpenAPI, { method: 'POST', url: '/api/v{api-version}/parameters/', @@ -265,7 +265,7 @@ export class DescriptionsService { * @param data.parameterWithReservedCharacters Testing reserved characters in string: * inline * and ** inline ** should work * @throws ApiError */ - public static callWithDescriptions(data: $OpenApiTs['/api/v{api-version}/descriptions/']['post']['req'] = {}): CancelablePromise { + public static callWithDescriptions(data: DescriptionsCallWithDescriptionsData = {}): CancelablePromise { return __request(OpenAPI, { method: 'POST', url: '/api/v{api-version}/descriptions/', @@ -289,7 +289,7 @@ export class DeprecatedService { * @param data.parameter This parameter is deprecated * @throws ApiError */ - public static deprecatedCall(data: $OpenApiTs['/api/v{api-version}/parameters/deprecated']['post']['req']): CancelablePromise { + public static deprecatedCall(data: DeprecatedDeprecatedCallData): CancelablePromise { return __request(OpenAPI, { method: 'POST', url: '/api/v{api-version}/parameters/deprecated', @@ -308,7 +308,7 @@ export class RequestBodyService { * @param data.foo A reusable request body * @throws ApiError */ - public static postApiRequestBody(data: $OpenApiTs['/api/v{api-version}/requestBody/']['post']['req'] = {}): CancelablePromise { + public static postApiRequestBody(data: RequestBodyPostApiRequestBodyData = {}): CancelablePromise { return __request(OpenAPI, { method: 'POST', url: '/api/v{api-version}/requestBody/', @@ -329,7 +329,7 @@ export class FormDataService { * @param data.formData A reusable request body * @throws ApiError */ - public static postApiFormData(data: $OpenApiTs['/api/v{api-version}/formData/']['post']['req'] = {}): CancelablePromise { + public static postApiFormData(data: FormDataPostApiFormDataData = {}): CancelablePromise { return __request(OpenAPI, { method: 'POST', url: '/api/v{api-version}/formData/', @@ -353,7 +353,7 @@ export class DefaultsService { * @param data.parameterModel This is a simple model with default value * @throws ApiError */ - public static callWithDefaultParameters(data: $OpenApiTs['/api/v{api-version}/defaults']['get']['req'] = {}): CancelablePromise { + public static callWithDefaultParameters(data: DefaultsCallWithDefaultParametersData = {}): CancelablePromise { return __request(OpenAPI, { method: 'GET', url: '/api/v{api-version}/defaults', @@ -376,7 +376,7 @@ export class DefaultsService { * @param data.parameterModel This is a simple model that is optional with default value * @throws ApiError */ - public static callWithDefaultOptionalParameters(data: $OpenApiTs['/api/v{api-version}/defaults']['post']['req'] = {}): CancelablePromise { + public static callWithDefaultOptionalParameters(data: DefaultsCallWithDefaultOptionalParametersData = {}): CancelablePromise { return __request(OpenAPI, { method: 'POST', url: '/api/v{api-version}/defaults', @@ -402,7 +402,7 @@ export class DefaultsService { * @param data.parameterStringNullableWithDefault This is a string that can be null with default * @throws ApiError */ - public static callToTestOrderOfParams(data: $OpenApiTs['/api/v{api-version}/defaults']['put']['req']): CancelablePromise { + public static callToTestOrderOfParams(data: DefaultsCallToTestOrderOfParamsData): CancelablePromise { return __request(OpenAPI, { method: 'PUT', url: '/api/v{api-version}/defaults', @@ -469,7 +469,7 @@ export class NoContentService { * @returns void Success * @throws ApiError */ - public static callWithNoContentResponse(): CancelablePromise<$OpenApiTs['/api/v{api-version}/no-content']['get']['res'][204]> { + public static callWithNoContentResponse(): CancelablePromise { return __request(OpenAPI, { method: 'GET', url: '/api/v{api-version}/no-content' @@ -481,7 +481,7 @@ export class NoContentService { * @returns void Success * @throws ApiError */ - public static callWithResponseAndNoContentResponse(): CancelablePromise<$OpenApiTs['/api/v{api-version}/multiple-tags/response-and-no-content']['get']['res'][200] | $OpenApiTs['/api/v{api-version}/multiple-tags/response-and-no-content']['get']['res'][204]> { + public static callWithResponseAndNoContentResponse(): CancelablePromise { return __request(OpenAPI, { method: 'GET', url: '/api/v{api-version}/multiple-tags/response-and-no-content' @@ -496,7 +496,7 @@ export class ResponseService { * @returns void Success * @throws ApiError */ - public static callWithResponseAndNoContentResponse(): CancelablePromise<$OpenApiTs['/api/v{api-version}/multiple-tags/response-and-no-content']['get']['res'][200] | $OpenApiTs['/api/v{api-version}/multiple-tags/response-and-no-content']['get']['res'][204]> { + public static callWithResponseAndNoContentResponse(): CancelablePromise { return __request(OpenAPI, { method: 'GET', url: '/api/v{api-version}/multiple-tags/response-and-no-content' @@ -507,7 +507,7 @@ export class ResponseService { * @returns ModelWithString * @throws ApiError */ - public static callWithResponse(): CancelablePromise<$OpenApiTs['/api/v{api-version}/response']['get']['res'][200]> { + public static callWithResponse(): CancelablePromise { return __request(OpenAPI, { method: 'GET', url: '/api/v{api-version}/response' @@ -515,10 +515,10 @@ export class ResponseService { } /** - * @returns ModelWithString Message for default response + * @returns ModelWithString Message for 201 response * @throws ApiError */ - public static callWithDuplicateResponses(): CancelablePromise<$OpenApiTs['/api/v{api-version}/response']['post']['res'][200]> { + public static callWithDuplicateResponses(): CancelablePromise { return __request(OpenAPI, { method: 'POST', url: '/api/v{api-version}/response', @@ -532,12 +532,12 @@ export class ResponseService { /** * @returns unknown Message for 200 response - * @returns ModelWithString Message for default response * @returns ModelThatExtends Message for 201 response * @returns ModelThatExtendsExtends Message for 202 response + * @returns ModelWithString Message for default response * @throws ApiError */ - public static callWithResponses(): CancelablePromise<$OpenApiTs['/api/v{api-version}/response']['put']['res'][200] | $OpenApiTs['/api/v{api-version}/response']['put']['res'][200] | $OpenApiTs['/api/v{api-version}/response']['put']['res'][201] | $OpenApiTs['/api/v{api-version}/response']['put']['res'][202]> { + public static callWithResponses(): CancelablePromise { return __request(OpenAPI, { method: 'PUT', url: '/api/v{api-version}/response', @@ -556,7 +556,7 @@ export class MultipleTags1Service { * @returns void Success * @throws ApiError */ - public static dummyA(): CancelablePromise<$OpenApiTs['/api/v{api-version}/multiple-tags/a']['get']['res'][204]> { + public static dummyA(): CancelablePromise { return __request(OpenAPI, { method: 'GET', url: '/api/v{api-version}/multiple-tags/a' @@ -567,7 +567,7 @@ export class MultipleTags1Service { * @returns void Success * @throws ApiError */ - public static dummyB(): CancelablePromise<$OpenApiTs['/api/v{api-version}/multiple-tags/b']['get']['res'][204]> { + public static dummyB(): CancelablePromise { return __request(OpenAPI, { method: 'GET', url: '/api/v{api-version}/multiple-tags/b' @@ -581,7 +581,7 @@ export class MultipleTags2Service { * @returns void Success * @throws ApiError */ - public static dummyA(): CancelablePromise<$OpenApiTs['/api/v{api-version}/multiple-tags/a']['get']['res'][204]> { + public static dummyA(): CancelablePromise { return __request(OpenAPI, { method: 'GET', url: '/api/v{api-version}/multiple-tags/a' @@ -592,7 +592,7 @@ export class MultipleTags2Service { * @returns void Success * @throws ApiError */ - public static dummyB(): CancelablePromise<$OpenApiTs['/api/v{api-version}/multiple-tags/b']['get']['res'][204]> { + public static dummyB(): CancelablePromise { return __request(OpenAPI, { method: 'GET', url: '/api/v{api-version}/multiple-tags/b' @@ -606,7 +606,7 @@ export class MultipleTags3Service { * @returns void Success * @throws ApiError */ - public static dummyB(): CancelablePromise<$OpenApiTs['/api/v{api-version}/multiple-tags/b']['get']['res'][204]> { + public static dummyB(): CancelablePromise { return __request(OpenAPI, { method: 'GET', url: '/api/v{api-version}/multiple-tags/b' @@ -625,7 +625,7 @@ export class CollectionFormatService { * @param data.parameterArrayMulti This is an array parameter that is sent as multi format (multiple parameter instances) * @throws ApiError */ - public static collectionFormat(data: $OpenApiTs['/api/v{api-version}/collectionFormat']['get']['req']): CancelablePromise { + public static collectionFormat(data: CollectionFormatCollectionFormatData): CancelablePromise { return __request(OpenAPI, { method: 'GET', url: '/api/v{api-version}/collectionFormat', @@ -658,7 +658,7 @@ export class TypesService { * @returns unknown Response is a simple object * @throws ApiError */ - public static types(data: $OpenApiTs['/api/v{api-version}/types']['get']['req']): CancelablePromise<$OpenApiTs['/api/v{api-version}/types']['get']['res'][200] | $OpenApiTs['/api/v{api-version}/types']['get']['res'][201] | $OpenApiTs['/api/v{api-version}/types']['get']['res'][202] | $OpenApiTs['/api/v{api-version}/types']['get']['res'][203]> { + public static types(data: TypesTypesData): CancelablePromise { return __request(OpenAPI, { method: 'GET', url: '/api/v{api-version}/types', @@ -686,7 +686,7 @@ export class UploadService { * @returns boolean * @throws ApiError */ - public static uploadFile(data: $OpenApiTs['/api/v{api-version}/upload']['post']['req']): CancelablePromise<$OpenApiTs['/api/v{api-version}/upload']['post']['res'][200]> { + public static uploadFile(data: UploadUploadFileData): CancelablePromise { return __request(OpenAPI, { method: 'POST', url: '/api/v{api-version}/upload', @@ -705,7 +705,7 @@ export class FileResponseService { * @returns binary Success * @throws ApiError */ - public static fileResponse(data: $OpenApiTs['/api/v{api-version}/file/{id}']['get']['req']): CancelablePromise<$OpenApiTs['/api/v{api-version}/file/{id}']['get']['res'][200]> { + public static fileResponse(data: FileResponseFileResponseData): CancelablePromise { return __request(OpenAPI, { method: 'GET', url: '/api/v{api-version}/file/{id}', @@ -725,7 +725,7 @@ export class ComplexService { * @returns ModelWithString Successful response * @throws ApiError */ - public static complexTypes(data: $OpenApiTs['/api/v{api-version}/complex']['get']['req']): CancelablePromise<$OpenApiTs['/api/v{api-version}/complex']['get']['res'][200]> { + public static complexTypes(data: ComplexComplexTypesData): CancelablePromise { return __request(OpenAPI, { method: 'GET', url: '/api/v{api-version}/complex', @@ -747,7 +747,7 @@ export class ComplexService { * @returns ModelWithString Success * @throws ApiError */ - public static complexParams(data: $OpenApiTs['/api/v{api-version}/complex/{id}']['put']['req']): CancelablePromise<$OpenApiTs['/api/v{api-version}/complex/{id}']['put']['res'][200]> { + public static complexParams(data: ComplexComplexParamsData): CancelablePromise { return __request(OpenAPI, { method: 'PUT', url: '/api/v{api-version}/complex/{id}', @@ -767,7 +767,7 @@ export class MultipartService { * @param data.formData * @throws ApiError */ - public static multipartRequest(data: $OpenApiTs['/api/v{api-version}/multipart']['post']['req'] = {}): CancelablePromise { + public static multipartRequest(data: MultipartMultipartRequestData = {}): CancelablePromise { return __request(OpenAPI, { method: 'POST', url: '/api/v{api-version}/multipart', @@ -780,7 +780,7 @@ export class MultipartService { * @returns unknown OK * @throws ApiError */ - public static multipartResponse(): CancelablePromise<$OpenApiTs['/api/v{api-version}/multipart']['get']['res'][200]> { + public static multipartResponse(): CancelablePromise { return __request(OpenAPI, { method: 'GET', url: '/api/v{api-version}/multipart' @@ -794,7 +794,7 @@ export class HeaderService { * @returns string Successful response * @throws ApiError */ - public static callWithResultFromHeader(): CancelablePromise<$OpenApiTs['/api/v{api-version}/header']['post']['res'][200]> { + public static callWithResultFromHeader(): CancelablePromise { return __request(OpenAPI, { method: 'POST', url: '/api/v{api-version}/header', @@ -815,7 +815,7 @@ export class ErrorService { * @returns unknown Custom message: Successful response * @throws ApiError */ - public static testErrorCode(data: $OpenApiTs['/api/v{api-version}/error']['post']['req']): CancelablePromise<$OpenApiTs['/api/v{api-version}/error']['post']['res'][200]> { + public static testErrorCode(data: ErrorTestErrorCodeData): CancelablePromise { return __request(OpenAPI, { method: 'POST', url: '/api/v{api-version}/error', @@ -840,7 +840,7 @@ export class NonAsciiÆøåÆøÅöôêÊService { * @returns NonAsciiStringæøåÆØÅöôêÊ字符串 Successful response * @throws ApiError */ - public static nonAsciiæøåÆøÅöôêÊ字符串(data: $OpenApiTs['/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串']['post']['req']): CancelablePromise<$OpenApiTs['/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串']['post']['res'][200]> { + public static nonAsciiæøåÆøÅöôêÊ字符串(data: NonAsciiÆøåÆøÅöôêÊNonAsciiæøåÆøÅöôêÊ字符串Data): CancelablePromise { return __request(OpenAPI, { method: 'POST', url: '/api/v{api-version}/non-ascii-æøåÆØÅöôêÊ字符串', diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/types.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/types.gen.ts.snap index 5df8aa391..8f051c403 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/types.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_enums_typescript/types.gen.ts.snap @@ -839,6 +839,436 @@ export type SimpleParameter = string; */ export type x_Foo_Bar = string; +export type DefaultPostServiceWithEmptyTagData = { + requestBody: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; +}; + +export type DefaultPostServiceWithEmptyTagResponse = ModelWithReadOnlyAndWriteOnly; + +export type SimpleApiVversionOdataControllerCountResponse = Model_From_Zendesk; + +export type ParametersDeleteFooData = { + /** + * bar in method + */ + bar: string; + /** + * foo in method + */ + foo: string; +}; + +export type ParametersCallWithParametersData = { + fooAllOfEnum: ModelWithNestedArrayEnumsDataFoo; + fooRefEnum?: ModelWithNestedArrayEnumsDataFoo; + /** + * This is the parameter that goes into the cookie + */ + parameterCookie: string | null; + /** + * This is the parameter that goes into the form data + */ + parameterForm: string | null; + /** + * This is the parameter that goes into the header + */ + parameterHeader: string | null; + /** + * This is the parameter that goes into the path + */ + parameterPath: string | null; + /** + * This is the parameter that goes into the query params + */ + parameterQuery: string | null; + /** + * This is the parameter that goes into the body + */ + requestBody: ModelWithString | null; +}; + +export type ParametersCallWithWeirdParameterNamesData = { + /** + * This is the parameter with a reserved keyword + */ + _default?: string; + /** + * This is the parameter that goes into the cookie + */ + parameterCookie: string | null; + /** + * This is the parameter that goes into the request form data + */ + parameterForm: string | null; + /** + * This is the parameter that goes into the request header + */ + parameterHeader: string | null; + /** + * This is the parameter that goes into the path + */ + parameterPath1?: string; + /** + * This is the parameter that goes into the path + */ + parameterPath2?: string; + /** + * This is the parameter that goes into the path + */ + parameterPath3?: string; + /** + * This is the parameter that goes into the request query params + */ + parameterQuery: string | null; + /** + * This is the parameter that goes into the body + */ + requestBody: ModelWithString | null; +}; + +export type ParametersGetCallWithOptionalParamData = { + /** + * This is an optional parameter + */ + parameter?: string; + /** + * This is a required parameter + */ + requestBody: ModelWithOneOfEnum; +}; + +export type ParametersPostCallWithOptionalParamData = { + /** + * This is a required parameter + */ + parameter: Pageable; + /** + * This is an optional parameter + */ + requestBody?: ModelWithString; +}; + +export type DescriptionsCallWithDescriptionsData = { + /** + * Testing backticks in string: `backticks` and ```multiple backticks``` should work + */ + parameterWithBackticks?: unknown; + /** + * Testing multiline comments in string: First line + * Second line + * + * Fourth line + */ + parameterWithBreaks?: unknown; + /** + * Testing expression placeholders in string: ${expression} should work + */ + parameterWithExpressionPlaceholders?: unknown; + /** + * Testing quotes in string: 'single quote''' and "double quotes""" should work + */ + parameterWithQuotes?: unknown; + /** + * Testing reserved characters in string: * inline * and ** inline ** should work + */ + parameterWithReservedCharacters?: unknown; + /** + * Testing slashes in string: \backwards\\\ and /forwards/// should work + */ + parameterWithSlashes?: unknown; +}; + +export type DeprecatedDeprecatedCallData = { + /** + * This parameter is deprecated + * @deprecated + */ + parameter: DeprecatedModel | null; +}; + +export type RequestBodyPostApiRequestBodyData = { + /** + * A reusable request body + */ + foo?: ModelWithString; + /** + * This is a reusable parameter + */ + parameter?: string; +}; + +export type FormDataPostApiFormDataData = { + /** + * A reusable request body + */ + formData?: ModelWithString; + /** + * This is a reusable parameter + */ + parameter?: string; +}; + +export type DefaultsCallWithDefaultParametersData = { + /** + * This is a simple boolean with default value + */ + parameterBoolean?: boolean | null; + /** + * This is a simple enum with default value + */ + parameterEnum?: 'Success' | 'Warning' | 'Error'; + /** + * This is a simple model with default value + */ + parameterModel?: ModelWithString | null; + /** + * This is a simple number with default value + */ + parameterNumber?: number | null; + /** + * This is a simple string with default value + */ + parameterString?: string | null; +}; + +export type DefaultsCallWithDefaultOptionalParametersData = { + /** + * This is a simple boolean that is optional with default value + */ + parameterBoolean?: boolean; + /** + * This is a simple enum that is optional with default value + */ + parameterEnum?: 'Success' | 'Warning' | 'Error'; + /** + * This is a simple model that is optional with default value + */ + parameterModel?: ModelWithString; + /** + * This is a simple number that is optional with default value + */ + parameterNumber?: number; + /** + * This is a simple string that is optional with default value + */ + parameterString?: string; +}; + +export type DefaultsCallToTestOrderOfParamsData = { + /** + * This is a optional string with default + */ + parameterOptionalStringWithDefault?: string; + /** + * This is a optional string with empty default + */ + parameterOptionalStringWithEmptyDefault?: string; + /** + * This is a optional string with no default + */ + parameterOptionalStringWithNoDefault?: string; + /** + * This is a string that can be null with default + */ + parameterStringNullableWithDefault?: string | null; + /** + * This is a string that can be null with no default + */ + parameterStringNullableWithNoDefault?: string | null; + /** + * This is a string with default + */ + parameterStringWithDefault: string; + /** + * This is a string with empty default + */ + parameterStringWithEmptyDefault: string; + /** + * This is a string with no default + */ + parameterStringWithNoDefault: string; +}; + +export type NoContentCallWithNoContentResponseResponse = void; + +export type NoContentCallWithResponseAndNoContentResponseResponse = number | void; + +export type ResponseCallWithResponseAndNoContentResponseResponse = number | void; + +export type ResponseCallWithResponseResponse = ModelWithString; + +export type ResponseCallWithDuplicateResponsesResponse = ModelWithString; + +export type ResponseCallWithResponsesResponse = { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; +} | ModelThatExtends | ModelThatExtendsExtends | ModelWithString; + +export type MultipleTags1DummyAResponse = void; + +export type MultipleTags1DummyBResponse = void; + +export type MultipleTags2DummyAResponse = void; + +export type MultipleTags2DummyBResponse = void; + +export type MultipleTags3DummyBResponse = void; + +export type CollectionFormatCollectionFormatData = { + /** + * This is an array parameter that is sent as csv format (comma-separated values) + */ + parameterArrayCsv: Array<(string)> | null; + /** + * This is an array parameter that is sent as multi format (multiple parameter instances) + */ + parameterArrayMulti: Array<(string)> | null; + /** + * This is an array parameter that is sent as pipes format (pipe-separated values) + */ + parameterArrayPipes: Array<(string)> | null; + /** + * This is an array parameter that is sent as ssv format (space-separated values) + */ + parameterArraySsv: Array<(string)> | null; + /** + * This is an array parameter that is sent as tsv format (tab-separated values) + */ + parameterArrayTsv: Array<(string)> | null; +}; + +export type TypesTypesData = { + /** + * This is a number parameter + */ + id?: number; + /** + * This is an array parameter + */ + parameterArray: Array<(string)> | null; + /** + * This is a boolean parameter + */ + parameterBoolean: boolean | null; + /** + * This is a dictionary parameter + */ + parameterDictionary: { + [key: string]: unknown; + } | null; + /** + * This is an enum parameter + */ + parameterEnum: 'Success' | 'Warning' | 'Error' | null; + /** + * This is a number parameter + */ + parameterNumber: number; + /** + * This is an object parameter + */ + parameterObject: { + [key: string]: unknown; + } | null; + /** + * This is a string parameter + */ + parameterString: string | null; +}; + +export type TypesTypesResponse = number | string | boolean | { + [key: string]: unknown; +}; + +export type UploadUploadFileData = { + /** + * Supply a file reference for upload + */ + file: (Blob | File); +}; + +export type UploadUploadFileResponse = boolean; + +export type FileResponseFileResponseData = { + id: string; +}; + +export type FileResponseFileResponseResponse = (Blob | File); + +export type ComplexComplexTypesData = { + /** + * Parameter containing object + */ + parameterObject: { + first?: { + second?: { + third?: string; + }; + }; + }; + /** + * Parameter containing reference + */ + parameterReference: ModelWithString; +}; + +export type ComplexComplexTypesResponse = Array; + +export type ComplexComplexParamsData = { + id: number; + requestBody?: { + readonly key: string | null; + name: string | null; + enabled?: boolean; + readonly type: 'Monkey' | 'Horse' | 'Bird'; + listOfModels?: Array | null; + listOfStrings?: Array<(string)> | null; + parameters: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary; + readonly user?: { + readonly id?: number; + readonly name?: string | null; + }; + }; +}; + +export type ComplexComplexParamsResponse = ModelWithString; + +export type MultipartMultipartRequestData = { + formData?: { + content?: (Blob | File); + data?: ModelWithString | null; + }; +}; + +export type MultipartMultipartResponseResponse = { + file?: (Blob | File); + metadata?: { + foo?: string; + bar?: string; + }; +}; + +export type HeaderCallWithResultFromHeaderResponse = string; + +export type ErrorTestErrorCodeData = { + /** + * Status code to return + */ + status: number; +}; + +export type ErrorTestErrorCodeResponse = unknown; + +export type NonAsciiÆøåÆøÅöôêÊNonAsciiæøåÆøÅöôêÊ字符串Data = { + /** + * Dummy input param + */ + nonAsciiParamæøåÆøÅöôêÊ: number; +}; + +export type NonAsciiÆøåÆøÅöôêÊNonAsciiæøåÆøÅöôêÊ字符串Response = Array; + export type $OpenApiTs = { '/api/v{api-version}/no-tag': { post: { @@ -846,7 +1276,7 @@ export type $OpenApiTs = { requestBody: ModelWithReadOnlyAndWriteOnly | ModelWithArrayReadOnlyAndWriteOnly; }; res: { - 200: ModelWithReadOnlyAndWriteOnly; + default: ModelWithReadOnlyAndWriteOnly; }; }; }; @@ -1159,15 +1589,15 @@ export type $OpenApiTs = { '/api/v{api-version}/response': { get: { res: { - 200: ModelWithString; + default: ModelWithString; }; }; post: { res: { /** - * Message for default response + * Message for 201 response */ - 200: ModelWithString; + 201: ModelWithString; /** * Message for 500 error */ @@ -1185,9 +1615,13 @@ export type $OpenApiTs = { put: { res: { /** - * Message for default response + * Message for 200 response */ - 200: ModelWithString; + 200: { + readonly '@namespace.string'?: string; + readonly '@namespace.integer'?: number; + readonly value?: Array; + }; /** * Message for 201 response */ @@ -1196,6 +1630,10 @@ export type $OpenApiTs = { * Message for 202 response */ 202: ModelThatExtendsExtends; + /** + * Message for default response + */ + default: ModelWithString; /** * Message for 500 error */ diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_legacy_positional_args/services.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_legacy_positional_args/services.gen.ts.snap index 1736b514e..f4e3829b7 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_legacy_positional_args/services.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_legacy_positional_args/services.gen.ts.snap @@ -3,7 +3,7 @@ import type { CancelablePromise } from './core/CancelablePromise'; import { OpenAPI } from './core/OpenAPI'; import { request as __request } from './core/request'; -import type { $OpenApiTs } from './types.gen'; +import type { DefaultsCallWithDefaultParametersData, DefaultsCallWithDefaultOptionalParametersData, DefaultsCallToTestOrderOfParamsData } from './types.gen'; export class DefaultsService { /** @@ -14,7 +14,7 @@ export class DefaultsService { * @param parameterModel This is a simple model with default value * @throws ApiError */ - public static callWithDefaultParameters(parameterString: $OpenApiTs['/api/v{api-version}/defaults']['get']['req']['parameterString'] = 'Hello World!', parameterNumber: $OpenApiTs['/api/v{api-version}/defaults']['get']['req']['parameterNumber'] = 123, parameterBoolean: $OpenApiTs['/api/v{api-version}/defaults']['get']['req']['parameterBoolean'] = true, parameterEnum: $OpenApiTs['/api/v{api-version}/defaults']['get']['req']['parameterEnum'] = 'Success', parameterModel: $OpenApiTs['/api/v{api-version}/defaults']['get']['req']['parameterModel'] = { + public static callWithDefaultParameters(parameterString: DefaultsCallWithDefaultParametersData['parameterString'] = 'Hello World!', parameterNumber: DefaultsCallWithDefaultParametersData['parameterNumber'] = 123, parameterBoolean: DefaultsCallWithDefaultParametersData['parameterBoolean'] = true, parameterEnum: DefaultsCallWithDefaultParametersData['parameterEnum'] = 'Success', parameterModel: DefaultsCallWithDefaultParametersData['parameterModel'] = { prop: 'Hello World!' }): CancelablePromise { return __request(OpenAPI, { @@ -38,7 +38,7 @@ export class DefaultsService { * @param parameterModel This is a simple model that is optional with default value * @throws ApiError */ - public static callWithDefaultOptionalParameters(parameterString: $OpenApiTs['/api/v{api-version}/defaults']['post']['req']['parameterString'] = 'Hello World!', parameterNumber: $OpenApiTs['/api/v{api-version}/defaults']['post']['req']['parameterNumber'] = 123, parameterBoolean: $OpenApiTs['/api/v{api-version}/defaults']['post']['req']['parameterBoolean'] = true, parameterEnum: $OpenApiTs['/api/v{api-version}/defaults']['post']['req']['parameterEnum'] = 'Success', parameterModel: $OpenApiTs['/api/v{api-version}/defaults']['post']['req']['parameterModel'] = { + public static callWithDefaultOptionalParameters(parameterString: DefaultsCallWithDefaultOptionalParametersData['parameterString'] = 'Hello World!', parameterNumber: DefaultsCallWithDefaultOptionalParametersData['parameterNumber'] = 123, parameterBoolean: DefaultsCallWithDefaultOptionalParametersData['parameterBoolean'] = true, parameterEnum: DefaultsCallWithDefaultOptionalParametersData['parameterEnum'] = 'Success', parameterModel: DefaultsCallWithDefaultOptionalParametersData['parameterModel'] = { prop: 'Hello World!' }): CancelablePromise { return __request(OpenAPI, { @@ -65,7 +65,7 @@ export class DefaultsService { * @param parameterStringNullableWithDefault This is a string that can be null with default * @throws ApiError */ - public static callToTestOrderOfParams(parameterStringWithNoDefault: $OpenApiTs['/api/v{api-version}/defaults']['put']['req']['parameterStringWithNoDefault'], parameterOptionalStringWithDefault: $OpenApiTs['/api/v{api-version}/defaults']['put']['req']['parameterOptionalStringWithDefault'] = 'Hello World!', parameterOptionalStringWithEmptyDefault: $OpenApiTs['/api/v{api-version}/defaults']['put']['req']['parameterOptionalStringWithEmptyDefault'] = '', parameterOptionalStringWithNoDefault?: $OpenApiTs['/api/v{api-version}/defaults']['put']['req']['parameterOptionalStringWithNoDefault'], parameterStringWithDefault: $OpenApiTs['/api/v{api-version}/defaults']['put']['req']['parameterStringWithDefault'] = 'Hello World!', parameterStringWithEmptyDefault: $OpenApiTs['/api/v{api-version}/defaults']['put']['req']['parameterStringWithEmptyDefault'] = '', parameterStringNullableWithNoDefault?: $OpenApiTs['/api/v{api-version}/defaults']['put']['req']['parameterStringNullableWithNoDefault'], parameterStringNullableWithDefault: $OpenApiTs['/api/v{api-version}/defaults']['put']['req']['parameterStringNullableWithDefault'] = null): CancelablePromise { + public static callToTestOrderOfParams(parameterStringWithNoDefault: DefaultsCallToTestOrderOfParamsData['parameterStringWithNoDefault'], parameterOptionalStringWithDefault: DefaultsCallToTestOrderOfParamsData['parameterOptionalStringWithDefault'] = 'Hello World!', parameterOptionalStringWithEmptyDefault: DefaultsCallToTestOrderOfParamsData['parameterOptionalStringWithEmptyDefault'] = '', parameterOptionalStringWithNoDefault?: DefaultsCallToTestOrderOfParamsData['parameterOptionalStringWithNoDefault'], parameterStringWithDefault: DefaultsCallToTestOrderOfParamsData['parameterStringWithDefault'] = 'Hello World!', parameterStringWithEmptyDefault: DefaultsCallToTestOrderOfParamsData['parameterStringWithEmptyDefault'] = '', parameterStringNullableWithNoDefault?: DefaultsCallToTestOrderOfParamsData['parameterStringNullableWithNoDefault'], parameterStringNullableWithDefault: DefaultsCallToTestOrderOfParamsData['parameterStringNullableWithDefault'] = null): CancelablePromise { return __request(OpenAPI, { method: 'PUT', url: '/api/v{api-version}/defaults', diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_legacy_positional_args/types.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_legacy_positional_args/types.gen.ts.snap index 896303a61..92ea597ed 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_legacy_positional_args/types.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_legacy_positional_args/types.gen.ts.snap @@ -20,6 +20,87 @@ export type ModelWithStringError = { prop?: string; }; +export type DefaultsCallWithDefaultParametersData = { + /** + * This is a simple boolean with default value + */ + parameterBoolean: boolean | null; + /** + * This is a simple enum with default value + */ + parameterEnum: 'Success' | 'Warning' | 'Error'; + /** + * This is a simple model with default value + */ + parameterModel: ModelWithString | null; + /** + * This is a simple number with default value + */ + parameterNumber: number | null; + /** + * This is a simple string with default value + */ + parameterString: string | null; +}; + +export type DefaultsCallWithDefaultOptionalParametersData = { + /** + * This is a simple boolean that is optional with default value + */ + parameterBoolean: boolean; + /** + * This is a simple enum that is optional with default value + */ + parameterEnum: 'Success' | 'Warning' | 'Error'; + /** + * This is a simple model that is optional with default value + */ + parameterModel: ModelWithString; + /** + * This is a simple number that is optional with default value + */ + parameterNumber: number; + /** + * This is a simple string that is optional with default value + */ + parameterString: string; +}; + +export type DefaultsCallToTestOrderOfParamsData = { + /** + * This is a optional string with default + */ + parameterOptionalStringWithDefault: string; + /** + * This is a optional string with empty default + */ + parameterOptionalStringWithEmptyDefault: string; + /** + * This is a optional string with no default + */ + parameterOptionalStringWithNoDefault?: string; + /** + * This is a string that can be null with default + */ + parameterStringNullableWithDefault: string | null; + /** + * This is a string that can be null with no default + */ + parameterStringNullableWithNoDefault?: string | null; + /** + * This is a string with default + */ + parameterStringWithDefault: string; + /** + * This is a string with empty default + */ + parameterStringWithEmptyDefault: string; + /** + * This is a string with no default + */ + parameterStringWithNoDefault: string; +}; + export type $OpenApiTs = { '/api/v{api-version}/defaults': { get: { diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_options/services.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_options/services.gen.ts.snap index 06e7adb74..a7bea07b8 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_options/services.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_options/services.gen.ts.snap @@ -3,7 +3,7 @@ import type { CancelablePromise } from './core/CancelablePromise'; import { OpenAPI } from './core/OpenAPI'; import { request as __request } from './core/request'; -import type { $OpenApiTs } from './types.gen'; +import type { DefaultsCallWithDefaultParametersData, DefaultsCallWithDefaultOptionalParametersData, DefaultsCallToTestOrderOfParamsData } from './types.gen'; export class DefaultsService { /** @@ -15,7 +15,7 @@ export class DefaultsService { * @param data.parameterModel This is a simple model with default value * @throws ApiError */ - public static callWithDefaultParameters(data: $OpenApiTs['/api/v{api-version}/defaults']['get']['req'] = {}): CancelablePromise { + public static callWithDefaultParameters(data: DefaultsCallWithDefaultParametersData = {}): CancelablePromise { return __request(OpenAPI, { method: 'GET', url: '/api/v{api-version}/defaults', @@ -38,7 +38,7 @@ export class DefaultsService { * @param data.parameterModel This is a simple model that is optional with default value * @throws ApiError */ - public static callWithDefaultOptionalParameters(data: $OpenApiTs['/api/v{api-version}/defaults']['post']['req'] = {}): CancelablePromise { + public static callWithDefaultOptionalParameters(data: DefaultsCallWithDefaultOptionalParametersData = {}): CancelablePromise { return __request(OpenAPI, { method: 'POST', url: '/api/v{api-version}/defaults', @@ -64,7 +64,7 @@ export class DefaultsService { * @param data.parameterStringNullableWithDefault This is a string that can be null with default * @throws ApiError */ - public static callToTestOrderOfParams(data: $OpenApiTs['/api/v{api-version}/defaults']['put']['req']): CancelablePromise { + public static callToTestOrderOfParams(data: DefaultsCallToTestOrderOfParamsData): CancelablePromise { return __request(OpenAPI, { method: 'PUT', url: '/api/v{api-version}/defaults', diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_options/types.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_options/types.gen.ts.snap index fade8236c..3750b35f7 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_options/types.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_options/types.gen.ts.snap @@ -20,6 +20,87 @@ export type ModelWithStringError = { prop?: string; }; +export type DefaultsCallWithDefaultParametersData = { + /** + * This is a simple boolean with default value + */ + parameterBoolean?: boolean | null; + /** + * This is a simple enum with default value + */ + parameterEnum?: 'Success' | 'Warning' | 'Error'; + /** + * This is a simple model with default value + */ + parameterModel?: ModelWithString | null; + /** + * This is a simple number with default value + */ + parameterNumber?: number | null; + /** + * This is a simple string with default value + */ + parameterString?: string | null; +}; + +export type DefaultsCallWithDefaultOptionalParametersData = { + /** + * This is a simple boolean that is optional with default value + */ + parameterBoolean?: boolean; + /** + * This is a simple enum that is optional with default value + */ + parameterEnum?: 'Success' | 'Warning' | 'Error'; + /** + * This is a simple model that is optional with default value + */ + parameterModel?: ModelWithString; + /** + * This is a simple number that is optional with default value + */ + parameterNumber?: number; + /** + * This is a simple string that is optional with default value + */ + parameterString?: string; +}; + +export type DefaultsCallToTestOrderOfParamsData = { + /** + * This is a optional string with default + */ + parameterOptionalStringWithDefault?: string; + /** + * This is a optional string with empty default + */ + parameterOptionalStringWithEmptyDefault?: string; + /** + * This is a optional string with no default + */ + parameterOptionalStringWithNoDefault?: string; + /** + * This is a string that can be null with default + */ + parameterStringNullableWithDefault?: string | null; + /** + * This is a string that can be null with no default + */ + parameterStringNullableWithNoDefault?: string | null; + /** + * This is a string with default + */ + parameterStringWithDefault: string; + /** + * This is a string with empty default + */ + parameterStringWithEmptyDefault: string; + /** + * This is a string with no default + */ + parameterStringWithNoDefault: string; +}; + export type $OpenApiTs = { '/api/v{api-version}/defaults': { get: { diff --git a/packages/openapi-ts/test/__snapshots__/test/generated/v3_services_name/services.gen.ts.snap b/packages/openapi-ts/test/__snapshots__/test/generated/v3_services_name/services.gen.ts.snap index 8d1cbe426..444ebc85d 100644 --- a/packages/openapi-ts/test/__snapshots__/test/generated/v3_services_name/services.gen.ts.snap +++ b/packages/openapi-ts/test/__snapshots__/test/generated/v3_services_name/services.gen.ts.snap @@ -9,7 +9,7 @@ export class myAwesomeSimpleApi { * @returns Model_From_Zendesk Success * @throws ApiError */ - public static apiVVersionOdataControllerCount(): CancelablePromise<$OpenApiTs['/api/v{api-version}/simple/$count']['get']['res'][200]> { + public static apiVVersionOdataControllerCount(): CancelablePromise { return __request(OpenAPI, { method: 'GET', url: '/api/v{api-version}/simple/$count' @@ -95,7 +95,7 @@ export class myAwesomeParametersApi { * @param data.bar bar in method * @throws ApiError */ - public static deleteFoo(data: $OpenApiTs['/api/v{api-version}/foo/{foo}/bar/{bar}']['delete']['req']): CancelablePromise { + public static deleteFoo(data: ParametersDeleteFooData): CancelablePromise { return __request(OpenAPI, { method: 'DELETE', url: '/api/v{api-version}/foo/{foo}/bar/{bar}', @@ -118,7 +118,7 @@ export class myAwesomeParametersApi { * @param data.fooRefEnum * @throws ApiError */ - public static callWithParameters(data: $OpenApiTs['/api/v{api-version}/parameters/{parameterPath}']['post']['req']): CancelablePromise { + public static callWithParameters(data: ParametersCallWithParametersData): CancelablePromise { return __request(OpenAPI, { method: 'POST', url: '/api/v{api-version}/parameters/{parameterPath}', @@ -157,7 +157,7 @@ export class myAwesomeParametersApi { * @param data._default This is the parameter with a reserved keyword * @throws ApiError */ - public static callWithWeirdParameterNames(data: $OpenApiTs['/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}']['post']['req']): CancelablePromise { + public static callWithWeirdParameterNames(data: ParametersCallWithWeirdParameterNamesData): CancelablePromise { return __request(OpenAPI, { method: 'POST', url: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}', @@ -190,7 +190,7 @@ export class myAwesomeParametersApi { * @param data.parameter This is an optional parameter * @throws ApiError */ - public static getCallWithOptionalParam(data: $OpenApiTs['/api/v{api-version}/parameters/']['get']['req']): CancelablePromise { + public static getCallWithOptionalParam(data: ParametersGetCallWithOptionalParamData): CancelablePromise { return __request(OpenAPI, { method: 'GET', url: '/api/v{api-version}/parameters/', @@ -208,7 +208,7 @@ export class myAwesomeParametersApi { * @param data.requestBody This is an optional parameter * @throws ApiError */ - public static postCallWithOptionalParam(data: $OpenApiTs['/api/v{api-version}/parameters/']['post']['req']): CancelablePromise { + public static postCallWithOptionalParam(data: ParametersPostCallWithOptionalParamData): CancelablePromise { return __request(OpenAPI, { method: 'POST', url: '/api/v{api-version}/parameters/', diff --git a/packages/openapi-ts/test/sample.cjs b/packages/openapi-ts/test/sample.cjs index 737fffe1f..18a5234f4 100644 --- a/packages/openapi-ts/test/sample.cjs +++ b/packages/openapi-ts/test/sample.cjs @@ -11,10 +11,10 @@ const main = async () => { export: false, }, services: { - export: false, + // export: false, }, types: { - include: '^DictionaryWithPropertiesAndAdditionalProperties', + // include: '^DictionaryWithPropertiesAndAdditionalProperties', }, };