Skip to content

Commit

Permalink
feat(api-client): void return type for methods with empty schema
Browse files Browse the repository at this point in the history
  • Loading branch information
vmasek committed May 18, 2019
1 parent d14ef9d commit f1977eb
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 43 deletions.
4 changes: 2 additions & 2 deletions src/helper.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Reference } from 'swagger-schema-official';
import { FileInfix } from './types';

export const BASIC_TS_TYPE_REGEX = /\b(?:string|number|integer|boolean)\b/;
const BUILD_IN_TS_TYPE_REGEX = /^(?:string|number|integer|boolean|null|undefined|any|Object|Date|File|Blob)\b/i;
export const BASIC_TS_TYPE_REGEX = /\b(?:string|number|integer|boolean|void)\b/;
const BUILD_IN_TS_TYPE_REGEX = /^(?:string|number|integer|boolean|null|undefined|any|void|Object|Date|File|Blob)\b/i;

export function toCamelCase(text: string = '', lowerFirst: boolean = true): string {
text = removeDuplicateWords(text);
Expand Down
3 changes: 1 addition & 2 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,7 @@ function determineResponseType(response: Response): {
const {schema} = response;

if (schema == null) {
logWarn('200 or 201 response schema not specified; `any` will be used');
return {name: 'any', type: 'any'};
return {name: 'void', type: 'void'};
}

const nullable = (schema as Schema & { 'x-nullable'?: boolean })['x-nullable'] || false;
Expand Down
2 changes: 1 addition & 1 deletion tests/custom/api/api-client.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export interface APIClientInterface {
id: string,
},
requestHttpOptions?: HttpOptions
): Observable<any>;
): Observable<void>;

getCustomers(
requestHttpOptions?: HttpOptions
Expand Down
4 changes: 2 additions & 2 deletions tests/custom/api/api-client.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,14 @@ export class APIClient implements APIClientInterface {
id: string,
},
requestHttpOptions?: HttpOptions
): Observable<any> {
): Observable<void> {
const path = `/pets/${args.id}`;
const options: APIHttpOptions = {
...this.options,
...requestHttpOptions,
};

return this.sendRequest<any>('DELETE', path, options);
return this.sendRequest<void>('DELETE', path, options);
}

getCustomers(
Expand Down
18 changes: 9 additions & 9 deletions tests/esquare/api/api-client.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export interface APIClientInterface {
structureId: number, // structure id to delete
},
requestHttpOptions?: HttpOptions
): Observable<any>;
): Observable<void>;

