From d42f27c9f565b774b01dcdcd70480dea396ab466 Mon Sep 17 00:00:00 2001 From: Lars Hvam Date: Tue, 17 Mar 2020 22:04:30 +0100 Subject: [PATCH] [typescript-fetch] add interfaces, withInterfaces (#5612) * typescript-fetch: interfaces, first draft * fix name in description --- .../resources/typescript-fetch/apis.mustache | 49 +++++++ .../builds/with-interfaces/apis/PetApi.ts | 138 +++++++++++++++++- .../builds/with-interfaces/apis/StoreApi.ts | 72 ++++++++- .../builds/with-interfaces/apis/UserApi.ts | 134 ++++++++++++++++- 4 files changed, 390 insertions(+), 3 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/typescript-fetch/apis.mustache b/modules/openapi-generator/src/main/resources/typescript-fetch/apis.mustache index 5bc1efdf160..881f1b7ab52 100644 --- a/modules/openapi-generator/src/main/resources/typescript-fetch/apis.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-fetch/apis.mustache @@ -25,11 +25,60 @@ export interface {{#prefixParameterInterfaces}}{{classname}}{{/prefixParameterIn {{/allParams.0}} {{/operation}} {{/operations}} +{{#withInterfaces}} +{{#operations}} +/** + * {{classname}} - interface{{#description}} + * {{&description}}{{/description}} + * @export + * @interface {{classname}}Interface + */ +export interface {{classname}}Interface { +{{#operation}} + /** + * {{¬es}} + {{#summary}} + * @summary {{&summary}} + {{/summary}} + {{#allParams}} + * @param {{=<% %>=}}{<%&dataType%>}<%={{ }}=%> {{^required}}[{{/required}}{{paramName}}{{^required}}]{{/required}} {{description}} + {{/allParams}} + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof {{classname}}Interface + */ + {{nickname}}Raw({{#allParams.0}}requestParameters: {{#prefixParameterInterfaces}}{{classname}}{{/prefixParameterInterfaces}}{{operationIdCamelCase}}Request{{/allParams.0}}): Promise>; + + /** + {{#notes}} + * {{¬es}} + {{/notes}} + {{#summary}} + * {{&summary}} + {{/summary}} + */ + {{^useSingleRequestParameter}} + {{nickname}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{#isNullable}} | null{{/isNullable}}{{/isEnum}}{{#hasMore}}, {{/hasMore}}{{/allParams}}): Promise<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}>; + {{/useSingleRequestParameter}} + {{#useSingleRequestParameter}} + {{nickname}}({{#allParams.0}}requestParameters: {{#prefixParameterInterfaces}}{{classname}}{{/prefixParameterInterfaces}}{{operationIdCamelCase}}Request{{/allParams.0}}): Promise<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}>; + {{/useSingleRequestParameter}} + +{{/operation}} +} + +{{/operations}} +{{/withInterfaces}} {{#operations}} /** * {{#description}}{{{description}}}{{/description}}{{^description}}no description{{/description}} */ +{{#withInterfaces}} +export class {{classname}} extends runtime.BaseAPI implements {{classname}}Interface { +{{/withInterfaces}} +{{^withInterfaces}} export class {{classname}} extends runtime.BaseAPI { +{{/withInterfaces}} {{#operation}} /** diff --git a/samples/client/petstore/typescript-fetch/builds/with-interfaces/apis/PetApi.ts b/samples/client/petstore/typescript-fetch/builds/with-interfaces/apis/PetApi.ts index 9f337889932..3aaa0da493a 100644 --- a/samples/client/petstore/typescript-fetch/builds/with-interfaces/apis/PetApi.ts +++ b/samples/client/petstore/typescript-fetch/builds/with-interfaces/apis/PetApi.ts @@ -60,10 +60,146 @@ export interface UploadFileRequest { file?: Blob; } +/** + * PetApi - interface + * @export + * @interface PetApiInterface + */ +export interface PetApiInterface { + /** + * + * @summary Add a new pet to the store + * @param {Pet} body Pet object that needs to be added to the store + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof PetApiInterface + */ + addPetRaw(requestParameters: AddPetRequest): Promise>; + + /** + * Add a new pet to the store + */ + addPet(requestParameters: AddPetRequest): Promise; + + /** + * + * @summary Deletes a pet + * @param {number} petId Pet id to delete + * @param {string} [apiKey] + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof PetApiInterface + */ + deletePetRaw(requestParameters: DeletePetRequest): Promise>; + + /** + * Deletes a pet + */ + deletePet(requestParameters: DeletePetRequest): Promise; + + /** + * Multiple status values can be provided with comma separated strings + * @summary Finds Pets by status + * @param {Array<'available' | 'pending' | 'sold'>} status Status values that need to be considered for filter + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof PetApiInterface + */ + findPetsByStatusRaw(requestParameters: FindPetsByStatusRequest): Promise>>; + + /** + * Multiple status values can be provided with comma separated strings + * Finds Pets by status + */ + findPetsByStatus(requestParameters: FindPetsByStatusRequest): Promise>; + + /** + * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. + * @summary Finds Pets by tags + * @param {Array} tags Tags to filter by + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof PetApiInterface + */ + findPetsByTagsRaw(requestParameters: FindPetsByTagsRequest): Promise>>; + + /** + * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. + * Finds Pets by tags + */ + findPetsByTags(requestParameters: FindPetsByTagsRequest): Promise>; + + /** + * Returns a single pet + * @summary Find pet by ID + * @param {number} petId ID of pet to return + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof PetApiInterface + */ + getPetByIdRaw(requestParameters: GetPetByIdRequest): Promise>; + + /** + * Returns a single pet + * Find pet by ID + */ + getPetById(requestParameters: GetPetByIdRequest): Promise; + + /** + * + * @summary Update an existing pet + * @param {Pet} body Pet object that needs to be added to the store + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof PetApiInterface + */ + updatePetRaw(requestParameters: UpdatePetRequest): Promise>; + + /** + * Update an existing pet + */ + updatePet(requestParameters: UpdatePetRequest): Promise; + + /** + * + * @summary Updates a pet in the store with form data + * @param {number} petId ID of pet that needs to be updated + * @param {string} [name] Updated name of the pet + * @param {string} [status] Updated status of the pet + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof PetApiInterface + */ + updatePetWithFormRaw(requestParameters: UpdatePetWithFormRequest): Promise>; + + /** + * Updates a pet in the store with form data + */ + updatePetWithForm(requestParameters: UpdatePetWithFormRequest): Promise; + + /** + * + * @summary uploads an image + * @param {number} petId ID of pet to update + * @param {string} [additionalMetadata] Additional data to pass to server + * @param {Blob} [file] file to upload + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof PetApiInterface + */ + uploadFileRaw(requestParameters: UploadFileRequest): Promise>; + + /** + * uploads an image + */ + uploadFile(requestParameters: UploadFileRequest): Promise; + +} + /** * no description */ -export class PetApi extends runtime.BaseAPI { +export class PetApi extends runtime.BaseAPI implements PetApiInterface { /** * Add a new pet to the store diff --git a/samples/client/petstore/typescript-fetch/builds/with-interfaces/apis/StoreApi.ts b/samples/client/petstore/typescript-fetch/builds/with-interfaces/apis/StoreApi.ts index 4d281723815..5c379a79098 100644 --- a/samples/client/petstore/typescript-fetch/builds/with-interfaces/apis/StoreApi.ts +++ b/samples/client/petstore/typescript-fetch/builds/with-interfaces/apis/StoreApi.ts @@ -32,10 +32,80 @@ export interface PlaceOrderRequest { body: Order; } +/** + * StoreApi - interface + * @export + * @interface StoreApiInterface + */ +export interface StoreApiInterface { + /** + * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + * @summary Delete purchase order by ID + * @param {string} orderId ID of the order that needs to be deleted + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof StoreApiInterface + */ + deleteOrderRaw(requestParameters: DeleteOrderRequest): Promise>; + + /** + * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + * Delete purchase order by ID + */ + deleteOrder(requestParameters: DeleteOrderRequest): Promise; + + /** + * Returns a map of status codes to quantities + * @summary Returns pet inventories by status + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof StoreApiInterface + */ + getInventoryRaw(): Promise>; + + /** + * Returns a map of status codes to quantities + * Returns pet inventories by status + */ + getInventory(): Promise<{ [key: string]: number; }>; + + /** + * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions + * @summary Find purchase order by ID + * @param {number} orderId ID of pet that needs to be fetched + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof StoreApiInterface + */ + getOrderByIdRaw(requestParameters: GetOrderByIdRequest): Promise>; + + /** + * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions + * Find purchase order by ID + */ + getOrderById(requestParameters: GetOrderByIdRequest): Promise; + + /** + * + * @summary Place an order for a pet + * @param {Order} body order placed for purchasing the pet + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof StoreApiInterface + */ + placeOrderRaw(requestParameters: PlaceOrderRequest): Promise>; + + /** + * Place an order for a pet + */ + placeOrder(requestParameters: PlaceOrderRequest): Promise; + +} + /** * no description */ -export class StoreApi extends runtime.BaseAPI { +export class StoreApi extends runtime.BaseAPI implements StoreApiInterface { /** * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors diff --git a/samples/client/petstore/typescript-fetch/builds/with-interfaces/apis/UserApi.ts b/samples/client/petstore/typescript-fetch/builds/with-interfaces/apis/UserApi.ts index e5441f0aaf1..43bb1ebc032 100644 --- a/samples/client/petstore/typescript-fetch/builds/with-interfaces/apis/UserApi.ts +++ b/samples/client/petstore/typescript-fetch/builds/with-interfaces/apis/UserApi.ts @@ -50,10 +50,142 @@ export interface UpdateUserRequest { body: User; } +/** + * UserApi - interface + * @export + * @interface UserApiInterface + */ +export interface UserApiInterface { + /** + * This can only be done by the logged in user. + * @summary Create user + * @param {User} body Created user object + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof UserApiInterface + */ + createUserRaw(requestParameters: CreateUserRequest): Promise>; + + /** + * This can only be done by the logged in user. + * Create user + */ + createUser(requestParameters: CreateUserRequest): Promise; + + /** + * + * @summary Creates list of users with given input array + * @param {Array} body List of user object + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof UserApiInterface + */ + createUsersWithArrayInputRaw(requestParameters: CreateUsersWithArrayInputRequest): Promise>; + + /** + * Creates list of users with given input array + */ + createUsersWithArrayInput(requestParameters: CreateUsersWithArrayInputRequest): Promise; + + /** + * + * @summary Creates list of users with given input array + * @param {Array} body List of user object + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof UserApiInterface + */ + createUsersWithListInputRaw(requestParameters: CreateUsersWithListInputRequest): Promise>; + + /** + * Creates list of users with given input array + */ + createUsersWithListInput(requestParameters: CreateUsersWithListInputRequest): Promise; + + /** + * This can only be done by the logged in user. + * @summary Delete user + * @param {string} username The name that needs to be deleted + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof UserApiInterface + */ + deleteUserRaw(requestParameters: DeleteUserRequest): Promise>; + + /** + * This can only be done by the logged in user. + * Delete user + */ + deleteUser(requestParameters: DeleteUserRequest): Promise; + + /** + * + * @summary Get user by user name + * @param {string} username The name that needs to be fetched. Use user1 for testing. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof UserApiInterface + */ + getUserByNameRaw(requestParameters: GetUserByNameRequest): Promise>; + + /** + * Get user by user name + */ + getUserByName(requestParameters: GetUserByNameRequest): Promise; + + /** + * + * @summary Logs user into the system + * @param {string} username The user name for login + * @param {string} password The password for login in clear text + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof UserApiInterface + */ + loginUserRaw(requestParameters: LoginUserRequest): Promise>; + + /** + * Logs user into the system + */ + loginUser(requestParameters: LoginUserRequest): Promise; + + /** + * + * @summary Logs out current logged in user session + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof UserApiInterface + */ + logoutUserRaw(): Promise>; + + /** + * Logs out current logged in user session + */ + logoutUser(): Promise; + + /** + * This can only be done by the logged in user. + * @summary Updated user + * @param {string} username name that need to be deleted + * @param {User} body Updated user object + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof UserApiInterface + */ + updateUserRaw(requestParameters: UpdateUserRequest): Promise>; + + /** + * This can only be done by the logged in user. + * Updated user + */ + updateUser(requestParameters: UpdateUserRequest): Promise; + +} + /** * no description */ -export class UserApi extends runtime.BaseAPI { +export class UserApi extends runtime.BaseAPI implements UserApiInterface { /** * This can only be done by the logged in user.