/**
* [Screenshot from design](http://prntscr.com/hy4z8d)
Expand Down Expand Up @@ -231,7 +231,7 @@ export interface APIClientInterface {
id: number, // Id of current import
},
requestHttpOptions?: HttpOptions
): Observable<any>;
): Observable<void>;

/**
* [Screenshot from design](http://prntscr.com/hy5bi6)
Expand All @@ -244,7 +244,7 @@ export interface APIClientInterface {
file: File, // file to upload
},
requestHttpOptions?: HttpOptions
): Observable<any>;
): Observable<void>;

/**
* [Screenshot from design](http://prntscr.com/i4052r)
Expand Down Expand Up @@ -334,7 +334,7 @@ export interface APIClientInterface {
id: number,
},
requestHttpOptions?: HttpOptions
): Observable<any>;
): Observable<void>;

/**
* [Screenshot from design](http://prntscr.com/i93q0s)
Expand Down Expand Up @@ -379,7 +379,7 @@ export interface APIClientInterface {
id: number,
},
requestHttpOptions?: HttpOptions
): Observable<any>;
): Observable<void>;

/**
* [Screenshot from design](http://prntscr.com/iba7xr)
Expand All @@ -394,7 +394,7 @@ export interface APIClientInterface {
body?: any,
},
requestHttpOptions?: HttpOptions
): Observable<any>;
): Observable<void>;

/**
* [Screenshot from design](http://prntscr.com/iba8tq)
Expand Down Expand Up @@ -447,14 +447,14 @@ export interface APIClientInterface {
id: number,
},
requestHttpOptions?: HttpOptions
): Observable<any>;
): Observable<void>;

disableNotification(
args: {
id: number,
},
requestHttpOptions?: HttpOptions
): Observable<any>;
): Observable<void>;

getNotification(
args: {
Expand All @@ -469,7 +469,7 @@ export interface APIClientInterface {
body?: models.NotificationEditable,
},
requestHttpOptions?: HttpOptions
): Observable<any>;
): Observable<void>;

createNotification(
args: {
Expand Down
36 changes: 18 additions & 18 deletions tests/esquare/api/api-client.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,14 @@ export class APIClient implements APIClientInterface {
structureId: number, // structure id to delete
},
requestHttpOptions?: HttpOptions
): Observable<any> {
): Observable<void> {
const path = `/structure/${args.structureId}`;
const options: APIHttpOptions = {
...this.options,
...requestHttpOptions,
};

return this.sendRequest<any>('DELETE', path, options);
return this.sendRequest<void>('DELETE', path, options);
}

/**
Expand Down Expand Up @@ -484,14 +484,14 @@ export class APIClient implements APIClientInterface {
id: number, // Id of current import
},
requestHttpOptions?: HttpOptions
): Observable<any> {
): Observable<void> {
const path = `/report/wizard/${args.id}/cancelImport`;
const options: APIHttpOptions = {
...this.options,
...requestHttpOptions,
};

return this.sendRequest<any>('POST', path, options);
return this.sendRequest<void>('POST', path, options);
}

/**
Expand All @@ -505,14 +505,14 @@ export class APIClient implements APIClientInterface {
file: File, // file to upload
},
requestHttpOptions?: HttpOptions
): Observable<any> {
): Observable<void> {
const path = `/report/wizard/${args.id}/override`;
const options: APIHttpOptions = {
...this.options,
...requestHttpOptions,
};

return this.sendRequest<any>('POST', path, options, JSON.stringify(args.description), JSON.stringify(args.file));
return this.sendRequest<void>('POST', path, options, JSON.stringify(args.description), JSON.stringify(args.file));
}

/**
Expand Down Expand Up @@ -730,14 +730,14 @@ export class APIClient implements APIClientInterface {
id: number,
},
requestHttpOptions?: HttpOptions
): Observable<any> {
): Observable<void> {
const path = `/users/${args.id}`;
const options: APIHttpOptions = {
...this.options,
...requestHttpOptions,
};

return this.sendRequest<any>('DELETE', path, options);
return this.sendRequest<void>('DELETE', path, options);
}

/**
Expand Down Expand Up @@ -823,14 +823,14 @@ export class APIClient implements APIClientInterface {
id: number,
},
requestHttpOptions?: HttpOptions
): Observable<any> {
): Observable<void> {
const path = `/users/roles/${args.id}`;
const options: APIHttpOptions = {
...this.options,
...requestHttpOptions,
};

return this.sendRequest<any>('DELETE', path, options);
return this.sendRequest<void>('DELETE', path, options);
}

/**
Expand All @@ -854,14 +854,14 @@ export class APIClient implements APIClientInterface {
body?: any,
},
requestHttpOptions?: HttpOptions
): Observable<any> {
): Observable<void> {
const path = `/notifications/markAsViewed`;
const options: APIHttpOptions = {
...this.options,
...requestHttpOptions,
};

return this.sendRequest<any>('PUT', path, options, JSON.stringify(args.body));
return this.sendRequest<void>('PUT', path, options, JSON.stringify(args.body));
}

/**
Expand Down Expand Up @@ -971,29 +971,29 @@ export class APIClient implements APIClientInterface {
id: number,
},
requestHttpOptions?: HttpOptions
): Observable<any> {
): Observable<void> {
const path = `/notifications/enable/${args.id}`;
const options: APIHttpOptions = {
...this.options,
...requestHttpOptions,
};

return this.sendRequest<any>('PUT', path, options);
return this.sendRequest<void>('PUT', path, options);
}

disableNotification(
args: {
id: number,
},
requestHttpOptions?: HttpOptions
): Observable<any> {
): Observable<void> {
const path = `/notifications/disable/${args.id}`;
const options: APIHttpOptions = {
...this.options,
...requestHttpOptions,
};

return this.sendRequest<any>('PUT', path, options);
return this.sendRequest<void>('PUT', path, options);
}

getNotification(
Expand All @@ -1017,14 +1017,14 @@ export class APIClient implements APIClientInterface {
body?: models.NotificationEditable,
},
requestHttpOptions?: HttpOptions
): Observable<any> {
): Observable<void> {
const path = `/notifications/${args.id}`;
const options: APIHttpOptions = {
...this.options,
...requestHttpOptions,
};

return this.sendRequest<any>('PUT', path, options, JSON.stringify(args.body));
return this.sendRequest<void>('PUT', path, options, JSON.stringify(args.body));
}

createNotification(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface MarkdownAPIClientInterface {
body: models.Markdown,
},
requestHttpOptions?: HttpOptions
): Observable<any>;
): Observable<void>;

/**
* Render a Markdown document in raw mode
Expand All @@ -35,6 +35,6 @@ export interface MarkdownAPIClientInterface {
xGitHubRequestId?: number,
},
requestHttpOptions?: HttpOptions
): Observable<any>;
): Observable<void>;

}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class MarkdownAPIClient implements MarkdownAPIClientInterface {
body: models.Markdown,
},
requestHttpOptions?: HttpOptions
): Observable<any> {
): Observable<void> {
const path = `/markdown`;
const options: APIHttpOptions = {
...this.options,
Expand All @@ -81,7 +81,7 @@ export class MarkdownAPIClient implements MarkdownAPIClientInterface {
if ('xGitHubRequestId' in args) {
options.headers = options.headers.set('X-GitHub-Request-Id', String(args.xGitHubRequestId));
}
return this.sendRequest<any>('POST', path, options, JSON.stringify(args.body));
return this.sendRequest<void>('POST', path, options, JSON.stringify(args.body));
}

/**
Expand All @@ -97,7 +97,7 @@ export class MarkdownAPIClient implements MarkdownAPIClientInterface {
xGitHubRequestId?: number,
},
requestHttpOptions?: HttpOptions
): Observable<any> {
): Observable<void> {
const path = `/markdown/raw`;
const options: APIHttpOptions = {
...this.options,
Expand All @@ -122,7 +122,7 @@ export class MarkdownAPIClient implements MarkdownAPIClientInterface {
if ('xGitHubRequestId' in args) {
options.headers = options.headers.set('X-GitHub-Request-Id', String(args.xGitHubRequestId));
}
return this.sendRequest<any>('POST', path, options);
return this.sendRequest<void>('POST', path, options);
}

private sendRequest<T>(method: string, path: string, options: HttpOptions, body?: any): Observable<T> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ export interface ReposAPIClientInterface {
body: models.DeploymentStatusesCreate,
},
requestHttpOptions?: HttpOptions
): Observable<any>;
): Observable<void>;

/**
* Deprecated. List downloads for a repository.
Expand Down
4 changes: 2 additions & 2 deletions tests/github/api/services/repos/repos-api-client.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1348,7 +1348,7 @@ export class ReposAPIClient implements ReposAPIClientInterface {
body: models.DeploymentStatusesCreate,
},
requestHttpOptions?: HttpOptions
): Observable<any> {
): Observable<void> {
const path = `/repos/${args.owner}/${args.repo}/deployments/${args.id}/statuses`;
const options: APIHttpOptions = {
...this.options,
Expand All @@ -1373,7 +1373,7 @@ export class ReposAPIClient implements ReposAPIClientInterface {
if ('xGitHubRequestId' in args) {
options.headers = options.headers.set('X-GitHub-Request-Id', String(args.xGitHubRequestId));
}
return this.sendRequest<any>('POST', path, options, JSON.stringify(args.body));
return this.sendRequest<void>('POST', path, options, JSON.stringify(args.body));
}

/**
Expand Down

0 comments on commit f1977eb

Please sign in to comment.