forked from loafle/openapi-generator-original
[typescript-rxjs] add support for raw response and progressSubscriber (#5465)
* feat(typescript-rxjs): add support for returning statusCode and progressSubscriber via function overloading * feat(typescript-rxjs): use ?? instead of || to support relative basePath of "", upgrade to typescript 3.7 * feat(typescript-rxjs): regenerate samples * refactor(typescript-rxjs): change explicit undefined checks to shorthand return * feat(typescript-rxjs): add missing progressSubscriber key when building RequestArgs * feat(typescript-rxjs): regenerate samples * style(typescript-rxjs): remove whitespace, add colons * feat(typescript-rxjs): regenerate samples * refactor(typescript-rxjs): destructure configuration in BaseApi * fix(typescript-rxjs): returning empty string for apiKey and accessToken * feat(typescript-rxjs): replace withStatusCode option with response = raw option, reuse rxjs AjaxRequest and AjaxResponse types * feat(typescript-rxjs): regenerate samples * Prints out the parameter name in throwIfNullOrUndefined * Fixed misspelling * feat(typescript-rxjs): add withProgressSubscriber additional-properties flag to cli, remove unused withInterfaces flag * refactor(typescript-rxjs): use backticks instead of String constructor in encodeURI * feat(typescript-rxjs): replace Object.keys() with Object.entries() in queryString helper * style(typescript-rxjs): improve indentation of new withProgressSubscriber checks within templates * feat(typescript-rxjs): use entire es2017 lib in tsconfig.json for building with target es6 * feat(typescript-rxjs): regenerate samples * feat(typescript-rxjs): adjust sample generation, regenerate samples * docs(typescript-rxjs): regenerate docs Co-authored-by: Justin Van Dort <justinvandort@gmail.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
generatorName: typescript-rxjs
|
||||
outputDir: samples/client/petstore/typescript-rxjs/builds/with-interfaces
|
||||
outputDir: samples/client/petstore/typescript-rxjs/builds/with-progress-subscriber
|
||||
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore.yaml
|
||||
additionalProperties:
|
||||
withInterfaces: "true"
|
||||
withProgressSubscriber: "true"
|
||||
@@ -21,7 +21,7 @@ sidebar_label: typescript-rxjs
|
||||
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
|
||||
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
|
||||
|supportsES6|Generate code that conforms to ES6.| |false|
|
||||
|withInterfaces|Setting this property to true will generate interfaces next to the default class implementations.| |false|
|
||||
|withProgressSubscriber|Setting this property to true will generate API controller methods with support for subscribing to request progress.| |false|
|
||||
|
||||
## IMPORT MAPPING
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ public class TypeScriptRxjsClientCodegen extends AbstractTypeScriptClientCodegen
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractTypeScriptClientCodegen.class);
|
||||
|
||||
public static final String NPM_REPOSITORY = "npmRepository";
|
||||
public static final String WITH_INTERFACES = "withInterfaces";
|
||||
public static final String WITH_PROGRESS_SUBSCRIBER = "withProgressSubscriber";
|
||||
|
||||
protected String npmRepository = null;
|
||||
protected Set<String> reservedParamNames = new HashSet<>();
|
||||
@@ -60,7 +60,7 @@ public class TypeScriptRxjsClientCodegen extends AbstractTypeScriptClientCodegen
|
||||
typeMapping.put("file", "Blob");
|
||||
|
||||
this.cliOptions.add(new CliOption(NPM_REPOSITORY, "Use this property to set an url your private npmRepo in the package.json"));
|
||||
this.cliOptions.add(new CliOption(WITH_INTERFACES, "Setting this property to true will generate interfaces next to the default class implementations.", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString()));
|
||||
this.cliOptions.add(new CliOption(WITH_PROGRESS_SUBSCRIBER, "Setting this property to true will generate API controller methods with support for subscribing to request progress.", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString()));
|
||||
|
||||
// these are used in the api template for more efficient destructuring
|
||||
this.reservedParamNames.add("headers");
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// tslint:disable
|
||||
{{>licenseInfo}}
|
||||
import { Observable } from 'rxjs';
|
||||
import { BaseAPI{{#hasHttpHeaders}}, HttpHeaders{{/hasHttpHeaders}}{{#hasQueryParams}}, HttpQuery{{/hasQueryParams}}{{#hasRequiredParams}}, throwIfNullOrUndefined{{/hasRequiredParams}}{{#hasPathParams}}, encodeURI{{/hasPathParams}}{{#hasListContainers}}, COLLECTION_FORMATS{{/hasListContainers}} } from '../runtime';
|
||||
import { BaseAPI{{#hasHttpHeaders}}, HttpHeaders{{/hasHttpHeaders}}{{#hasQueryParams}}, HttpQuery{{/hasQueryParams}}{{#hasRequiredParams}}, throwIfNullOrUndefined{{/hasRequiredParams}}{{#hasPathParams}}, encodeURI{{/hasPathParams}}{{#hasListContainers}}, COLLECTION_FORMATS{{/hasListContainers}}, OperationOpts, RawAjaxResponse } from '../runtime';
|
||||
{{#imports.0}}
|
||||
import {
|
||||
{{#imports}}
|
||||
@@ -37,7 +37,12 @@ export class {{classname}} extends BaseAPI {
|
||||
* {{&summary}}
|
||||
{{/summary}}
|
||||
*/
|
||||
{{nickname}} = ({{#allParams.0}}{ {{#allParams}}{{paramName}}{{#vendorExtensions.x-param-name-alternative}}: {{vendorExtensions.x-param-name-alternative}}{{/vendorExtensions.x-param-name-alternative}}{{^-last}}, {{/-last}}{{/allParams}} }: {{operationIdCamelCase}}Request{{/allParams.0}}): Observable<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}> => {
|
||||
{{nickname}}({{#allParams.0}}{ {{#allParams}}{{paramName}}{{#vendorExtensions.x-param-name-alternative}}: {{vendorExtensions.x-param-name-alternative}}{{/vendorExtensions.x-param-name-alternative}}{{^-last}}, {{/-last}}{{/allParams}} }: {{operationIdCamelCase}}Request{{/allParams.0}}): Observable<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}>
|
||||
{{#withProgressSubscriber}}
|
||||
{{nickname}}({{#allParams.0}}{ {{#allParams}}{{paramName}}{{#vendorExtensions.x-param-name-alternative}}: {{vendorExtensions.x-param-name-alternative}}{{/vendorExtensions.x-param-name-alternative}}{{^-last}}, {{/-last}}{{/allParams}} }: {{operationIdCamelCase}}Request, {{/allParams.0}}opts?: Pick<OperationOpts, 'progressSubscriber'>): Observable<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}>
|
||||
{{/withProgressSubscriber}}
|
||||
{{nickname}}({{#allParams.0}}{ {{#allParams}}{{paramName}}{{#vendorExtensions.x-param-name-alternative}}: {{vendorExtensions.x-param-name-alternative}}{{/vendorExtensions.x-param-name-alternative}}{{^-last}}, {{/-last}}{{/allParams}} }: {{operationIdCamelCase}}Request, {{/allParams.0}}opts?: OperationOpts): Observable<{{#returnType}}RawAjaxResponse<{{{returnType}}}>{{/returnType}}{{^returnType}}void | RawAjaxResponse<void>{{/returnType}}>
|
||||
{{nickname}}({{#allParams.0}}{ {{#allParams}}{{paramName}}{{#vendorExtensions.x-param-name-alternative}}: {{vendorExtensions.x-param-name-alternative}}{{/vendorExtensions.x-param-name-alternative}}{{^-last}}, {{/-last}}{{/allParams}} }: {{operationIdCamelCase}}Request, {{/allParams.0}}opts?: OperationOpts): Observable<{{#returnType}}{{{returnType}}} | RawAjaxResponse<{{{returnType}}}>{{/returnType}}{{^returnType}}void | RawAjaxResponse<void>{{/returnType}}> {
|
||||
{{#hasParams}}
|
||||
{{#allParams}}
|
||||
{{#required}}
|
||||
@@ -177,7 +182,7 @@ export class {{classname}} extends BaseAPI {
|
||||
|
||||
{{/hasFormParams}}
|
||||
return this.request<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}>({
|
||||
path: '{{{path}}}'{{#pathParams}}.replace({{=<% %>=}}'{<%baseName%>}'<%={{ }}=%>, encodeURI({{> paramNamePartial}})){{/pathParams}},
|
||||
url: '{{{path}}}'{{#pathParams}}.replace({{=<% %>=}}'{<%baseName%>}'<%={{ }}=%>, encodeURI({{> paramNamePartial}})){{/pathParams}},
|
||||
method: '{{httpMethod}}',
|
||||
{{#hasHttpHeaders}}
|
||||
headers,
|
||||
@@ -204,9 +209,12 @@ export class {{classname}} extends BaseAPI {
|
||||
body: formData,
|
||||
{{/hasFormParams}}
|
||||
{{#isResponseFile}}
|
||||
responseType: 'blob'
|
||||
responseType: 'blob',
|
||||
{{/isResponseFile}}
|
||||
});
|
||||
{{#withProgressSubscriber}}
|
||||
progressSubscriber: opts?.progressSubscriber,
|
||||
{{/withProgressSubscriber}}
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
{{/operation}}
|
||||
|
||||
@@ -6,14 +6,14 @@
|
||||
"main": "./dist/index.js",
|
||||
"typings": "./dist/index.d.ts",
|
||||
"scripts" : {
|
||||
"build": "tsc --outDir dist/",
|
||||
"build": "node_modules/.bin/tsc --outDir dist/",
|
||||
"prepare": "npm run build"
|
||||
},
|
||||
"dependencies": {
|
||||
"rxjs": "^6.3.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^3.0.1"
|
||||
"typescript": "^3.7"
|
||||
}{{#npmRepository}},{{/npmRepository}}
|
||||
{{#npmRepository}}
|
||||
"publishConfig": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// tslint:disable
|
||||
{{>licenseInfo}}
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { Observable, of, Subscriber } from 'rxjs';
|
||||
import { ajax, AjaxRequest, AjaxResponse } from 'rxjs/ajax';
|
||||
import { map, concatMap } from 'rxjs/operators';
|
||||
|
||||
@@ -19,11 +19,11 @@ export class Configuration {
|
||||
constructor(private configuration: ConfigurationParameters = {}) {}
|
||||
|
||||
get basePath(): string {
|
||||
return this.configuration.basePath || BASE_PATH;
|
||||
return this.configuration.basePath ?? BASE_PATH;
|
||||
}
|
||||
|
||||
get middleware(): Middleware[] {
|
||||
return this.configuration.middleware || [];
|
||||
return this.configuration.middleware ?? [];
|
||||
}
|
||||
|
||||
get username(): string | undefined {
|
||||
@@ -36,18 +36,12 @@ export class Configuration {
|
||||
|
||||
get apiKey(): ((name: string) => string) | undefined {
|
||||
const { apiKey } = this.configuration;
|
||||
if (!apiKey) {
|
||||
return undefined;
|
||||
}
|
||||
return typeof apiKey === 'string' ? () => apiKey : apiKey;
|
||||
return apiKey ? (typeof apiKey === 'string' ? () => apiKey : apiKey) : undefined;
|
||||
}
|
||||
|
||||
get accessToken(): ((name: string, scopes?: string[]) => string) | undefined {
|
||||
const { accessToken } = this.configuration;
|
||||
if (!accessToken) {
|
||||
return undefined;
|
||||
}
|
||||
return typeof accessToken === 'string' ? () => accessToken : accessToken;
|
||||
return accessToken ? (typeof accessToken === 'string' ? () => accessToken : accessToken) : undefined;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,31 +67,35 @@ export class BaseAPI {
|
||||
withPostMiddleware = (postMiddlewares: Array<Middleware['post']>) =>
|
||||
this.withMiddleware(postMiddlewares.map((post) => ({ post })));
|
||||
|
||||
protected request = <T>(requestOpts: RequestOpts): Observable<T> =>
|
||||
this.rxjsRequest(this.createRequestArgs(requestOpts)).pipe(
|
||||
protected request<T>(requestOpts: RequestOpts): Observable<T>
|
||||
protected request<T>(requestOpts: RequestOpts, responseOpts?: ResponseOpts): Observable<RawAjaxResponse<T>>
|
||||
protected request<T>(requestOpts: RequestOpts, responseOpts?: ResponseOpts): Observable<T | RawAjaxResponse<T>> {
|
||||
return this.rxjsRequest(this.createRequestArgs(requestOpts)).pipe(
|
||||
map((res) => {
|
||||
if (res.status >= 200 && res.status < 300) {
|
||||
return res.response as T;
|
||||
const { status, response } = res;
|
||||
if (status >= 200 && status < 300) {
|
||||
return responseOpts?.respone === 'raw' ? res : response;
|
||||
}
|
||||
throw res;
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
private createRequestArgs = (requestOpts: RequestOpts): RequestArgs => {
|
||||
let url = this.configuration.basePath + requestOpts.path;
|
||||
if (requestOpts.query !== undefined && Object.keys(requestOpts.query).length !== 0) {
|
||||
// only add the queryString to the URL if there are query parameters.
|
||||
// this is done to avoid urls ending with a '?' character which buggy webservers
|
||||
// do not handle correctly sometimes.
|
||||
url += '?' + queryString(requestOpts.query);
|
||||
}
|
||||
private createRequestArgs = ({ url: baseUrl, query, method, headers, body, responseType{{#withProgressSubscriber}}, progressSubscriber{{/withProgressSubscriber}} }: RequestOpts): RequestArgs => {
|
||||
// only add the queryString to the URL if there are query parameters.
|
||||
// this is done to avoid urls ending with a '?' character which buggy webservers
|
||||
// do not handle correctly sometimes.
|
||||
const url = `${this.configuration.basePath}${baseUrl}${query && Object.keys(query).length ? `?${queryString(query)}`: ''}`;
|
||||
|
||||
return {
|
||||
url,
|
||||
method: requestOpts.method,
|
||||
headers: requestOpts.headers,
|
||||
body: requestOpts.body instanceof FormData ? requestOpts.body : JSON.stringify(requestOpts.body),
|
||||
responseType: requestOpts.responseType || 'json',
|
||||
method,
|
||||
headers,
|
||||
body: body instanceof FormData ? body : JSON.stringify(body),
|
||||
responseType: responseType ?? 'json',
|
||||
{{#withProgressSubscriber}}
|
||||
progressSubscriber,
|
||||
{{/withProgressSubscriber}}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -146,24 +144,41 @@ export type HttpHeaders = { [key: string]: string };
|
||||
export type HttpQuery = Partial<{ [key: string]: string | number | null | boolean | Array<string | number | null | boolean> }>; // partial is needed for strict mode
|
||||
export type HttpBody = Json | FormData;
|
||||
|
||||
export interface RequestOpts {
|
||||
path: string;
|
||||
export interface RequestOpts extends AjaxRequest {
|
||||
query?: HttpQuery; // additional prop
|
||||
// the following props have improved types over AjaxRequest
|
||||
method: HttpMethod;
|
||||
headers?: HttpHeaders;
|
||||
query?: HttpQuery;
|
||||
body?: HttpBody;
|
||||
responseType?: 'json' | 'blob' | 'arraybuffer' | 'text';
|
||||
{{#withProgressSubscriber}}
|
||||
progressSubscriber?: Subscriber<ProgressEvent>;
|
||||
{{/withProgressSubscriber}}
|
||||
}
|
||||
|
||||
export const encodeURI = (value: any) => encodeURIComponent(String(value));
|
||||
export interface ResponseOpts {
|
||||
respone?: 'raw';
|
||||
}
|
||||
|
||||
const queryString = (params: HttpQuery): string => Object.keys(params)
|
||||
.map((key) => {
|
||||
const value = params[key];
|
||||
return (value instanceof Array)
|
||||
? value.map((val) => `${encodeURI(key)}=${encodeURI(val)}`).join('&')
|
||||
: `${encodeURI(key)}=${encodeURI(value)}`;
|
||||
})
|
||||
export interface OperationOpts {
|
||||
{{#withProgressSubscriber}}
|
||||
progressSubscriber?: Subscriber<ProgressEvent>;
|
||||
{{/withProgressSubscriber}}
|
||||
responseOpts?: ResponseOpts;
|
||||
}
|
||||
|
||||
// AjaxResponse with typed response
|
||||
export interface RawAjaxResponse<T> extends AjaxResponse {
|
||||
response: T;
|
||||
}
|
||||
|
||||
export const encodeURI = (value: any) => encodeURIComponent(`${value}`);
|
||||
|
||||
const queryString = (params: HttpQuery): string => Object.entries(params)
|
||||
.map(([key, value]) => value instanceof Array
|
||||
? value.map((val) => `${encodeURI(key)}=${encodeURI(val)}`).join('&')
|
||||
: `${encodeURI(key)}=${encodeURI(value)}`
|
||||
)
|
||||
.join('&');
|
||||
|
||||
// alias fallback for not being a breaking change
|
||||
|
||||
@@ -6,12 +6,13 @@
|
||||
"moduleResolution": "node",
|
||||
"outDir": "dist",
|
||||
"rootDir": ".",
|
||||
{{^supportsES6}}
|
||||
"lib": [
|
||||
{{^supportsES6}}
|
||||
"es6",
|
||||
"dom"
|
||||
{{/supportsES6}}
|
||||
"dom",
|
||||
"es2017"
|
||||
],
|
||||
{{/supportsES6}}
|
||||
"typeRoots": [
|
||||
"node_modules/@types"
|
||||
]
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
*/
|
||||
|
||||
import { Observable } from 'rxjs';
|
||||
import { BaseAPI, HttpHeaders, HttpQuery, throwIfNullOrUndefined, encodeURI, COLLECTION_FORMATS } from '../runtime';
|
||||
import { BaseAPI, HttpHeaders, HttpQuery, throwIfNullOrUndefined, encodeURI, COLLECTION_FORMATS, OperationOpts, RawAjaxResponse } from '../runtime';
|
||||
import {
|
||||
ApiResponse,
|
||||
Pet,
|
||||
@@ -63,7 +63,9 @@ export class PetApi extends BaseAPI {
|
||||
/**
|
||||
* Add a new pet to the store
|
||||
*/
|
||||
addPet = ({ body }: AddPetRequest): Observable<void> => {
|
||||
addPet({ body }: AddPetRequest): Observable<void>
|
||||
addPet({ body }: AddPetRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>>
|
||||
addPet({ body }: AddPetRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>> {
|
||||
throwIfNullOrUndefined(body, 'body', 'addPet');
|
||||
|
||||
const headers: HttpHeaders = {
|
||||
@@ -78,17 +80,19 @@ export class PetApi extends BaseAPI {
|
||||
};
|
||||
|
||||
return this.request<void>({
|
||||
path: '/pet',
|
||||
url: '/pet',
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: body,
|
||||
});
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* Deletes a pet
|
||||
*/
|
||||
deletePet = ({ petId, apiKey }: DeletePetRequest): Observable<void> => {
|
||||
deletePet({ petId, apiKey }: DeletePetRequest): Observable<void>
|
||||
deletePet({ petId, apiKey }: DeletePetRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>>
|
||||
deletePet({ petId, apiKey }: DeletePetRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>> {
|
||||
throwIfNullOrUndefined(petId, 'petId', 'deletePet');
|
||||
|
||||
const headers: HttpHeaders = {
|
||||
@@ -103,17 +107,19 @@ export class PetApi extends BaseAPI {
|
||||
};
|
||||
|
||||
return this.request<void>({
|
||||
path: '/pet/{petId}'.replace('{petId}', encodeURI(petId)),
|
||||
url: '/pet/{petId}'.replace('{petId}', encodeURI(petId)),
|
||||
method: 'DELETE',
|
||||
headers,
|
||||
});
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* Multiple status values can be provided with comma separated strings
|
||||
* Finds Pets by status
|
||||
*/
|
||||
findPetsByStatus = ({ status }: FindPetsByStatusRequest): Observable<Array<Pet>> => {
|
||||
findPetsByStatus({ status }: FindPetsByStatusRequest): Observable<Array<Pet>>
|
||||
findPetsByStatus({ status }: FindPetsByStatusRequest, opts?: OperationOpts): Observable<RawAjaxResponse<Array<Pet>>>
|
||||
findPetsByStatus({ status }: FindPetsByStatusRequest, opts?: OperationOpts): Observable<Array<Pet> | RawAjaxResponse<Array<Pet>>> {
|
||||
throwIfNullOrUndefined(status, 'status', 'findPetsByStatus');
|
||||
|
||||
const headers: HttpHeaders = {
|
||||
@@ -131,18 +137,20 @@ export class PetApi extends BaseAPI {
|
||||
};
|
||||
|
||||
return this.request<Array<Pet>>({
|
||||
path: '/pet/findByStatus',
|
||||
url: '/pet/findByStatus',
|
||||
method: 'GET',
|
||||
headers,
|
||||
query,
|
||||
});
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
||||
* Finds Pets by tags
|
||||
*/
|
||||
findPetsByTags = ({ tags }: FindPetsByTagsRequest): Observable<Array<Pet>> => {
|
||||
findPetsByTags({ tags }: FindPetsByTagsRequest): Observable<Array<Pet>>
|
||||
findPetsByTags({ tags }: FindPetsByTagsRequest, opts?: OperationOpts): Observable<RawAjaxResponse<Array<Pet>>>
|
||||
findPetsByTags({ tags }: FindPetsByTagsRequest, opts?: OperationOpts): Observable<Array<Pet> | RawAjaxResponse<Array<Pet>>> {
|
||||
throwIfNullOrUndefined(tags, 'tags', 'findPetsByTags');
|
||||
|
||||
const headers: HttpHeaders = {
|
||||
@@ -160,18 +168,20 @@ export class PetApi extends BaseAPI {
|
||||
};
|
||||
|
||||
return this.request<Array<Pet>>({
|
||||
path: '/pet/findByTags',
|
||||
url: '/pet/findByTags',
|
||||
method: 'GET',
|
||||
headers,
|
||||
query,
|
||||
});
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns a single pet
|
||||
* Find pet by ID
|
||||
*/
|
||||
getPetById = ({ petId }: GetPetByIdRequest): Observable<Pet> => {
|
||||
getPetById({ petId }: GetPetByIdRequest): Observable<Pet>
|
||||
getPetById({ petId }: GetPetByIdRequest, opts?: OperationOpts): Observable<RawAjaxResponse<Pet>>
|
||||
getPetById({ petId }: GetPetByIdRequest, opts?: OperationOpts): Observable<Pet | RawAjaxResponse<Pet>> {
|
||||
throwIfNullOrUndefined(petId, 'petId', 'getPetById');
|
||||
|
||||
const headers: HttpHeaders = {
|
||||
@@ -179,16 +189,18 @@ export class PetApi extends BaseAPI {
|
||||
};
|
||||
|
||||
return this.request<Pet>({
|
||||
path: '/pet/{petId}'.replace('{petId}', encodeURI(petId)),
|
||||
url: '/pet/{petId}'.replace('{petId}', encodeURI(petId)),
|
||||
method: 'GET',
|
||||
headers,
|
||||
});
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* Update an existing pet
|
||||
*/
|
||||
updatePet = ({ body }: UpdatePetRequest): Observable<void> => {
|
||||
updatePet({ body }: UpdatePetRequest): Observable<void>
|
||||
updatePet({ body }: UpdatePetRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>>
|
||||
updatePet({ body }: UpdatePetRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>> {
|
||||
throwIfNullOrUndefined(body, 'body', 'updatePet');
|
||||
|
||||
const headers: HttpHeaders = {
|
||||
@@ -203,17 +215,19 @@ export class PetApi extends BaseAPI {
|
||||
};
|
||||
|
||||
return this.request<void>({
|
||||
path: '/pet',
|
||||
url: '/pet',
|
||||
method: 'PUT',
|
||||
headers,
|
||||
body: body,
|
||||
});
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates a pet in the store with form data
|
||||
*/
|
||||
updatePetWithForm = ({ petId, name, status }: UpdatePetWithFormRequest): Observable<void> => {
|
||||
updatePetWithForm({ petId, name, status }: UpdatePetWithFormRequest): Observable<void>
|
||||
updatePetWithForm({ petId, name, status }: UpdatePetWithFormRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>>
|
||||
updatePetWithForm({ petId, name, status }: UpdatePetWithFormRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>> {
|
||||
throwIfNullOrUndefined(petId, 'petId', 'updatePetWithForm');
|
||||
|
||||
const headers: HttpHeaders = {
|
||||
@@ -231,17 +245,19 @@ export class PetApi extends BaseAPI {
|
||||
if (status !== undefined) { formData.append('status', status as any); }
|
||||
|
||||
return this.request<void>({
|
||||
path: '/pet/{petId}'.replace('{petId}', encodeURI(petId)),
|
||||
url: '/pet/{petId}'.replace('{petId}', encodeURI(petId)),
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: formData,
|
||||
});
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* uploads an image
|
||||
*/
|
||||
uploadFile = ({ petId, additionalMetadata, file }: UploadFileRequest): Observable<ApiResponse> => {
|
||||
uploadFile({ petId, additionalMetadata, file }: UploadFileRequest): Observable<ApiResponse>
|
||||
uploadFile({ petId, additionalMetadata, file }: UploadFileRequest, opts?: OperationOpts): Observable<RawAjaxResponse<ApiResponse>>
|
||||
uploadFile({ petId, additionalMetadata, file }: UploadFileRequest, opts?: OperationOpts): Observable<ApiResponse | RawAjaxResponse<ApiResponse>> {
|
||||
throwIfNullOrUndefined(petId, 'petId', 'uploadFile');
|
||||
|
||||
const headers: HttpHeaders = {
|
||||
@@ -259,11 +275,11 @@ export class PetApi extends BaseAPI {
|
||||
if (file !== undefined) { formData.append('file', file as any); }
|
||||
|
||||
return this.request<ApiResponse>({
|
||||
path: '/pet/{petId}/uploadImage'.replace('{petId}', encodeURI(petId)),
|
||||
url: '/pet/{petId}/uploadImage'.replace('{petId}', encodeURI(petId)),
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: formData,
|
||||
});
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
*/
|
||||
|
||||
import { Observable } from 'rxjs';
|
||||
import { BaseAPI, HttpHeaders, throwIfNullOrUndefined, encodeURI } from '../runtime';
|
||||
import { BaseAPI, HttpHeaders, throwIfNullOrUndefined, encodeURI, OperationOpts, RawAjaxResponse } from '../runtime';
|
||||
import {
|
||||
Order,
|
||||
} from '../models';
|
||||
@@ -38,48 +38,56 @@ export class StoreApi extends BaseAPI {
|
||||
* For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
||||
* Delete purchase order by ID
|
||||
*/
|
||||
deleteOrder = ({ orderId }: DeleteOrderRequest): Observable<void> => {
|
||||
deleteOrder({ orderId }: DeleteOrderRequest): Observable<void>
|
||||
deleteOrder({ orderId }: DeleteOrderRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>>
|
||||
deleteOrder({ orderId }: DeleteOrderRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>> {
|
||||
throwIfNullOrUndefined(orderId, 'orderId', 'deleteOrder');
|
||||
|
||||
return this.request<void>({
|
||||
path: '/store/order/{orderId}'.replace('{orderId}', encodeURI(orderId)),
|
||||
url: '/store/order/{orderId}'.replace('{orderId}', encodeURI(orderId)),
|
||||
method: 'DELETE',
|
||||
});
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns a map of status codes to quantities
|
||||
* Returns pet inventories by status
|
||||
*/
|
||||
getInventory = (): Observable<{ [key: string]: number; }> => {
|
||||
getInventory(): Observable<{ [key: string]: number; }>
|
||||
getInventory(opts?: OperationOpts): Observable<RawAjaxResponse<{ [key: string]: number; }>>
|
||||
getInventory(opts?: OperationOpts): Observable<{ [key: string]: number; } | RawAjaxResponse<{ [key: string]: number; }>> {
|
||||
const headers: HttpHeaders = {
|
||||
...(this.configuration.apiKey && { 'api_key': this.configuration.apiKey('api_key') }), // api_key authentication
|
||||
};
|
||||
|
||||
return this.request<{ [key: string]: number; }>({
|
||||
path: '/store/inventory',
|
||||
url: '/store/inventory',
|
||||
method: 'GET',
|
||||
headers,
|
||||
});
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
|
||||
* Find purchase order by ID
|
||||
*/
|
||||
getOrderById = ({ orderId }: GetOrderByIdRequest): Observable<Order> => {
|
||||
getOrderById({ orderId }: GetOrderByIdRequest): Observable<Order>
|
||||
getOrderById({ orderId }: GetOrderByIdRequest, opts?: OperationOpts): Observable<RawAjaxResponse<Order>>
|
||||
getOrderById({ orderId }: GetOrderByIdRequest, opts?: OperationOpts): Observable<Order | RawAjaxResponse<Order>> {
|
||||
throwIfNullOrUndefined(orderId, 'orderId', 'getOrderById');
|
||||
|
||||
return this.request<Order>({
|
||||
path: '/store/order/{orderId}'.replace('{orderId}', encodeURI(orderId)),
|
||||
url: '/store/order/{orderId}'.replace('{orderId}', encodeURI(orderId)),
|
||||
method: 'GET',
|
||||
});
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* Place an order for a pet
|
||||
*/
|
||||
placeOrder = ({ body }: PlaceOrderRequest): Observable<Order> => {
|
||||
placeOrder({ body }: PlaceOrderRequest): Observable<Order>
|
||||
placeOrder({ body }: PlaceOrderRequest, opts?: OperationOpts): Observable<RawAjaxResponse<Order>>
|
||||
placeOrder({ body }: PlaceOrderRequest, opts?: OperationOpts): Observable<Order | RawAjaxResponse<Order>> {
|
||||
throwIfNullOrUndefined(body, 'body', 'placeOrder');
|
||||
|
||||
const headers: HttpHeaders = {
|
||||
@@ -87,11 +95,11 @@ export class StoreApi extends BaseAPI {
|
||||
};
|
||||
|
||||
return this.request<Order>({
|
||||
path: '/store/order',
|
||||
url: '/store/order',
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: body,
|
||||
});
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
*/
|
||||
|
||||
import { Observable } from 'rxjs';
|
||||
import { BaseAPI, HttpHeaders, HttpQuery, throwIfNullOrUndefined, encodeURI } from '../runtime';
|
||||
import { BaseAPI, HttpHeaders, HttpQuery, throwIfNullOrUndefined, encodeURI, OperationOpts, RawAjaxResponse } from '../runtime';
|
||||
import {
|
||||
User,
|
||||
} from '../models';
|
||||
@@ -56,7 +56,9 @@ export class UserApi extends BaseAPI {
|
||||
* This can only be done by the logged in user.
|
||||
* Create user
|
||||
*/
|
||||
createUser = ({ body }: CreateUserRequest): Observable<void> => {
|
||||
createUser({ body }: CreateUserRequest): Observable<void>
|
||||
createUser({ body }: CreateUserRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>>
|
||||
createUser({ body }: CreateUserRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>> {
|
||||
throwIfNullOrUndefined(body, 'body', 'createUser');
|
||||
|
||||
const headers: HttpHeaders = {
|
||||
@@ -64,17 +66,19 @@ export class UserApi extends BaseAPI {
|
||||
};
|
||||
|
||||
return this.request<void>({
|
||||
path: '/user',
|
||||
url: '/user',
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: body,
|
||||
});
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates list of users with given input array
|
||||
*/
|
||||
createUsersWithArrayInput = ({ body }: CreateUsersWithArrayInputRequest): Observable<void> => {
|
||||
createUsersWithArrayInput({ body }: CreateUsersWithArrayInputRequest): Observable<void>
|
||||
createUsersWithArrayInput({ body }: CreateUsersWithArrayInputRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>>
|
||||
createUsersWithArrayInput({ body }: CreateUsersWithArrayInputRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>> {
|
||||
throwIfNullOrUndefined(body, 'body', 'createUsersWithArrayInput');
|
||||
|
||||
const headers: HttpHeaders = {
|
||||
@@ -82,17 +86,19 @@ export class UserApi extends BaseAPI {
|
||||
};
|
||||
|
||||
return this.request<void>({
|
||||
path: '/user/createWithArray',
|
||||
url: '/user/createWithArray',
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: body,
|
||||
});
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates list of users with given input array
|
||||
*/
|
||||
createUsersWithListInput = ({ body }: CreateUsersWithListInputRequest): Observable<void> => {
|
||||
createUsersWithListInput({ body }: CreateUsersWithListInputRequest): Observable<void>
|
||||
createUsersWithListInput({ body }: CreateUsersWithListInputRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>>
|
||||
createUsersWithListInput({ body }: CreateUsersWithListInputRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>> {
|
||||
throwIfNullOrUndefined(body, 'body', 'createUsersWithListInput');
|
||||
|
||||
const headers: HttpHeaders = {
|
||||
@@ -100,42 +106,48 @@ export class UserApi extends BaseAPI {
|
||||
};
|
||||
|
||||
return this.request<void>({
|
||||
path: '/user/createWithList',
|
||||
url: '/user/createWithList',
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: body,
|
||||
});
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* This can only be done by the logged in user.
|
||||
* Delete user
|
||||
*/
|
||||
deleteUser = ({ username }: DeleteUserRequest): Observable<void> => {
|
||||
deleteUser({ username }: DeleteUserRequest): Observable<void>
|
||||
deleteUser({ username }: DeleteUserRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>>
|
||||
deleteUser({ username }: DeleteUserRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>> {
|
||||
throwIfNullOrUndefined(username, 'username', 'deleteUser');
|
||||
|
||||
return this.request<void>({
|
||||
path: '/user/{username}'.replace('{username}', encodeURI(username)),
|
||||
url: '/user/{username}'.replace('{username}', encodeURI(username)),
|
||||
method: 'DELETE',
|
||||
});
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* Get user by user name
|
||||
*/
|
||||
getUserByName = ({ username }: GetUserByNameRequest): Observable<User> => {
|
||||
getUserByName({ username }: GetUserByNameRequest): Observable<User>
|
||||
getUserByName({ username }: GetUserByNameRequest, opts?: OperationOpts): Observable<RawAjaxResponse<User>>
|
||||
getUserByName({ username }: GetUserByNameRequest, opts?: OperationOpts): Observable<User | RawAjaxResponse<User>> {
|
||||
throwIfNullOrUndefined(username, 'username', 'getUserByName');
|
||||
|
||||
return this.request<User>({
|
||||
path: '/user/{username}'.replace('{username}', encodeURI(username)),
|
||||
url: '/user/{username}'.replace('{username}', encodeURI(username)),
|
||||
method: 'GET',
|
||||
});
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* Logs user into the system
|
||||
*/
|
||||
loginUser = ({ username, password }: LoginUserRequest): Observable<string> => {
|
||||
loginUser({ username, password }: LoginUserRequest): Observable<string>
|
||||
loginUser({ username, password }: LoginUserRequest, opts?: OperationOpts): Observable<RawAjaxResponse<string>>
|
||||
loginUser({ username, password }: LoginUserRequest, opts?: OperationOpts): Observable<string | RawAjaxResponse<string>> {
|
||||
throwIfNullOrUndefined(username, 'username', 'loginUser');
|
||||
throwIfNullOrUndefined(password, 'password', 'loginUser');
|
||||
|
||||
@@ -145,27 +157,31 @@ export class UserApi extends BaseAPI {
|
||||
};
|
||||
|
||||
return this.request<string>({
|
||||
path: '/user/login',
|
||||
url: '/user/login',
|
||||
method: 'GET',
|
||||
query,
|
||||
});
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* Logs out current logged in user session
|
||||
*/
|
||||
logoutUser = (): Observable<void> => {
|
||||
logoutUser(): Observable<void>
|
||||
logoutUser(opts?: OperationOpts): Observable<void | RawAjaxResponse<void>>
|
||||
logoutUser(opts?: OperationOpts): Observable<void | RawAjaxResponse<void>> {
|
||||
return this.request<void>({
|
||||
path: '/user/logout',
|
||||
url: '/user/logout',
|
||||
method: 'GET',
|
||||
});
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* This can only be done by the logged in user.
|
||||
* Updated user
|
||||
*/
|
||||
updateUser = ({ username, body }: UpdateUserRequest): Observable<void> => {
|
||||
updateUser({ username, body }: UpdateUserRequest): Observable<void>
|
||||
updateUser({ username, body }: UpdateUserRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>>
|
||||
updateUser({ username, body }: UpdateUserRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>> {
|
||||
throwIfNullOrUndefined(username, 'username', 'updateUser');
|
||||
throwIfNullOrUndefined(body, 'body', 'updateUser');
|
||||
|
||||
@@ -174,11 +190,11 @@ export class UserApi extends BaseAPI {
|
||||
};
|
||||
|
||||
return this.request<void>({
|
||||
path: '/user/{username}'.replace('{username}', encodeURI(username)),
|
||||
url: '/user/{username}'.replace('{username}', encodeURI(username)),
|
||||
method: 'PUT',
|
||||
headers,
|
||||
body: body,
|
||||
});
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { Observable, of, Subscriber } from 'rxjs';
|
||||
import { ajax, AjaxRequest, AjaxResponse } from 'rxjs/ajax';
|
||||
import { map, concatMap } from 'rxjs/operators';
|
||||
|
||||
@@ -30,11 +30,11 @@ export class Configuration {
|
||||
constructor(private configuration: ConfigurationParameters = {}) {}
|
||||
|
||||
get basePath(): string {
|
||||
return this.configuration.basePath || BASE_PATH;
|
||||
return this.configuration.basePath ?? BASE_PATH;
|
||||
}
|
||||
|
||||
get middleware(): Middleware[] {
|
||||
return this.configuration.middleware || [];
|
||||
return this.configuration.middleware ?? [];
|
||||
}
|
||||
|
||||
get username(): string | undefined {
|
||||
@@ -47,18 +47,12 @@ export class Configuration {
|
||||
|
||||
get apiKey(): ((name: string) => string) | undefined {
|
||||
const { apiKey } = this.configuration;
|
||||
if (!apiKey) {
|
||||
return undefined;
|
||||
}
|
||||
return typeof apiKey === 'string' ? () => apiKey : apiKey;
|
||||
return apiKey ? (typeof apiKey === 'string' ? () => apiKey : apiKey) : undefined;
|
||||
}
|
||||
|
||||
get accessToken(): ((name: string, scopes?: string[]) => string) | undefined {
|
||||
const { accessToken } = this.configuration;
|
||||
if (!accessToken) {
|
||||
return undefined;
|
||||
}
|
||||
return typeof accessToken === 'string' ? () => accessToken : accessToken;
|
||||
return accessToken ? (typeof accessToken === 'string' ? () => accessToken : accessToken) : undefined;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,31 +78,32 @@ export class BaseAPI {
|
||||
withPostMiddleware = (postMiddlewares: Array<Middleware['post']>) =>
|
||||
this.withMiddleware(postMiddlewares.map((post) => ({ post })));
|
||||
|
||||
protected request = <T>(requestOpts: RequestOpts): Observable<T> =>
|
||||
this.rxjsRequest(this.createRequestArgs(requestOpts)).pipe(
|
||||
protected request<T>(requestOpts: RequestOpts): Observable<T>
|
||||
protected request<T>(requestOpts: RequestOpts, responseOpts?: ResponseOpts): Observable<RawAjaxResponse<T>>
|
||||
protected request<T>(requestOpts: RequestOpts, responseOpts?: ResponseOpts): Observable<T | RawAjaxResponse<T>> {
|
||||
return this.rxjsRequest(this.createRequestArgs(requestOpts)).pipe(
|
||||
map((res) => {
|
||||
if (res.status >= 200 && res.status < 300) {
|
||||
return res.response as T;
|
||||
const { status, response } = res;
|
||||
if (status >= 200 && status < 300) {
|
||||
return responseOpts?.respone === 'raw' ? res : response;
|
||||
}
|
||||
throw res;
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
private createRequestArgs = (requestOpts: RequestOpts): RequestArgs => {
|
||||
let url = this.configuration.basePath + requestOpts.path;
|
||||
if (requestOpts.query !== undefined && Object.keys(requestOpts.query).length !== 0) {
|
||||
// only add the queryString to the URL if there are query parameters.
|
||||
// this is done to avoid urls ending with a '?' character which buggy webservers
|
||||
// do not handle correctly sometimes.
|
||||
url += '?' + queryString(requestOpts.query);
|
||||
}
|
||||
private createRequestArgs = ({ url: baseUrl, query, method, headers, body, responseType }: RequestOpts): RequestArgs => {
|
||||
// only add the queryString to the URL if there are query parameters.
|
||||
// this is done to avoid urls ending with a '?' character which buggy webservers
|
||||
// do not handle correctly sometimes.
|
||||
const url = `${this.configuration.basePath}${baseUrl}${query && Object.keys(query).length ? `?${queryString(query)}`: ''}`;
|
||||
|
||||
return {
|
||||
url,
|
||||
method: requestOpts.method,
|
||||
headers: requestOpts.headers,
|
||||
body: requestOpts.body instanceof FormData ? requestOpts.body : JSON.stringify(requestOpts.body),
|
||||
responseType: requestOpts.responseType || 'json',
|
||||
method,
|
||||
headers,
|
||||
body: body instanceof FormData ? body : JSON.stringify(body),
|
||||
responseType: responseType ?? 'json',
|
||||
};
|
||||
}
|
||||
|
||||
@@ -157,24 +152,35 @@ export type HttpHeaders = { [key: string]: string };
|
||||
export type HttpQuery = Partial<{ [key: string]: string | number | null | boolean | Array<string | number | null | boolean> }>; // partial is needed for strict mode
|
||||
export type HttpBody = Json | FormData;
|
||||
|
||||
export interface RequestOpts {
|
||||
path: string;
|
||||
export interface RequestOpts extends AjaxRequest {
|
||||
query?: HttpQuery; // additional prop
|
||||
// the following props have improved types over AjaxRequest
|
||||
method: HttpMethod;
|
||||
headers?: HttpHeaders;
|
||||
query?: HttpQuery;
|
||||
body?: HttpBody;
|
||||
responseType?: 'json' | 'blob' | 'arraybuffer' | 'text';
|
||||
}
|
||||
|
||||
export const encodeURI = (value: any) => encodeURIComponent(String(value));
|
||||
export interface ResponseOpts {
|
||||
respone?: 'raw';
|
||||
}
|
||||
|
||||
const queryString = (params: HttpQuery): string => Object.keys(params)
|
||||
.map((key) => {
|
||||
const value = params[key];
|
||||
return (value instanceof Array)
|
||||
? value.map((val) => `${encodeURI(key)}=${encodeURI(val)}`).join('&')
|
||||
: `${encodeURI(key)}=${encodeURI(value)}`;
|
||||
})
|
||||
export interface OperationOpts {
|
||||
responseOpts?: ResponseOpts;
|
||||
}
|
||||
|
||||
// AjaxResponse with typed response
|
||||
export interface RawAjaxResponse<T> extends AjaxResponse {
|
||||
response: T;
|
||||
}
|
||||
|
||||
export const encodeURI = (value: any) => encodeURIComponent(`${value}`);
|
||||
|
||||
const queryString = (params: HttpQuery): string => Object.entries(params)
|
||||
.map(([key, value]) => value instanceof Array
|
||||
? value.map((val) => `${encodeURI(key)}=${encodeURI(val)}`).join('&')
|
||||
: `${encodeURI(key)}=${encodeURI(value)}`
|
||||
)
|
||||
.join('&');
|
||||
|
||||
// alias fallback for not being a breaking change
|
||||
|
||||
@@ -8,7 +8,8 @@
|
||||
"rootDir": ".",
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
"dom",
|
||||
"es2017"
|
||||
],
|
||||
"typeRoots": [
|
||||
"node_modules/@types"
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
*/
|
||||
|
||||
import { Observable } from 'rxjs';
|
||||
import { BaseAPI, HttpHeaders, HttpQuery, throwIfNullOrUndefined, encodeURI, COLLECTION_FORMATS } from '../runtime';
|
||||
import { BaseAPI, HttpHeaders, HttpQuery, throwIfNullOrUndefined, encodeURI, COLLECTION_FORMATS, OperationOpts, RawAjaxResponse } from '../runtime';
|
||||
import {
|
||||
ApiResponse,
|
||||
Pet,
|
||||
@@ -63,7 +63,9 @@ export class PetApi extends BaseAPI {
|
||||
/**
|
||||
* Add a new pet to the store
|
||||
*/
|
||||
addPet = ({ body }: AddPetRequest): Observable<void> => {
|
||||
addPet({ body }: AddPetRequest): Observable<void>
|
||||
addPet({ body }: AddPetRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>>
|
||||
addPet({ body }: AddPetRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>> {
|
||||
throwIfNullOrUndefined(body, 'body', 'addPet');
|
||||
|
||||
const headers: HttpHeaders = {
|
||||
@@ -78,17 +80,19 @@ export class PetApi extends BaseAPI {
|
||||
};
|
||||
|
||||
return this.request<void>({
|
||||
path: '/pet',
|
||||
url: '/pet',
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: body,
|
||||
});
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* Deletes a pet
|
||||
*/
|
||||
deletePet = ({ petId, apiKey }: DeletePetRequest): Observable<void> => {
|
||||
deletePet({ petId, apiKey }: DeletePetRequest): Observable<void>
|
||||
deletePet({ petId, apiKey }: DeletePetRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>>
|
||||
deletePet({ petId, apiKey }: DeletePetRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>> {
|
||||
throwIfNullOrUndefined(petId, 'petId', 'deletePet');
|
||||
|
||||
const headers: HttpHeaders = {
|
||||
@@ -103,17 +107,19 @@ export class PetApi extends BaseAPI {
|
||||
};
|
||||
|
||||
return this.request<void>({
|
||||
path: '/pet/{petId}'.replace('{petId}', encodeURI(petId)),
|
||||
url: '/pet/{petId}'.replace('{petId}', encodeURI(petId)),
|
||||
method: 'DELETE',
|
||||
headers,
|
||||
});
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* Multiple status values can be provided with comma separated strings
|
||||
* Finds Pets by status
|
||||
*/
|
||||
findPetsByStatus = ({ status }: FindPetsByStatusRequest): Observable<Array<Pet>> => {
|
||||
findPetsByStatus({ status }: FindPetsByStatusRequest): Observable<Array<Pet>>
|
||||
findPetsByStatus({ status }: FindPetsByStatusRequest, opts?: OperationOpts): Observable<RawAjaxResponse<Array<Pet>>>
|
||||
findPetsByStatus({ status }: FindPetsByStatusRequest, opts?: OperationOpts): Observable<Array<Pet> | RawAjaxResponse<Array<Pet>>> {
|
||||
throwIfNullOrUndefined(status, 'status', 'findPetsByStatus');
|
||||
|
||||
const headers: HttpHeaders = {
|
||||
@@ -131,18 +137,20 @@ export class PetApi extends BaseAPI {
|
||||
};
|
||||
|
||||
return this.request<Array<Pet>>({
|
||||
path: '/pet/findByStatus',
|
||||
url: '/pet/findByStatus',
|
||||
method: 'GET',
|
||||
headers,
|
||||
query,
|
||||
});
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
||||
* Finds Pets by tags
|
||||
*/
|
||||
findPetsByTags = ({ tags }: FindPetsByTagsRequest): Observable<Array<Pet>> => {
|
||||
findPetsByTags({ tags }: FindPetsByTagsRequest): Observable<Array<Pet>>
|
||||
findPetsByTags({ tags }: FindPetsByTagsRequest, opts?: OperationOpts): Observable<RawAjaxResponse<Array<Pet>>>
|
||||
findPetsByTags({ tags }: FindPetsByTagsRequest, opts?: OperationOpts): Observable<Array<Pet> | RawAjaxResponse<Array<Pet>>> {
|
||||
throwIfNullOrUndefined(tags, 'tags', 'findPetsByTags');
|
||||
|
||||
const headers: HttpHeaders = {
|
||||
@@ -160,18 +168,20 @@ export class PetApi extends BaseAPI {
|
||||
};
|
||||
|
||||
return this.request<Array<Pet>>({
|
||||
path: '/pet/findByTags',
|
||||
url: '/pet/findByTags',
|
||||
method: 'GET',
|
||||
headers,
|
||||
query,
|
||||
});
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns a single pet
|
||||
* Find pet by ID
|
||||
*/
|
||||
getPetById = ({ petId }: GetPetByIdRequest): Observable<Pet> => {
|
||||
getPetById({ petId }: GetPetByIdRequest): Observable<Pet>
|
||||
getPetById({ petId }: GetPetByIdRequest, opts?: OperationOpts): Observable<RawAjaxResponse<Pet>>
|
||||
getPetById({ petId }: GetPetByIdRequest, opts?: OperationOpts): Observable<Pet | RawAjaxResponse<Pet>> {
|
||||
throwIfNullOrUndefined(petId, 'petId', 'getPetById');
|
||||
|
||||
const headers: HttpHeaders = {
|
||||
@@ -179,16 +189,18 @@ export class PetApi extends BaseAPI {
|
||||
};
|
||||
|
||||
return this.request<Pet>({
|
||||
path: '/pet/{petId}'.replace('{petId}', encodeURI(petId)),
|
||||
url: '/pet/{petId}'.replace('{petId}', encodeURI(petId)),
|
||||
method: 'GET',
|
||||
headers,
|
||||
});
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* Update an existing pet
|
||||
*/
|
||||
updatePet = ({ body }: UpdatePetRequest): Observable<void> => {
|
||||
updatePet({ body }: UpdatePetRequest): Observable<void>
|
||||
updatePet({ body }: UpdatePetRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>>
|
||||
updatePet({ body }: UpdatePetRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>> {
|
||||
throwIfNullOrUndefined(body, 'body', 'updatePet');
|
||||
|
||||
const headers: HttpHeaders = {
|
||||
@@ -203,17 +215,19 @@ export class PetApi extends BaseAPI {
|
||||
};
|
||||
|
||||
return this.request<void>({
|
||||
path: '/pet',
|
||||
url: '/pet',
|
||||
method: 'PUT',
|
||||
headers,
|
||||
body: body,
|
||||
});
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates a pet in the store with form data
|
||||
*/
|
||||
updatePetWithForm = ({ petId, name, status }: UpdatePetWithFormRequest): Observable<void> => {
|
||||
updatePetWithForm({ petId, name, status }: UpdatePetWithFormRequest): Observable<void>
|
||||
updatePetWithForm({ petId, name, status }: UpdatePetWithFormRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>>
|
||||
updatePetWithForm({ petId, name, status }: UpdatePetWithFormRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>> {
|
||||
throwIfNullOrUndefined(petId, 'petId', 'updatePetWithForm');
|
||||
|
||||
const headers: HttpHeaders = {
|
||||
@@ -231,17 +245,19 @@ export class PetApi extends BaseAPI {
|
||||
if (status !== undefined) { formData.append('status', status as any); }
|
||||
|
||||
return this.request<void>({
|
||||
path: '/pet/{petId}'.replace('{petId}', encodeURI(petId)),
|
||||
url: '/pet/{petId}'.replace('{petId}', encodeURI(petId)),
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: formData,
|
||||
});
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* uploads an image
|
||||
*/
|
||||
uploadFile = ({ petId, additionalMetadata, file }: UploadFileRequest): Observable<ApiResponse> => {
|
||||
uploadFile({ petId, additionalMetadata, file }: UploadFileRequest): Observable<ApiResponse>
|
||||
uploadFile({ petId, additionalMetadata, file }: UploadFileRequest, opts?: OperationOpts): Observable<RawAjaxResponse<ApiResponse>>
|
||||
uploadFile({ petId, additionalMetadata, file }: UploadFileRequest, opts?: OperationOpts): Observable<ApiResponse | RawAjaxResponse<ApiResponse>> {
|
||||
throwIfNullOrUndefined(petId, 'petId', 'uploadFile');
|
||||
|
||||
const headers: HttpHeaders = {
|
||||
@@ -259,11 +275,11 @@ export class PetApi extends BaseAPI {
|
||||
if (file !== undefined) { formData.append('file', file as any); }
|
||||
|
||||
return this.request<ApiResponse>({
|
||||
path: '/pet/{petId}/uploadImage'.replace('{petId}', encodeURI(petId)),
|
||||
url: '/pet/{petId}/uploadImage'.replace('{petId}', encodeURI(petId)),
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: formData,
|
||||
});
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
*/
|
||||
|
||||
import { Observable } from 'rxjs';
|
||||
import { BaseAPI, HttpHeaders, throwIfNullOrUndefined, encodeURI } from '../runtime';
|
||||
import { BaseAPI, HttpHeaders, throwIfNullOrUndefined, encodeURI, OperationOpts, RawAjaxResponse } from '../runtime';
|
||||
import {
|
||||
Order,
|
||||
} from '../models';
|
||||
@@ -38,48 +38,56 @@ export class StoreApi extends BaseAPI {
|
||||
* For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
||||
* Delete purchase order by ID
|
||||
*/
|
||||
deleteOrder = ({ orderId }: DeleteOrderRequest): Observable<void> => {
|
||||
deleteOrder({ orderId }: DeleteOrderRequest): Observable<void>
|
||||
deleteOrder({ orderId }: DeleteOrderRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>>
|
||||
deleteOrder({ orderId }: DeleteOrderRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>> {
|
||||
throwIfNullOrUndefined(orderId, 'orderId', 'deleteOrder');
|
||||
|
||||
return this.request<void>({
|
||||
path: '/store/order/{orderId}'.replace('{orderId}', encodeURI(orderId)),
|
||||
url: '/store/order/{orderId}'.replace('{orderId}', encodeURI(orderId)),
|
||||
method: 'DELETE',
|
||||
});
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns a map of status codes to quantities
|
||||
* Returns pet inventories by status
|
||||
*/
|
||||
getInventory = (): Observable<{ [key: string]: number; }> => {
|
||||
getInventory(): Observable<{ [key: string]: number; }>
|
||||
getInventory(opts?: OperationOpts): Observable<RawAjaxResponse<{ [key: string]: number; }>>
|
||||
getInventory(opts?: OperationOpts): Observable<{ [key: string]: number; } | RawAjaxResponse<{ [key: string]: number; }>> {
|
||||
const headers: HttpHeaders = {
|
||||
...(this.configuration.apiKey && { 'api_key': this.configuration.apiKey('api_key') }), // api_key authentication
|
||||
};
|
||||
|
||||
return this.request<{ [key: string]: number; }>({
|
||||
path: '/store/inventory',
|
||||
url: '/store/inventory',
|
||||
method: 'GET',
|
||||
headers,
|
||||
});
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
|
||||
* Find purchase order by ID
|
||||
*/
|
||||
getOrderById = ({ orderId }: GetOrderByIdRequest): Observable<Order> => {
|
||||
getOrderById({ orderId }: GetOrderByIdRequest): Observable<Order>
|
||||
getOrderById({ orderId }: GetOrderByIdRequest, opts?: OperationOpts): Observable<RawAjaxResponse<Order>>
|
||||
getOrderById({ orderId }: GetOrderByIdRequest, opts?: OperationOpts): Observable<Order | RawAjaxResponse<Order>> {
|
||||
throwIfNullOrUndefined(orderId, 'orderId', 'getOrderById');
|
||||
|
||||
return this.request<Order>({
|
||||
path: '/store/order/{orderId}'.replace('{orderId}', encodeURI(orderId)),
|
||||
url: '/store/order/{orderId}'.replace('{orderId}', encodeURI(orderId)),
|
||||
method: 'GET',
|
||||
});
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* Place an order for a pet
|
||||
*/
|
||||
placeOrder = ({ body }: PlaceOrderRequest): Observable<Order> => {
|
||||
placeOrder({ body }: PlaceOrderRequest): Observable<Order>
|
||||
placeOrder({ body }: PlaceOrderRequest, opts?: OperationOpts): Observable<RawAjaxResponse<Order>>
|
||||
placeOrder({ body }: PlaceOrderRequest, opts?: OperationOpts): Observable<Order | RawAjaxResponse<Order>> {
|
||||
throwIfNullOrUndefined(body, 'body', 'placeOrder');
|
||||
|
||||
const headers: HttpHeaders = {
|
||||
@@ -87,11 +95,11 @@ export class StoreApi extends BaseAPI {
|
||||
};
|
||||
|
||||
return this.request<Order>({
|
||||
path: '/store/order',
|
||||
url: '/store/order',
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: body,
|
||||
});
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
*/
|
||||
|
||||
import { Observable } from 'rxjs';
|
||||
import { BaseAPI, HttpHeaders, HttpQuery, throwIfNullOrUndefined, encodeURI } from '../runtime';
|
||||
import { BaseAPI, HttpHeaders, HttpQuery, throwIfNullOrUndefined, encodeURI, OperationOpts, RawAjaxResponse } from '../runtime';
|
||||
import {
|
||||
User,
|
||||
} from '../models';
|
||||
@@ -56,7 +56,9 @@ export class UserApi extends BaseAPI {
|
||||
* This can only be done by the logged in user.
|
||||
* Create user
|
||||
*/
|
||||
createUser = ({ body }: CreateUserRequest): Observable<void> => {
|
||||
createUser({ body }: CreateUserRequest): Observable<void>
|
||||
createUser({ body }: CreateUserRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>>
|
||||
createUser({ body }: CreateUserRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>> {
|
||||
throwIfNullOrUndefined(body, 'body', 'createUser');
|
||||
|
||||
const headers: HttpHeaders = {
|
||||
@@ -64,17 +66,19 @@ export class UserApi extends BaseAPI {
|
||||
};
|
||||
|
||||
return this.request<void>({
|
||||
path: '/user',
|
||||
url: '/user',
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: body,
|
||||
});
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates list of users with given input array
|
||||
*/
|
||||
createUsersWithArrayInput = ({ body }: CreateUsersWithArrayInputRequest): Observable<void> => {
|
||||
createUsersWithArrayInput({ body }: CreateUsersWithArrayInputRequest): Observable<void>
|
||||
createUsersWithArrayInput({ body }: CreateUsersWithArrayInputRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>>
|
||||
createUsersWithArrayInput({ body }: CreateUsersWithArrayInputRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>> {
|
||||
throwIfNullOrUndefined(body, 'body', 'createUsersWithArrayInput');
|
||||
|
||||
const headers: HttpHeaders = {
|
||||
@@ -82,17 +86,19 @@ export class UserApi extends BaseAPI {
|
||||
};
|
||||
|
||||
return this.request<void>({
|
||||
path: '/user/createWithArray',
|
||||
url: '/user/createWithArray',
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: body,
|
||||
});
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates list of users with given input array
|
||||
*/
|
||||
createUsersWithListInput = ({ body }: CreateUsersWithListInputRequest): Observable<void> => {
|
||||
createUsersWithListInput({ body }: CreateUsersWithListInputRequest): Observable<void>
|
||||
createUsersWithListInput({ body }: CreateUsersWithListInputRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>>
|
||||
createUsersWithListInput({ body }: CreateUsersWithListInputRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>> {
|
||||
throwIfNullOrUndefined(body, 'body', 'createUsersWithListInput');
|
||||
|
||||
const headers: HttpHeaders = {
|
||||
@@ -100,42 +106,48 @@ export class UserApi extends BaseAPI {
|
||||
};
|
||||
|
||||
return this.request<void>({
|
||||
path: '/user/createWithList',
|
||||
url: '/user/createWithList',
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: body,
|
||||
});
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* This can only be done by the logged in user.
|
||||
* Delete user
|
||||
*/
|
||||
deleteUser = ({ username }: DeleteUserRequest): Observable<void> => {
|
||||
deleteUser({ username }: DeleteUserRequest): Observable<void>
|
||||
deleteUser({ username }: DeleteUserRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>>
|
||||
deleteUser({ username }: DeleteUserRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>> {
|
||||
throwIfNullOrUndefined(username, 'username', 'deleteUser');
|
||||
|
||||
return this.request<void>({
|
||||
path: '/user/{username}'.replace('{username}', encodeURI(username)),
|
||||
url: '/user/{username}'.replace('{username}', encodeURI(username)),
|
||||
method: 'DELETE',
|
||||
});
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* Get user by user name
|
||||
*/
|
||||
getUserByName = ({ username }: GetUserByNameRequest): Observable<User> => {
|
||||
getUserByName({ username }: GetUserByNameRequest): Observable<User>
|
||||
getUserByName({ username }: GetUserByNameRequest, opts?: OperationOpts): Observable<RawAjaxResponse<User>>
|
||||
getUserByName({ username }: GetUserByNameRequest, opts?: OperationOpts): Observable<User | RawAjaxResponse<User>> {
|
||||
throwIfNullOrUndefined(username, 'username', 'getUserByName');
|
||||
|
||||
return this.request<User>({
|
||||
path: '/user/{username}'.replace('{username}', encodeURI(username)),
|
||||
url: '/user/{username}'.replace('{username}', encodeURI(username)),
|
||||
method: 'GET',
|
||||
});
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* Logs user into the system
|
||||
*/
|
||||
loginUser = ({ username, password }: LoginUserRequest): Observable<string> => {
|
||||
loginUser({ username, password }: LoginUserRequest): Observable<string>
|
||||
loginUser({ username, password }: LoginUserRequest, opts?: OperationOpts): Observable<RawAjaxResponse<string>>
|
||||
loginUser({ username, password }: LoginUserRequest, opts?: OperationOpts): Observable<string | RawAjaxResponse<string>> {
|
||||
throwIfNullOrUndefined(username, 'username', 'loginUser');
|
||||
throwIfNullOrUndefined(password, 'password', 'loginUser');
|
||||
|
||||
@@ -145,27 +157,31 @@ export class UserApi extends BaseAPI {
|
||||
};
|
||||
|
||||
return this.request<string>({
|
||||
path: '/user/login',
|
||||
url: '/user/login',
|
||||
method: 'GET',
|
||||
query,
|
||||
});
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* Logs out current logged in user session
|
||||
*/
|
||||
logoutUser = (): Observable<void> => {
|
||||
logoutUser(): Observable<void>
|
||||
logoutUser(opts?: OperationOpts): Observable<void | RawAjaxResponse<void>>
|
||||
logoutUser(opts?: OperationOpts): Observable<void | RawAjaxResponse<void>> {
|
||||
return this.request<void>({
|
||||
path: '/user/logout',
|
||||
url: '/user/logout',
|
||||
method: 'GET',
|
||||
});
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* This can only be done by the logged in user.
|
||||
* Updated user
|
||||
*/
|
||||
updateUser = ({ username, body }: UpdateUserRequest): Observable<void> => {
|
||||
updateUser({ username, body }: UpdateUserRequest): Observable<void>
|
||||
updateUser({ username, body }: UpdateUserRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>>
|
||||
updateUser({ username, body }: UpdateUserRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>> {
|
||||
throwIfNullOrUndefined(username, 'username', 'updateUser');
|
||||
throwIfNullOrUndefined(body, 'body', 'updateUser');
|
||||
|
||||
@@ -174,11 +190,11 @@ export class UserApi extends BaseAPI {
|
||||
};
|
||||
|
||||
return this.request<void>({
|
||||
path: '/user/{username}'.replace('{username}', encodeURI(username)),
|
||||
url: '/user/{username}'.replace('{username}', encodeURI(username)),
|
||||
method: 'PUT',
|
||||
headers,
|
||||
body: body,
|
||||
});
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -6,14 +6,14 @@
|
||||
"main": "./dist/index.js",
|
||||
"typings": "./dist/index.d.ts",
|
||||
"scripts" : {
|
||||
"build": "tsc --outDir dist/",
|
||||
"build": "node_modules/.bin/tsc --outDir dist/",
|
||||
"prepare": "npm run build"
|
||||
},
|
||||
"dependencies": {
|
||||
"rxjs": "^6.3.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^3.0.1"
|
||||
"typescript": "^3.7"
|
||||
},
|
||||
"publishConfig": {
|
||||
"registry": "https://skimdb.npmjs.com/registry"
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { Observable, of, Subscriber } from 'rxjs';
|
||||
import { ajax, AjaxRequest, AjaxResponse } from 'rxjs/ajax';
|
||||
import { map, concatMap } from 'rxjs/operators';
|
||||
|
||||
@@ -30,11 +30,11 @@ export class Configuration {
|
||||
constructor(private configuration: ConfigurationParameters = {}) {}
|
||||
|
||||
get basePath(): string {
|
||||
return this.configuration.basePath || BASE_PATH;
|
||||
return this.configuration.basePath ?? BASE_PATH;
|
||||
}
|
||||
|
||||
get middleware(): Middleware[] {
|
||||
return this.configuration.middleware || [];
|
||||
return this.configuration.middleware ?? [];
|
||||
}
|
||||
|
||||
get username(): string | undefined {
|
||||
@@ -47,18 +47,12 @@ export class Configuration {
|
||||
|
||||
get apiKey(): ((name: string) => string) | undefined {
|
||||
const { apiKey } = this.configuration;
|
||||
if (!apiKey) {
|
||||
return undefined;
|
||||
}
|
||||
return typeof apiKey === 'string' ? () => apiKey : apiKey;
|
||||
return apiKey ? (typeof apiKey === 'string' ? () => apiKey : apiKey) : undefined;
|
||||
}
|
||||
|
||||
get accessToken(): ((name: string, scopes?: string[]) => string) | undefined {
|
||||
const { accessToken } = this.configuration;
|
||||
if (!accessToken) {
|
||||
return undefined;
|
||||
}
|
||||
return typeof accessToken === 'string' ? () => accessToken : accessToken;
|
||||
return accessToken ? (typeof accessToken === 'string' ? () => accessToken : accessToken) : undefined;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,31 +78,32 @@ export class BaseAPI {
|
||||
withPostMiddleware = (postMiddlewares: Array<Middleware['post']>) =>
|
||||
this.withMiddleware(postMiddlewares.map((post) => ({ post })));
|
||||
|
||||
protected request = <T>(requestOpts: RequestOpts): Observable<T> =>
|
||||
this.rxjsRequest(this.createRequestArgs(requestOpts)).pipe(
|
||||
protected request<T>(requestOpts: RequestOpts): Observable<T>
|
||||
protected request<T>(requestOpts: RequestOpts, responseOpts?: ResponseOpts): Observable<RawAjaxResponse<T>>
|
||||
protected request<T>(requestOpts: RequestOpts, responseOpts?: ResponseOpts): Observable<T | RawAjaxResponse<T>> {
|
||||
return this.rxjsRequest(this.createRequestArgs(requestOpts)).pipe(
|
||||
map((res) => {
|
||||
if (res.status >= 200 && res.status < 300) {
|
||||
return res.response as T;
|
||||
const { status, response } = res;
|
||||
if (status >= 200 && status < 300) {
|
||||
return responseOpts?.respone === 'raw' ? res : response;
|
||||
}
|
||||
throw res;
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
private createRequestArgs = (requestOpts: RequestOpts): RequestArgs => {
|
||||
let url = this.configuration.basePath + requestOpts.path;
|
||||
if (requestOpts.query !== undefined && Object.keys(requestOpts.query).length !== 0) {
|
||||
// only add the queryString to the URL if there are query parameters.
|
||||
// this is done to avoid urls ending with a '?' character which buggy webservers
|
||||
// do not handle correctly sometimes.
|
||||
url += '?' + queryString(requestOpts.query);
|
||||
}
|
||||
private createRequestArgs = ({ url: baseUrl, query, method, headers, body, responseType }: RequestOpts): RequestArgs => {
|
||||
// only add the queryString to the URL if there are query parameters.
|
||||
// this is done to avoid urls ending with a '?' character which buggy webservers
|
||||
// do not handle correctly sometimes.
|
||||
const url = `${this.configuration.basePath}${baseUrl}${query && Object.keys(query).length ? `?${queryString(query)}`: ''}`;
|
||||
|
||||
return {
|
||||
url,
|
||||
method: requestOpts.method,
|
||||
headers: requestOpts.headers,
|
||||
body: requestOpts.body instanceof FormData ? requestOpts.body : JSON.stringify(requestOpts.body),
|
||||
responseType: requestOpts.responseType || 'json',
|
||||
method,
|
||||
headers,
|
||||
body: body instanceof FormData ? body : JSON.stringify(body),
|
||||
responseType: responseType ?? 'json',
|
||||
};
|
||||
}
|
||||
|
||||
@@ -157,24 +152,35 @@ export type HttpHeaders = { [key: string]: string };
|
||||
export type HttpQuery = Partial<{ [key: string]: string | number | null | boolean | Array<string | number | null | boolean> }>; // partial is needed for strict mode
|
||||
export type HttpBody = Json | FormData;
|
||||
|
||||
export interface RequestOpts {
|
||||
path: string;
|
||||
export interface RequestOpts extends AjaxRequest {
|
||||
query?: HttpQuery; // additional prop
|
||||
// the following props have improved types over AjaxRequest
|
||||
method: HttpMethod;
|
||||
headers?: HttpHeaders;
|
||||
query?: HttpQuery;
|
||||
body?: HttpBody;
|
||||
responseType?: 'json' | 'blob' | 'arraybuffer' | 'text';
|
||||
}
|
||||
|
||||
export const encodeURI = (value: any) => encodeURIComponent(String(value));
|
||||
export interface ResponseOpts {
|
||||
respone?: 'raw';
|
||||
}
|
||||
|
||||
const queryString = (params: HttpQuery): string => Object.keys(params)
|
||||
.map((key) => {
|
||||
const value = params[key];
|
||||
return (value instanceof Array)
|
||||
? value.map((val) => `${encodeURI(key)}=${encodeURI(val)}`).join('&')
|
||||
: `${encodeURI(key)}=${encodeURI(value)}`;
|
||||
})
|
||||
export interface OperationOpts {
|
||||
responseOpts?: ResponseOpts;
|
||||
}
|
||||
|
||||
// AjaxResponse with typed response
|
||||
export interface RawAjaxResponse<T> extends AjaxResponse {
|
||||
response: T;
|
||||
}
|
||||
|
||||
export const encodeURI = (value: any) => encodeURIComponent(`${value}`);
|
||||
|
||||
const queryString = (params: HttpQuery): string => Object.entries(params)
|
||||
.map(([key, value]) => value instanceof Array
|
||||
? value.map((val) => `${encodeURI(key)}=${encodeURI(val)}`).join('&')
|
||||
: `${encodeURI(key)}=${encodeURI(value)}`
|
||||
)
|
||||
.join('&');
|
||||
|
||||
// alias fallback for not being a breaking change
|
||||
|
||||
@@ -6,6 +6,10 @@
|
||||
"moduleResolution": "node",
|
||||
"outDir": "dist",
|
||||
"rootDir": ".",
|
||||
"lib": [
|
||||
"dom",
|
||||
"es2017"
|
||||
],
|
||||
"typeRoots": [
|
||||
"node_modules/@types"
|
||||
]
|
||||
|
||||
@@ -1,97 +0,0 @@
|
||||
// tslint:disable
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
import { Observable } from 'rxjs';
|
||||
import { BaseAPI, HttpHeaders, throwIfNullOrUndefined, encodeURI } from '../runtime';
|
||||
import {
|
||||
Order,
|
||||
} from '../models';
|
||||
|
||||
export interface DeleteOrderRequest {
|
||||
orderId: string;
|
||||
}
|
||||
|
||||
export interface GetOrderByIdRequest {
|
||||
orderId: number;
|
||||
}
|
||||
|
||||
export interface PlaceOrderRequest {
|
||||
body: Order;
|
||||
}
|
||||
|
||||
/**
|
||||
* no description
|
||||
*/
|
||||
export class StoreApi extends BaseAPI {
|
||||
|
||||
/**
|
||||
* For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
||||
* Delete purchase order by ID
|
||||
*/
|
||||
deleteOrder = ({ orderId }: DeleteOrderRequest): Observable<void> => {
|
||||
throwIfNullOrUndefined(orderId, 'orderId', 'deleteOrder');
|
||||
|
||||
return this.request<void>({
|
||||
path: '/store/order/{orderId}'.replace('{orderId}', encodeURI(orderId)),
|
||||
method: 'DELETE',
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns a map of status codes to quantities
|
||||
* Returns pet inventories by status
|
||||
*/
|
||||
getInventory = (): Observable<{ [key: string]: number; }> => {
|
||||
const headers: HttpHeaders = {
|
||||
...(this.configuration.apiKey && { 'api_key': this.configuration.apiKey('api_key') }), // api_key authentication
|
||||
};
|
||||
|
||||
return this.request<{ [key: string]: number; }>({
|
||||
path: '/store/inventory',
|
||||
method: 'GET',
|
||||
headers,
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
|
||||
* Find purchase order by ID
|
||||
*/
|
||||
getOrderById = ({ orderId }: GetOrderByIdRequest): Observable<Order> => {
|
||||
throwIfNullOrUndefined(orderId, 'orderId', 'getOrderById');
|
||||
|
||||
return this.request<Order>({
|
||||
path: '/store/order/{orderId}'.replace('{orderId}', encodeURI(orderId)),
|
||||
method: 'GET',
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Place an order for a pet
|
||||
*/
|
||||
placeOrder = ({ body }: PlaceOrderRequest): Observable<Order> => {
|
||||
throwIfNullOrUndefined(body, 'body', 'placeOrder');
|
||||
|
||||
const headers: HttpHeaders = {
|
||||
'Content-Type': 'application/json',
|
||||
};
|
||||
|
||||
return this.request<Order>({
|
||||
path: '/store/order',
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: body,
|
||||
});
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,184 +0,0 @@
|
||||
// tslint:disable
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
import { Observable } from 'rxjs';
|
||||
import { BaseAPI, HttpHeaders, HttpQuery, throwIfNullOrUndefined, encodeURI } from '../runtime';
|
||||
import {
|
||||
User,
|
||||
} from '../models';
|
||||
|
||||
export interface CreateUserRequest {
|
||||
body: User;
|
||||
}
|
||||
|
||||
export interface CreateUsersWithArrayInputRequest {
|
||||
body: Array<User>;
|
||||
}
|
||||
|
||||
export interface CreateUsersWithListInputRequest {
|
||||
body: Array<User>;
|
||||
}
|
||||
|
||||
export interface DeleteUserRequest {
|
||||
username: string;
|
||||
}
|
||||
|
||||
export interface GetUserByNameRequest {
|
||||
username: string;
|
||||
}
|
||||
|
||||
export interface LoginUserRequest {
|
||||
username: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
export interface UpdateUserRequest {
|
||||
username: string;
|
||||
body: User;
|
||||
}
|
||||
|
||||
/**
|
||||
* no description
|
||||
*/
|
||||
export class UserApi extends BaseAPI {
|
||||
|
||||
/**
|
||||
* This can only be done by the logged in user.
|
||||
* Create user
|
||||
*/
|
||||
createUser = ({ body }: CreateUserRequest): Observable<void> => {
|
||||
throwIfNullOrUndefined(body, 'body', 'createUser');
|
||||
|
||||
const headers: HttpHeaders = {
|
||||
'Content-Type': 'application/json',
|
||||
};
|
||||
|
||||
return this.request<void>({
|
||||
path: '/user',
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: body,
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates list of users with given input array
|
||||
*/
|
||||
createUsersWithArrayInput = ({ body }: CreateUsersWithArrayInputRequest): Observable<void> => {
|
||||
throwIfNullOrUndefined(body, 'body', 'createUsersWithArrayInput');
|
||||
|
||||
const headers: HttpHeaders = {
|
||||
'Content-Type': 'application/json',
|
||||
};
|
||||
|
||||
return this.request<void>({
|
||||
path: '/user/createWithArray',
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: body,
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates list of users with given input array
|
||||
*/
|
||||
createUsersWithListInput = ({ body }: CreateUsersWithListInputRequest): Observable<void> => {
|
||||
throwIfNullOrUndefined(body, 'body', 'createUsersWithListInput');
|
||||
|
||||
const headers: HttpHeaders = {
|
||||
'Content-Type': 'application/json',
|
||||
};
|
||||
|
||||
return this.request<void>({
|
||||
path: '/user/createWithList',
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: body,
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* This can only be done by the logged in user.
|
||||
* Delete user
|
||||
*/
|
||||
deleteUser = ({ username }: DeleteUserRequest): Observable<void> => {
|
||||
throwIfNullOrUndefined(username, 'username', 'deleteUser');
|
||||
|
||||
return this.request<void>({
|
||||
path: '/user/{username}'.replace('{username}', encodeURI(username)),
|
||||
method: 'DELETE',
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Get user by user name
|
||||
*/
|
||||
getUserByName = ({ username }: GetUserByNameRequest): Observable<User> => {
|
||||
throwIfNullOrUndefined(username, 'username', 'getUserByName');
|
||||
|
||||
return this.request<User>({
|
||||
path: '/user/{username}'.replace('{username}', encodeURI(username)),
|
||||
method: 'GET',
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Logs user into the system
|
||||
*/
|
||||
loginUser = ({ username, password }: LoginUserRequest): Observable<string> => {
|
||||
throwIfNullOrUndefined(username, 'username', 'loginUser');
|
||||
throwIfNullOrUndefined(password, 'password', 'loginUser');
|
||||
|
||||
const query: HttpQuery = { // required parameters are used directly since they are already checked by throwIfNullOrUndefined
|
||||
'username': username,
|
||||
'password': password,
|
||||
};
|
||||
|
||||
return this.request<string>({
|
||||
path: '/user/login',
|
||||
method: 'GET',
|
||||
query,
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Logs out current logged in user session
|
||||
*/
|
||||
logoutUser = (): Observable<void> => {
|
||||
return this.request<void>({
|
||||
path: '/user/logout',
|
||||
method: 'GET',
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* This can only be done by the logged in user.
|
||||
* Updated user
|
||||
*/
|
||||
updateUser = ({ username, body }: UpdateUserRequest): Observable<void> => {
|
||||
throwIfNullOrUndefined(username, 'username', 'updateUser');
|
||||
throwIfNullOrUndefined(body, 'body', 'updateUser');
|
||||
|
||||
const headers: HttpHeaders = {
|
||||
'Content-Type': 'application/json',
|
||||
};
|
||||
|
||||
return this.request<void>({
|
||||
path: '/user/{username}'.replace('{username}', encodeURI(username)),
|
||||
method: 'PUT',
|
||||
headers,
|
||||
body: body,
|
||||
});
|
||||
};
|
||||
|
||||
}
|
||||
@@ -12,7 +12,7 @@
|
||||
*/
|
||||
|
||||
import { Observable } from 'rxjs';
|
||||
import { BaseAPI, HttpHeaders, HttpQuery, throwIfNullOrUndefined, encodeURI, COLLECTION_FORMATS } from '../runtime';
|
||||
import { BaseAPI, HttpHeaders, HttpQuery, throwIfNullOrUndefined, encodeURI, COLLECTION_FORMATS, OperationOpts, RawAjaxResponse } from '../runtime';
|
||||
import {
|
||||
ApiResponse,
|
||||
Pet,
|
||||
@@ -63,7 +63,9 @@ export class PetApi extends BaseAPI {
|
||||
/**
|
||||
* Add a new pet to the store
|
||||
*/
|
||||
addPet = ({ body }: AddPetRequest): Observable<void> => {
|
||||
addPet({ body }: AddPetRequest): Observable<void>
|
||||
addPet({ body }: AddPetRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>>
|
||||
addPet({ body }: AddPetRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>> {
|
||||
throwIfNullOrUndefined(body, 'body', 'addPet');
|
||||
|
||||
const headers: HttpHeaders = {
|
||||
@@ -78,17 +80,19 @@ export class PetApi extends BaseAPI {
|
||||
};
|
||||
|
||||
return this.request<void>({
|
||||
path: '/pet',
|
||||
url: '/pet',
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: body,
|
||||
});
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* Deletes a pet
|
||||
*/
|
||||
deletePet = ({ petId, apiKey }: DeletePetRequest): Observable<void> => {
|
||||
deletePet({ petId, apiKey }: DeletePetRequest): Observable<void>
|
||||
deletePet({ petId, apiKey }: DeletePetRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>>
|
||||
deletePet({ petId, apiKey }: DeletePetRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>> {
|
||||
throwIfNullOrUndefined(petId, 'petId', 'deletePet');
|
||||
|
||||
const headers: HttpHeaders = {
|
||||
@@ -103,17 +107,19 @@ export class PetApi extends BaseAPI {
|
||||
};
|
||||
|
||||
return this.request<void>({
|
||||
path: '/pet/{petId}'.replace('{petId}', encodeURI(petId)),
|
||||
url: '/pet/{petId}'.replace('{petId}', encodeURI(petId)),
|
||||
method: 'DELETE',
|
||||
headers,
|
||||
});
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* Multiple status values can be provided with comma separated strings
|
||||
* Finds Pets by status
|
||||
*/
|
||||
findPetsByStatus = ({ status }: FindPetsByStatusRequest): Observable<Array<Pet>> => {
|
||||
findPetsByStatus({ status }: FindPetsByStatusRequest): Observable<Array<Pet>>
|
||||
findPetsByStatus({ status }: FindPetsByStatusRequest, opts?: OperationOpts): Observable<RawAjaxResponse<Array<Pet>>>
|
||||
findPetsByStatus({ status }: FindPetsByStatusRequest, opts?: OperationOpts): Observable<Array<Pet> | RawAjaxResponse<Array<Pet>>> {
|
||||
throwIfNullOrUndefined(status, 'status', 'findPetsByStatus');
|
||||
|
||||
const headers: HttpHeaders = {
|
||||
@@ -131,18 +137,20 @@ export class PetApi extends BaseAPI {
|
||||
};
|
||||
|
||||
return this.request<Array<Pet>>({
|
||||
path: '/pet/findByStatus',
|
||||
url: '/pet/findByStatus',
|
||||
method: 'GET',
|
||||
headers,
|
||||
query,
|
||||
});
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
||||
* Finds Pets by tags
|
||||
*/
|
||||
findPetsByTags = ({ tags }: FindPetsByTagsRequest): Observable<Array<Pet>> => {
|
||||
findPetsByTags({ tags }: FindPetsByTagsRequest): Observable<Array<Pet>>
|
||||
findPetsByTags({ tags }: FindPetsByTagsRequest, opts?: OperationOpts): Observable<RawAjaxResponse<Array<Pet>>>
|
||||
findPetsByTags({ tags }: FindPetsByTagsRequest, opts?: OperationOpts): Observable<Array<Pet> | RawAjaxResponse<Array<Pet>>> {
|
||||
throwIfNullOrUndefined(tags, 'tags', 'findPetsByTags');
|
||||
|
||||
const headers: HttpHeaders = {
|
||||
@@ -160,18 +168,20 @@ export class PetApi extends BaseAPI {
|
||||
};
|
||||
|
||||
return this.request<Array<Pet>>({
|
||||
path: '/pet/findByTags',
|
||||
url: '/pet/findByTags',
|
||||
method: 'GET',
|
||||
headers,
|
||||
query,
|
||||
});
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns a single pet
|
||||
* Find pet by ID
|
||||
*/
|
||||
getPetById = ({ petId }: GetPetByIdRequest): Observable<Pet> => {
|
||||
getPetById({ petId }: GetPetByIdRequest): Observable<Pet>
|
||||
getPetById({ petId }: GetPetByIdRequest, opts?: OperationOpts): Observable<RawAjaxResponse<Pet>>
|
||||
getPetById({ petId }: GetPetByIdRequest, opts?: OperationOpts): Observable<Pet | RawAjaxResponse<Pet>> {
|
||||
throwIfNullOrUndefined(petId, 'petId', 'getPetById');
|
||||
|
||||
const headers: HttpHeaders = {
|
||||
@@ -179,16 +189,18 @@ export class PetApi extends BaseAPI {
|
||||
};
|
||||
|
||||
return this.request<Pet>({
|
||||
path: '/pet/{petId}'.replace('{petId}', encodeURI(petId)),
|
||||
url: '/pet/{petId}'.replace('{petId}', encodeURI(petId)),
|
||||
method: 'GET',
|
||||
headers,
|
||||
});
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* Update an existing pet
|
||||
*/
|
||||
updatePet = ({ body }: UpdatePetRequest): Observable<void> => {
|
||||
updatePet({ body }: UpdatePetRequest): Observable<void>
|
||||
updatePet({ body }: UpdatePetRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>>
|
||||
updatePet({ body }: UpdatePetRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>> {
|
||||
throwIfNullOrUndefined(body, 'body', 'updatePet');
|
||||
|
||||
const headers: HttpHeaders = {
|
||||
@@ -203,17 +215,19 @@ export class PetApi extends BaseAPI {
|
||||
};
|
||||
|
||||
return this.request<void>({
|
||||
path: '/pet',
|
||||
url: '/pet',
|
||||
method: 'PUT',
|
||||
headers,
|
||||
body: body,
|
||||
});
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates a pet in the store with form data
|
||||
*/
|
||||
updatePetWithForm = ({ petId, name, status }: UpdatePetWithFormRequest): Observable<void> => {
|
||||
updatePetWithForm({ petId, name, status }: UpdatePetWithFormRequest): Observable<void>
|
||||
updatePetWithForm({ petId, name, status }: UpdatePetWithFormRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>>
|
||||
updatePetWithForm({ petId, name, status }: UpdatePetWithFormRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>> {
|
||||
throwIfNullOrUndefined(petId, 'petId', 'updatePetWithForm');
|
||||
|
||||
const headers: HttpHeaders = {
|
||||
@@ -231,17 +245,19 @@ export class PetApi extends BaseAPI {
|
||||
if (status !== undefined) { formData.append('status', status as any); }
|
||||
|
||||
return this.request<void>({
|
||||
path: '/pet/{petId}'.replace('{petId}', encodeURI(petId)),
|
||||
url: '/pet/{petId}'.replace('{petId}', encodeURI(petId)),
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: formData,
|
||||
});
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* uploads an image
|
||||
*/
|
||||
uploadFile = ({ petId, additionalMetadata, file }: UploadFileRequest): Observable<ApiResponse> => {
|
||||
uploadFile({ petId, additionalMetadata, file }: UploadFileRequest): Observable<ApiResponse>
|
||||
uploadFile({ petId, additionalMetadata, file }: UploadFileRequest, opts?: OperationOpts): Observable<RawAjaxResponse<ApiResponse>>
|
||||
uploadFile({ petId, additionalMetadata, file }: UploadFileRequest, opts?: OperationOpts): Observable<ApiResponse | RawAjaxResponse<ApiResponse>> {
|
||||
throwIfNullOrUndefined(petId, 'petId', 'uploadFile');
|
||||
|
||||
const headers: HttpHeaders = {
|
||||
@@ -259,11 +275,11 @@ export class PetApi extends BaseAPI {
|
||||
if (file !== undefined) { formData.append('file', file as any); }
|
||||
|
||||
return this.request<ApiResponse>({
|
||||
path: '/pet/{petId}/uploadImage'.replace('{petId}', encodeURI(petId)),
|
||||
url: '/pet/{petId}/uploadImage'.replace('{petId}', encodeURI(petId)),
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: formData,
|
||||
});
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
*/
|
||||
|
||||
import { Observable } from 'rxjs';
|
||||
import { BaseAPI, HttpHeaders, throwIfNullOrUndefined, encodeURI } from '../runtime';
|
||||
import { BaseAPI, HttpHeaders, throwIfNullOrUndefined, encodeURI, OperationOpts, RawAjaxResponse } from '../runtime';
|
||||
import {
|
||||
Order,
|
||||
} from '../models';
|
||||
@@ -38,48 +38,56 @@ export class StoreApi extends BaseAPI {
|
||||
* For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
||||
* Delete purchase order by ID
|
||||
*/
|
||||
deleteOrder = ({ orderId }: DeleteOrderRequest): Observable<void> => {
|
||||
deleteOrder({ orderId }: DeleteOrderRequest): Observable<void>
|
||||
deleteOrder({ orderId }: DeleteOrderRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>>
|
||||
deleteOrder({ orderId }: DeleteOrderRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>> {
|
||||
throwIfNullOrUndefined(orderId, 'orderId', 'deleteOrder');
|
||||
|
||||
return this.request<void>({
|
||||
path: '/store/order/{orderId}'.replace('{orderId}', encodeURI(orderId)),
|
||||
url: '/store/order/{orderId}'.replace('{orderId}', encodeURI(orderId)),
|
||||
method: 'DELETE',
|
||||
});
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns a map of status codes to quantities
|
||||
* Returns pet inventories by status
|
||||
*/
|
||||
getInventory = (): Observable<{ [key: string]: number; }> => {
|
||||
getInventory(): Observable<{ [key: string]: number; }>
|
||||
getInventory(opts?: OperationOpts): Observable<RawAjaxResponse<{ [key: string]: number; }>>
|
||||
getInventory(opts?: OperationOpts): Observable<{ [key: string]: number; } | RawAjaxResponse<{ [key: string]: number; }>> {
|
||||
const headers: HttpHeaders = {
|
||||
...(this.configuration.apiKey && { 'api_key': this.configuration.apiKey('api_key') }), // api_key authentication
|
||||
};
|
||||
|
||||
return this.request<{ [key: string]: number; }>({
|
||||
path: '/store/inventory',
|
||||
url: '/store/inventory',
|
||||
method: 'GET',
|
||||
headers,
|
||||
});
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
|
||||
* Find purchase order by ID
|
||||
*/
|
||||
getOrderById = ({ orderId }: GetOrderByIdRequest): Observable<Order> => {
|
||||
getOrderById({ orderId }: GetOrderByIdRequest): Observable<Order>
|
||||
getOrderById({ orderId }: GetOrderByIdRequest, opts?: OperationOpts): Observable<RawAjaxResponse<Order>>
|
||||
getOrderById({ orderId }: GetOrderByIdRequest, opts?: OperationOpts): Observable<Order | RawAjaxResponse<Order>> {
|
||||
throwIfNullOrUndefined(orderId, 'orderId', 'getOrderById');
|
||||
|
||||
return this.request<Order>({
|
||||
path: '/store/order/{orderId}'.replace('{orderId}', encodeURI(orderId)),
|
||||
url: '/store/order/{orderId}'.replace('{orderId}', encodeURI(orderId)),
|
||||
method: 'GET',
|
||||
});
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* Place an order for a pet
|
||||
*/
|
||||
placeOrder = ({ body }: PlaceOrderRequest): Observable<Order> => {
|
||||
placeOrder({ body }: PlaceOrderRequest): Observable<Order>
|
||||
placeOrder({ body }: PlaceOrderRequest, opts?: OperationOpts): Observable<RawAjaxResponse<Order>>
|
||||
placeOrder({ body }: PlaceOrderRequest, opts?: OperationOpts): Observable<Order | RawAjaxResponse<Order>> {
|
||||
throwIfNullOrUndefined(body, 'body', 'placeOrder');
|
||||
|
||||
const headers: HttpHeaders = {
|
||||
@@ -87,11 +95,11 @@ export class StoreApi extends BaseAPI {
|
||||
};
|
||||
|
||||
return this.request<Order>({
|
||||
path: '/store/order',
|
||||
url: '/store/order',
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: body,
|
||||
});
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
*/
|
||||
|
||||
import { Observable } from 'rxjs';
|
||||
import { BaseAPI, HttpHeaders, HttpQuery, throwIfNullOrUndefined, encodeURI } from '../runtime';
|
||||
import { BaseAPI, HttpHeaders, HttpQuery, throwIfNullOrUndefined, encodeURI, OperationOpts, RawAjaxResponse } from '../runtime';
|
||||
import {
|
||||
User,
|
||||
} from '../models';
|
||||
@@ -56,7 +56,9 @@ export class UserApi extends BaseAPI {
|
||||
* This can only be done by the logged in user.
|
||||
* Create user
|
||||
*/
|
||||
createUser = ({ body }: CreateUserRequest): Observable<void> => {
|
||||
createUser({ body }: CreateUserRequest): Observable<void>
|
||||
createUser({ body }: CreateUserRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>>
|
||||
createUser({ body }: CreateUserRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>> {
|
||||
throwIfNullOrUndefined(body, 'body', 'createUser');
|
||||
|
||||
const headers: HttpHeaders = {
|
||||
@@ -64,17 +66,19 @@ export class UserApi extends BaseAPI {
|
||||
};
|
||||
|
||||
return this.request<void>({
|
||||
path: '/user',
|
||||
url: '/user',
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: body,
|
||||
});
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates list of users with given input array
|
||||
*/
|
||||
createUsersWithArrayInput = ({ body }: CreateUsersWithArrayInputRequest): Observable<void> => {
|
||||
createUsersWithArrayInput({ body }: CreateUsersWithArrayInputRequest): Observable<void>
|
||||
createUsersWithArrayInput({ body }: CreateUsersWithArrayInputRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>>
|
||||
createUsersWithArrayInput({ body }: CreateUsersWithArrayInputRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>> {
|
||||
throwIfNullOrUndefined(body, 'body', 'createUsersWithArrayInput');
|
||||
|
||||
const headers: HttpHeaders = {
|
||||
@@ -82,17 +86,19 @@ export class UserApi extends BaseAPI {
|
||||
};
|
||||
|
||||
return this.request<void>({
|
||||
path: '/user/createWithArray',
|
||||
url: '/user/createWithArray',
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: body,
|
||||
});
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates list of users with given input array
|
||||
*/
|
||||
createUsersWithListInput = ({ body }: CreateUsersWithListInputRequest): Observable<void> => {
|
||||
createUsersWithListInput({ body }: CreateUsersWithListInputRequest): Observable<void>
|
||||
createUsersWithListInput({ body }: CreateUsersWithListInputRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>>
|
||||
createUsersWithListInput({ body }: CreateUsersWithListInputRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>> {
|
||||
throwIfNullOrUndefined(body, 'body', 'createUsersWithListInput');
|
||||
|
||||
const headers: HttpHeaders = {
|
||||
@@ -100,42 +106,48 @@ export class UserApi extends BaseAPI {
|
||||
};
|
||||
|
||||
return this.request<void>({
|
||||
path: '/user/createWithList',
|
||||
url: '/user/createWithList',
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: body,
|
||||
});
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* This can only be done by the logged in user.
|
||||
* Delete user
|
||||
*/
|
||||
deleteUser = ({ username }: DeleteUserRequest): Observable<void> => {
|
||||
deleteUser({ username }: DeleteUserRequest): Observable<void>
|
||||
deleteUser({ username }: DeleteUserRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>>
|
||||
deleteUser({ username }: DeleteUserRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>> {
|
||||
throwIfNullOrUndefined(username, 'username', 'deleteUser');
|
||||
|
||||
return this.request<void>({
|
||||
path: '/user/{username}'.replace('{username}', encodeURI(username)),
|
||||
url: '/user/{username}'.replace('{username}', encodeURI(username)),
|
||||
method: 'DELETE',
|
||||
});
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* Get user by user name
|
||||
*/
|
||||
getUserByName = ({ username }: GetUserByNameRequest): Observable<User> => {
|
||||
getUserByName({ username }: GetUserByNameRequest): Observable<User>
|
||||
getUserByName({ username }: GetUserByNameRequest, opts?: OperationOpts): Observable<RawAjaxResponse<User>>
|
||||
getUserByName({ username }: GetUserByNameRequest, opts?: OperationOpts): Observable<User | RawAjaxResponse<User>> {
|
||||
throwIfNullOrUndefined(username, 'username', 'getUserByName');
|
||||
|
||||
return this.request<User>({
|
||||
path: '/user/{username}'.replace('{username}', encodeURI(username)),
|
||||
url: '/user/{username}'.replace('{username}', encodeURI(username)),
|
||||
method: 'GET',
|
||||
});
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* Logs user into the system
|
||||
*/
|
||||
loginUser = ({ username, password }: LoginUserRequest): Observable<string> => {
|
||||
loginUser({ username, password }: LoginUserRequest): Observable<string>
|
||||
loginUser({ username, password }: LoginUserRequest, opts?: OperationOpts): Observable<RawAjaxResponse<string>>
|
||||
loginUser({ username, password }: LoginUserRequest, opts?: OperationOpts): Observable<string | RawAjaxResponse<string>> {
|
||||
throwIfNullOrUndefined(username, 'username', 'loginUser');
|
||||
throwIfNullOrUndefined(password, 'password', 'loginUser');
|
||||
|
||||
@@ -145,27 +157,31 @@ export class UserApi extends BaseAPI {
|
||||
};
|
||||
|
||||
return this.request<string>({
|
||||
path: '/user/login',
|
||||
url: '/user/login',
|
||||
method: 'GET',
|
||||
query,
|
||||
});
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* Logs out current logged in user session
|
||||
*/
|
||||
logoutUser = (): Observable<void> => {
|
||||
logoutUser(): Observable<void>
|
||||
logoutUser(opts?: OperationOpts): Observable<void | RawAjaxResponse<void>>
|
||||
logoutUser(opts?: OperationOpts): Observable<void | RawAjaxResponse<void>> {
|
||||
return this.request<void>({
|
||||
path: '/user/logout',
|
||||
url: '/user/logout',
|
||||
method: 'GET',
|
||||
});
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* This can only be done by the logged in user.
|
||||
* Updated user
|
||||
*/
|
||||
updateUser = ({ username, body }: UpdateUserRequest): Observable<void> => {
|
||||
updateUser({ username, body }: UpdateUserRequest): Observable<void>
|
||||
updateUser({ username, body }: UpdateUserRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>>
|
||||
updateUser({ username, body }: UpdateUserRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>> {
|
||||
throwIfNullOrUndefined(username, 'username', 'updateUser');
|
||||
throwIfNullOrUndefined(body, 'body', 'updateUser');
|
||||
|
||||
@@ -174,11 +190,11 @@ export class UserApi extends BaseAPI {
|
||||
};
|
||||
|
||||
return this.request<void>({
|
||||
path: '/user/{username}'.replace('{username}', encodeURI(username)),
|
||||
url: '/user/{username}'.replace('{username}', encodeURI(username)),
|
||||
method: 'PUT',
|
||||
headers,
|
||||
body: body,
|
||||
});
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -6,14 +6,14 @@
|
||||
"main": "./dist/index.js",
|
||||
"typings": "./dist/index.d.ts",
|
||||
"scripts" : {
|
||||
"build": "tsc --outDir dist/",
|
||||
"build": "node_modules/.bin/tsc --outDir dist/",
|
||||
"prepare": "npm run build"
|
||||
},
|
||||
"dependencies": {
|
||||
"rxjs": "^6.3.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^3.0.1"
|
||||
"typescript": "^3.7"
|
||||
},
|
||||
"publishConfig": {
|
||||
"registry": "https://skimdb.npmjs.com/registry"
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { Observable, of, Subscriber } from 'rxjs';
|
||||
import { ajax, AjaxRequest, AjaxResponse } from 'rxjs/ajax';
|
||||
import { map, concatMap } from 'rxjs/operators';
|
||||
|
||||
@@ -30,11 +30,11 @@ export class Configuration {
|
||||
constructor(private configuration: ConfigurationParameters = {}) {}
|
||||
|
||||
get basePath(): string {
|
||||
return this.configuration.basePath || BASE_PATH;
|
||||
return this.configuration.basePath ?? BASE_PATH;
|
||||
}
|
||||
|
||||
get middleware(): Middleware[] {
|
||||
return this.configuration.middleware || [];
|
||||
return this.configuration.middleware ?? [];
|
||||
}
|
||||
|
||||
get username(): string | undefined {
|
||||
@@ -47,18 +47,12 @@ export class Configuration {
|
||||
|
||||
get apiKey(): ((name: string) => string) | undefined {
|
||||
const { apiKey } = this.configuration;
|
||||
if (!apiKey) {
|
||||
return undefined;
|
||||
}
|
||||
return typeof apiKey === 'string' ? () => apiKey : apiKey;
|
||||
return apiKey ? (typeof apiKey === 'string' ? () => apiKey : apiKey) : undefined;
|
||||
}
|
||||
|
||||
get accessToken(): ((name: string, scopes?: string[]) => string) | undefined {
|
||||
const { accessToken } = this.configuration;
|
||||
if (!accessToken) {
|
||||
return undefined;
|
||||
}
|
||||
return typeof accessToken === 'string' ? () => accessToken : accessToken;
|
||||
return accessToken ? (typeof accessToken === 'string' ? () => accessToken : accessToken) : undefined;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,31 +78,32 @@ export class BaseAPI {
|
||||
withPostMiddleware = (postMiddlewares: Array<Middleware['post']>) =>
|
||||
this.withMiddleware(postMiddlewares.map((post) => ({ post })));
|
||||
|
||||
protected request = <T>(requestOpts: RequestOpts): Observable<T> =>
|
||||
this.rxjsRequest(this.createRequestArgs(requestOpts)).pipe(
|
||||
protected request<T>(requestOpts: RequestOpts): Observable<T>
|
||||
protected request<T>(requestOpts: RequestOpts, responseOpts?: ResponseOpts): Observable<RawAjaxResponse<T>>
|
||||
protected request<T>(requestOpts: RequestOpts, responseOpts?: ResponseOpts): Observable<T | RawAjaxResponse<T>> {
|
||||
return this.rxjsRequest(this.createRequestArgs(requestOpts)).pipe(
|
||||
map((res) => {
|
||||
if (res.status >= 200 && res.status < 300) {
|
||||
return res.response as T;
|
||||
const { status, response } = res;
|
||||
if (status >= 200 && status < 300) {
|
||||
return responseOpts?.respone === 'raw' ? res : response;
|
||||
}
|
||||
throw res;
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
private createRequestArgs = (requestOpts: RequestOpts): RequestArgs => {
|
||||
let url = this.configuration.basePath + requestOpts.path;
|
||||
if (requestOpts.query !== undefined && Object.keys(requestOpts.query).length !== 0) {
|
||||
// only add the queryString to the URL if there are query parameters.
|
||||
// this is done to avoid urls ending with a '?' character which buggy webservers
|
||||
// do not handle correctly sometimes.
|
||||
url += '?' + queryString(requestOpts.query);
|
||||
}
|
||||
private createRequestArgs = ({ url: baseUrl, query, method, headers, body, responseType }: RequestOpts): RequestArgs => {
|
||||
// only add the queryString to the URL if there are query parameters.
|
||||
// this is done to avoid urls ending with a '?' character which buggy webservers
|
||||
// do not handle correctly sometimes.
|
||||
const url = `${this.configuration.basePath}${baseUrl}${query && Object.keys(query).length ? `?${queryString(query)}`: ''}`;
|
||||
|
||||
return {
|
||||
url,
|
||||
method: requestOpts.method,
|
||||
headers: requestOpts.headers,
|
||||
body: requestOpts.body instanceof FormData ? requestOpts.body : JSON.stringify(requestOpts.body),
|
||||
responseType: requestOpts.responseType || 'json',
|
||||
method,
|
||||
headers,
|
||||
body: body instanceof FormData ? body : JSON.stringify(body),
|
||||
responseType: responseType ?? 'json',
|
||||
};
|
||||
}
|
||||
|
||||
@@ -157,24 +152,35 @@ export type HttpHeaders = { [key: string]: string };
|
||||
export type HttpQuery = Partial<{ [key: string]: string | number | null | boolean | Array<string | number | null | boolean> }>; // partial is needed for strict mode
|
||||
export type HttpBody = Json | FormData;
|
||||
|
||||
export interface RequestOpts {
|
||||
path: string;
|
||||
export interface RequestOpts extends AjaxRequest {
|
||||
query?: HttpQuery; // additional prop
|
||||
// the following props have improved types over AjaxRequest
|
||||
method: HttpMethod;
|
||||
headers?: HttpHeaders;
|
||||
query?: HttpQuery;
|
||||
body?: HttpBody;
|
||||
responseType?: 'json' | 'blob' | 'arraybuffer' | 'text';
|
||||
}
|
||||
|
||||
export const encodeURI = (value: any) => encodeURIComponent(String(value));
|
||||
export interface ResponseOpts {
|
||||
respone?: 'raw';
|
||||
}
|
||||
|
||||
const queryString = (params: HttpQuery): string => Object.keys(params)
|
||||
.map((key) => {
|
||||
const value = params[key];
|
||||
return (value instanceof Array)
|
||||
? value.map((val) => `${encodeURI(key)}=${encodeURI(val)}`).join('&')
|
||||
: `${encodeURI(key)}=${encodeURI(value)}`;
|
||||
})
|
||||
export interface OperationOpts {
|
||||
responseOpts?: ResponseOpts;
|
||||
}
|
||||
|
||||
// AjaxResponse with typed response
|
||||
export interface RawAjaxResponse<T> extends AjaxResponse {
|
||||
response: T;
|
||||
}
|
||||
|
||||
export const encodeURI = (value: any) => encodeURIComponent(`${value}`);
|
||||
|
||||
const queryString = (params: HttpQuery): string => Object.entries(params)
|
||||
.map(([key, value]) => value instanceof Array
|
||||
? value.map((val) => `${encodeURI(key)}=${encodeURI(val)}`).join('&')
|
||||
: `${encodeURI(key)}=${encodeURI(value)}`
|
||||
)
|
||||
.join('&');
|
||||
|
||||
// alias fallback for not being a breaking change
|
||||
|
||||
@@ -8,7 +8,8 @@
|
||||
"rootDir": ".",
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
"dom",
|
||||
"es2017"
|
||||
],
|
||||
"typeRoots": [
|
||||
"node_modules/@types"
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
*/
|
||||
|
||||
import { Observable } from 'rxjs';
|
||||
import { BaseAPI, HttpHeaders, HttpQuery, throwIfNullOrUndefined, encodeURI, COLLECTION_FORMATS } from '../runtime';
|
||||
import { BaseAPI, HttpHeaders, HttpQuery, throwIfNullOrUndefined, encodeURI, COLLECTION_FORMATS, OperationOpts, RawAjaxResponse } from '../runtime';
|
||||
import {
|
||||
ApiResponse,
|
||||
Pet,
|
||||
@@ -63,7 +63,10 @@ export class PetApi extends BaseAPI {
|
||||
/**
|
||||
* Add a new pet to the store
|
||||
*/
|
||||
addPet = ({ body }: AddPetRequest): Observable<void> => {
|
||||
addPet({ body }: AddPetRequest): Observable<void>
|
||||
addPet({ body }: AddPetRequest, opts?: Pick<OperationOpts, 'progressSubscriber'>): Observable<void>
|
||||
addPet({ body }: AddPetRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>>
|
||||
addPet({ body }: AddPetRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>> {
|
||||
throwIfNullOrUndefined(body, 'body', 'addPet');
|
||||
|
||||
const headers: HttpHeaders = {
|
||||
@@ -78,17 +81,21 @@ export class PetApi extends BaseAPI {
|
||||
};
|
||||
|
||||
return this.request<void>({
|
||||
path: '/pet',
|
||||
url: '/pet',
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: body,
|
||||
});
|
||||
progressSubscriber: opts?.progressSubscriber,
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* Deletes a pet
|
||||
*/
|
||||
deletePet = ({ petId, apiKey }: DeletePetRequest): Observable<void> => {
|
||||
deletePet({ petId, apiKey }: DeletePetRequest): Observable<void>
|
||||
deletePet({ petId, apiKey }: DeletePetRequest, opts?: Pick<OperationOpts, 'progressSubscriber'>): Observable<void>
|
||||
deletePet({ petId, apiKey }: DeletePetRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>>
|
||||
deletePet({ petId, apiKey }: DeletePetRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>> {
|
||||
throwIfNullOrUndefined(petId, 'petId', 'deletePet');
|
||||
|
||||
const headers: HttpHeaders = {
|
||||
@@ -103,17 +110,21 @@ export class PetApi extends BaseAPI {
|
||||
};
|
||||
|
||||
return this.request<void>({
|
||||
path: '/pet/{petId}'.replace('{petId}', encodeURI(petId)),
|
||||
url: '/pet/{petId}'.replace('{petId}', encodeURI(petId)),
|
||||
method: 'DELETE',
|
||||
headers,
|
||||
});
|
||||
progressSubscriber: opts?.progressSubscriber,
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* Multiple status values can be provided with comma separated strings
|
||||
* Finds Pets by status
|
||||
*/
|
||||
findPetsByStatus = ({ status }: FindPetsByStatusRequest): Observable<Array<Pet>> => {
|
||||
findPetsByStatus({ status }: FindPetsByStatusRequest): Observable<Array<Pet>>
|
||||
findPetsByStatus({ status }: FindPetsByStatusRequest, opts?: Pick<OperationOpts, 'progressSubscriber'>): Observable<Array<Pet>>
|
||||
findPetsByStatus({ status }: FindPetsByStatusRequest, opts?: OperationOpts): Observable<RawAjaxResponse<Array<Pet>>>
|
||||
findPetsByStatus({ status }: FindPetsByStatusRequest, opts?: OperationOpts): Observable<Array<Pet> | RawAjaxResponse<Array<Pet>>> {
|
||||
throwIfNullOrUndefined(status, 'status', 'findPetsByStatus');
|
||||
|
||||
const headers: HttpHeaders = {
|
||||
@@ -131,18 +142,22 @@ export class PetApi extends BaseAPI {
|
||||
};
|
||||
|
||||
return this.request<Array<Pet>>({
|
||||
path: '/pet/findByStatus',
|
||||
url: '/pet/findByStatus',
|
||||
method: 'GET',
|
||||
headers,
|
||||
query,
|
||||
});
|
||||
progressSubscriber: opts?.progressSubscriber,
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
||||
* Finds Pets by tags
|
||||
*/
|
||||
findPetsByTags = ({ tags }: FindPetsByTagsRequest): Observable<Array<Pet>> => {
|
||||
findPetsByTags({ tags }: FindPetsByTagsRequest): Observable<Array<Pet>>
|
||||
findPetsByTags({ tags }: FindPetsByTagsRequest, opts?: Pick<OperationOpts, 'progressSubscriber'>): Observable<Array<Pet>>
|
||||
findPetsByTags({ tags }: FindPetsByTagsRequest, opts?: OperationOpts): Observable<RawAjaxResponse<Array<Pet>>>
|
||||
findPetsByTags({ tags }: FindPetsByTagsRequest, opts?: OperationOpts): Observable<Array<Pet> | RawAjaxResponse<Array<Pet>>> {
|
||||
throwIfNullOrUndefined(tags, 'tags', 'findPetsByTags');
|
||||
|
||||
const headers: HttpHeaders = {
|
||||
@@ -160,18 +175,22 @@ export class PetApi extends BaseAPI {
|
||||
};
|
||||
|
||||
return this.request<Array<Pet>>({
|
||||
path: '/pet/findByTags',
|
||||
url: '/pet/findByTags',
|
||||
method: 'GET',
|
||||
headers,
|
||||
query,
|
||||
});
|
||||
progressSubscriber: opts?.progressSubscriber,
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns a single pet
|
||||
* Find pet by ID
|
||||
*/
|
||||
getPetById = ({ petId }: GetPetByIdRequest): Observable<Pet> => {
|
||||
getPetById({ petId }: GetPetByIdRequest): Observable<Pet>
|
||||
getPetById({ petId }: GetPetByIdRequest, opts?: Pick<OperationOpts, 'progressSubscriber'>): Observable<Pet>
|
||||
getPetById({ petId }: GetPetByIdRequest, opts?: OperationOpts): Observable<RawAjaxResponse<Pet>>
|
||||
getPetById({ petId }: GetPetByIdRequest, opts?: OperationOpts): Observable<Pet | RawAjaxResponse<Pet>> {
|
||||
throwIfNullOrUndefined(petId, 'petId', 'getPetById');
|
||||
|
||||
const headers: HttpHeaders = {
|
||||
@@ -179,16 +198,20 @@ export class PetApi extends BaseAPI {
|
||||
};
|
||||
|
||||
return this.request<Pet>({
|
||||
path: '/pet/{petId}'.replace('{petId}', encodeURI(petId)),
|
||||
url: '/pet/{petId}'.replace('{petId}', encodeURI(petId)),
|
||||
method: 'GET',
|
||||
headers,
|
||||
});
|
||||
progressSubscriber: opts?.progressSubscriber,
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* Update an existing pet
|
||||
*/
|
||||
updatePet = ({ body }: UpdatePetRequest): Observable<void> => {
|
||||
updatePet({ body }: UpdatePetRequest): Observable<void>
|
||||
updatePet({ body }: UpdatePetRequest, opts?: Pick<OperationOpts, 'progressSubscriber'>): Observable<void>
|
||||
updatePet({ body }: UpdatePetRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>>
|
||||
updatePet({ body }: UpdatePetRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>> {
|
||||
throwIfNullOrUndefined(body, 'body', 'updatePet');
|
||||
|
||||
const headers: HttpHeaders = {
|
||||
@@ -203,17 +226,21 @@ export class PetApi extends BaseAPI {
|
||||
};
|
||||
|
||||
return this.request<void>({
|
||||
path: '/pet',
|
||||
url: '/pet',
|
||||
method: 'PUT',
|
||||
headers,
|
||||
body: body,
|
||||
});
|
||||
progressSubscriber: opts?.progressSubscriber,
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates a pet in the store with form data
|
||||
*/
|
||||
updatePetWithForm = ({ petId, name, status }: UpdatePetWithFormRequest): Observable<void> => {
|
||||
updatePetWithForm({ petId, name, status }: UpdatePetWithFormRequest): Observable<void>
|
||||
updatePetWithForm({ petId, name, status }: UpdatePetWithFormRequest, opts?: Pick<OperationOpts, 'progressSubscriber'>): Observable<void>
|
||||
updatePetWithForm({ petId, name, status }: UpdatePetWithFormRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>>
|
||||
updatePetWithForm({ petId, name, status }: UpdatePetWithFormRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>> {
|
||||
throwIfNullOrUndefined(petId, 'petId', 'updatePetWithForm');
|
||||
|
||||
const headers: HttpHeaders = {
|
||||
@@ -231,17 +258,21 @@ export class PetApi extends BaseAPI {
|
||||
if (status !== undefined) { formData.append('status', status as any); }
|
||||
|
||||
return this.request<void>({
|
||||
path: '/pet/{petId}'.replace('{petId}', encodeURI(petId)),
|
||||
url: '/pet/{petId}'.replace('{petId}', encodeURI(petId)),
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: formData,
|
||||
});
|
||||
progressSubscriber: opts?.progressSubscriber,
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* uploads an image
|
||||
*/
|
||||
uploadFile = ({ petId, additionalMetadata, file }: UploadFileRequest): Observable<ApiResponse> => {
|
||||
uploadFile({ petId, additionalMetadata, file }: UploadFileRequest): Observable<ApiResponse>
|
||||
uploadFile({ petId, additionalMetadata, file }: UploadFileRequest, opts?: Pick<OperationOpts, 'progressSubscriber'>): Observable<ApiResponse>
|
||||
uploadFile({ petId, additionalMetadata, file }: UploadFileRequest, opts?: OperationOpts): Observable<RawAjaxResponse<ApiResponse>>
|
||||
uploadFile({ petId, additionalMetadata, file }: UploadFileRequest, opts?: OperationOpts): Observable<ApiResponse | RawAjaxResponse<ApiResponse>> {
|
||||
throwIfNullOrUndefined(petId, 'petId', 'uploadFile');
|
||||
|
||||
const headers: HttpHeaders = {
|
||||
@@ -259,11 +290,12 @@ export class PetApi extends BaseAPI {
|
||||
if (file !== undefined) { formData.append('file', file as any); }
|
||||
|
||||
return this.request<ApiResponse>({
|
||||
path: '/pet/{petId}/uploadImage'.replace('{petId}', encodeURI(petId)),
|
||||
url: '/pet/{petId}/uploadImage'.replace('{petId}', encodeURI(petId)),
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: formData,
|
||||
});
|
||||
progressSubscriber: opts?.progressSubscriber,
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
// tslint:disable
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
import { Observable } from 'rxjs';
|
||||
import { BaseAPI, HttpHeaders, throwIfNullOrUndefined, encodeURI, OperationOpts, RawAjaxResponse } from '../runtime';
|
||||
import {
|
||||
Order,
|
||||
} from '../models';
|
||||
|
||||
export interface DeleteOrderRequest {
|
||||
orderId: string;
|
||||
}
|
||||
|
||||
export interface GetOrderByIdRequest {
|
||||
orderId: number;
|
||||
}
|
||||
|
||||
export interface PlaceOrderRequest {
|
||||
body: Order;
|
||||
}
|
||||
|
||||
/**
|
||||
* no description
|
||||
*/
|
||||
export class StoreApi extends BaseAPI {
|
||||
|
||||
/**
|
||||
* For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
||||
* Delete purchase order by ID
|
||||
*/
|
||||
deleteOrder({ orderId }: DeleteOrderRequest): Observable<void>
|
||||
deleteOrder({ orderId }: DeleteOrderRequest, opts?: Pick<OperationOpts, 'progressSubscriber'>): Observable<void>
|
||||
deleteOrder({ orderId }: DeleteOrderRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>>
|
||||
deleteOrder({ orderId }: DeleteOrderRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>> {
|
||||
throwIfNullOrUndefined(orderId, 'orderId', 'deleteOrder');
|
||||
|
||||
return this.request<void>({
|
||||
url: '/store/order/{orderId}'.replace('{orderId}', encodeURI(orderId)),
|
||||
method: 'DELETE',
|
||||
progressSubscriber: opts?.progressSubscriber,
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns a map of status codes to quantities
|
||||
* Returns pet inventories by status
|
||||
*/
|
||||
getInventory(): Observable<{ [key: string]: number; }>
|
||||
getInventory(opts?: Pick<OperationOpts, 'progressSubscriber'>): Observable<{ [key: string]: number; }>
|
||||
getInventory(opts?: OperationOpts): Observable<RawAjaxResponse<{ [key: string]: number; }>>
|
||||
getInventory(opts?: OperationOpts): Observable<{ [key: string]: number; } | RawAjaxResponse<{ [key: string]: number; }>> {
|
||||
const headers: HttpHeaders = {
|
||||
...(this.configuration.apiKey && { 'api_key': this.configuration.apiKey('api_key') }), // api_key authentication
|
||||
};
|
||||
|
||||
return this.request<{ [key: string]: number; }>({
|
||||
url: '/store/inventory',
|
||||
method: 'GET',
|
||||
headers,
|
||||
progressSubscriber: opts?.progressSubscriber,
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
|
||||
* Find purchase order by ID
|
||||
*/
|
||||
getOrderById({ orderId }: GetOrderByIdRequest): Observable<Order>
|
||||
getOrderById({ orderId }: GetOrderByIdRequest, opts?: Pick<OperationOpts, 'progressSubscriber'>): Observable<Order>
|
||||
getOrderById({ orderId }: GetOrderByIdRequest, opts?: OperationOpts): Observable<RawAjaxResponse<Order>>
|
||||
getOrderById({ orderId }: GetOrderByIdRequest, opts?: OperationOpts): Observable<Order | RawAjaxResponse<Order>> {
|
||||
throwIfNullOrUndefined(orderId, 'orderId', 'getOrderById');
|
||||
|
||||
return this.request<Order>({
|
||||
url: '/store/order/{orderId}'.replace('{orderId}', encodeURI(orderId)),
|
||||
method: 'GET',
|
||||
progressSubscriber: opts?.progressSubscriber,
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* Place an order for a pet
|
||||
*/
|
||||
placeOrder({ body }: PlaceOrderRequest): Observable<Order>
|
||||
placeOrder({ body }: PlaceOrderRequest, opts?: Pick<OperationOpts, 'progressSubscriber'>): Observable<Order>
|
||||
placeOrder({ body }: PlaceOrderRequest, opts?: OperationOpts): Observable<RawAjaxResponse<Order>>
|
||||
placeOrder({ body }: PlaceOrderRequest, opts?: OperationOpts): Observable<Order | RawAjaxResponse<Order>> {
|
||||
throwIfNullOrUndefined(body, 'body', 'placeOrder');
|
||||
|
||||
const headers: HttpHeaders = {
|
||||
'Content-Type': 'application/json',
|
||||
};
|
||||
|
||||
return this.request<Order>({
|
||||
url: '/store/order',
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: body,
|
||||
progressSubscriber: opts?.progressSubscriber,
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,216 @@
|
||||
// tslint:disable
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
import { Observable } from 'rxjs';
|
||||
import { BaseAPI, HttpHeaders, HttpQuery, throwIfNullOrUndefined, encodeURI, OperationOpts, RawAjaxResponse } from '../runtime';
|
||||
import {
|
||||
User,
|
||||
} from '../models';
|
||||
|
||||
export interface CreateUserRequest {
|
||||
body: User;
|
||||
}
|
||||
|
||||
export interface CreateUsersWithArrayInputRequest {
|
||||
body: Array<User>;
|
||||
}
|
||||
|
||||
export interface CreateUsersWithListInputRequest {
|
||||
body: Array<User>;
|
||||
}
|
||||
|
||||
export interface DeleteUserRequest {
|
||||
username: string;
|
||||
}
|
||||
|
||||
export interface GetUserByNameRequest {
|
||||
username: string;
|
||||
}
|
||||
|
||||
export interface LoginUserRequest {
|
||||
username: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
export interface UpdateUserRequest {
|
||||
username: string;
|
||||
body: User;
|
||||
}
|
||||
|
||||
/**
|
||||
* no description
|
||||
*/
|
||||
export class UserApi extends BaseAPI {
|
||||
|
||||
/**
|
||||
* This can only be done by the logged in user.
|
||||
* Create user
|
||||
*/
|
||||
createUser({ body }: CreateUserRequest): Observable<void>
|
||||
createUser({ body }: CreateUserRequest, opts?: Pick<OperationOpts, 'progressSubscriber'>): Observable<void>
|
||||
createUser({ body }: CreateUserRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>>
|
||||
createUser({ body }: CreateUserRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>> {
|
||||
throwIfNullOrUndefined(body, 'body', 'createUser');
|
||||
|
||||
const headers: HttpHeaders = {
|
||||
'Content-Type': 'application/json',
|
||||
};
|
||||
|
||||
return this.request<void>({
|
||||
url: '/user',
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: body,
|
||||
progressSubscriber: opts?.progressSubscriber,
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates list of users with given input array
|
||||
*/
|
||||
createUsersWithArrayInput({ body }: CreateUsersWithArrayInputRequest): Observable<void>
|
||||
createUsersWithArrayInput({ body }: CreateUsersWithArrayInputRequest, opts?: Pick<OperationOpts, 'progressSubscriber'>): Observable<void>
|
||||
createUsersWithArrayInput({ body }: CreateUsersWithArrayInputRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>>
|
||||
createUsersWithArrayInput({ body }: CreateUsersWithArrayInputRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>> {
|
||||
throwIfNullOrUndefined(body, 'body', 'createUsersWithArrayInput');
|
||||
|
||||
const headers: HttpHeaders = {
|
||||
'Content-Type': 'application/json',
|
||||
};
|
||||
|
||||
return this.request<void>({
|
||||
url: '/user/createWithArray',
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: body,
|
||||
progressSubscriber: opts?.progressSubscriber,
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates list of users with given input array
|
||||
*/
|
||||
createUsersWithListInput({ body }: CreateUsersWithListInputRequest): Observable<void>
|
||||
createUsersWithListInput({ body }: CreateUsersWithListInputRequest, opts?: Pick<OperationOpts, 'progressSubscriber'>): Observable<void>
|
||||
createUsersWithListInput({ body }: CreateUsersWithListInputRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>>
|
||||
createUsersWithListInput({ body }: CreateUsersWithListInputRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>> {
|
||||
throwIfNullOrUndefined(body, 'body', 'createUsersWithListInput');
|
||||
|
||||
const headers: HttpHeaders = {
|
||||
'Content-Type': 'application/json',
|
||||
};
|
||||
|
||||
return this.request<void>({
|
||||
url: '/user/createWithList',
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: body,
|
||||
progressSubscriber: opts?.progressSubscriber,
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* This can only be done by the logged in user.
|
||||
* Delete user
|
||||
*/
|
||||
deleteUser({ username }: DeleteUserRequest): Observable<void>
|
||||
deleteUser({ username }: DeleteUserRequest, opts?: Pick<OperationOpts, 'progressSubscriber'>): Observable<void>
|
||||
deleteUser({ username }: DeleteUserRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>>
|
||||
deleteUser({ username }: DeleteUserRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>> {
|
||||
throwIfNullOrUndefined(username, 'username', 'deleteUser');
|
||||
|
||||
return this.request<void>({
|
||||
url: '/user/{username}'.replace('{username}', encodeURI(username)),
|
||||
method: 'DELETE',
|
||||
progressSubscriber: opts?.progressSubscriber,
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* Get user by user name
|
||||
*/
|
||||
getUserByName({ username }: GetUserByNameRequest): Observable<User>
|
||||
getUserByName({ username }: GetUserByNameRequest, opts?: Pick<OperationOpts, 'progressSubscriber'>): Observable<User>
|
||||
getUserByName({ username }: GetUserByNameRequest, opts?: OperationOpts): Observable<RawAjaxResponse<User>>
|
||||
getUserByName({ username }: GetUserByNameRequest, opts?: OperationOpts): Observable<User | RawAjaxResponse<User>> {
|
||||
throwIfNullOrUndefined(username, 'username', 'getUserByName');
|
||||
|
||||
return this.request<User>({
|
||||
url: '/user/{username}'.replace('{username}', encodeURI(username)),
|
||||
method: 'GET',
|
||||
progressSubscriber: opts?.progressSubscriber,
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* Logs user into the system
|
||||
*/
|
||||
loginUser({ username, password }: LoginUserRequest): Observable<string>
|
||||
loginUser({ username, password }: LoginUserRequest, opts?: Pick<OperationOpts, 'progressSubscriber'>): Observable<string>
|
||||
loginUser({ username, password }: LoginUserRequest, opts?: OperationOpts): Observable<RawAjaxResponse<string>>
|
||||
loginUser({ username, password }: LoginUserRequest, opts?: OperationOpts): Observable<string | RawAjaxResponse<string>> {
|
||||
throwIfNullOrUndefined(username, 'username', 'loginUser');
|
||||
throwIfNullOrUndefined(password, 'password', 'loginUser');
|
||||
|
||||
const query: HttpQuery = { // required parameters are used directly since they are already checked by throwIfNullOrUndefined
|
||||
'username': username,
|
||||
'password': password,
|
||||
};
|
||||
|
||||
return this.request<string>({
|
||||
url: '/user/login',
|
||||
method: 'GET',
|
||||
query,
|
||||
progressSubscriber: opts?.progressSubscriber,
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* Logs out current logged in user session
|
||||
*/
|
||||
logoutUser(): Observable<void>
|
||||
logoutUser(opts?: Pick<OperationOpts, 'progressSubscriber'>): Observable<void>
|
||||
logoutUser(opts?: OperationOpts): Observable<void | RawAjaxResponse<void>>
|
||||
logoutUser(opts?: OperationOpts): Observable<void | RawAjaxResponse<void>> {
|
||||
return this.request<void>({
|
||||
url: '/user/logout',
|
||||
method: 'GET',
|
||||
progressSubscriber: opts?.progressSubscriber,
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
/**
|
||||
* This can only be done by the logged in user.
|
||||
* Updated user
|
||||
*/
|
||||
updateUser({ username, body }: UpdateUserRequest): Observable<void>
|
||||
updateUser({ username, body }: UpdateUserRequest, opts?: Pick<OperationOpts, 'progressSubscriber'>): Observable<void>
|
||||
updateUser({ username, body }: UpdateUserRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>>
|
||||
updateUser({ username, body }: UpdateUserRequest, opts?: OperationOpts): Observable<void | RawAjaxResponse<void>> {
|
||||
throwIfNullOrUndefined(username, 'username', 'updateUser');
|
||||
throwIfNullOrUndefined(body, 'body', 'updateUser');
|
||||
|
||||
const headers: HttpHeaders = {
|
||||
'Content-Type': 'application/json',
|
||||
};
|
||||
|
||||
return this.request<void>({
|
||||
url: '/user/{username}'.replace('{username}', encodeURI(username)),
|
||||
method: 'PUT',
|
||||
headers,
|
||||
body: body,
|
||||
progressSubscriber: opts?.progressSubscriber,
|
||||
}, opts?.responseOpts);
|
||||
};
|
||||
|
||||
}
|
||||
@@ -11,7 +11,7 @@
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { Observable, of, Subscriber } from 'rxjs';
|
||||
import { ajax, AjaxRequest, AjaxResponse } from 'rxjs/ajax';
|
||||
import { map, concatMap } from 'rxjs/operators';
|
||||
|
||||
@@ -30,11 +30,11 @@ export class Configuration {
|
||||
constructor(private configuration: ConfigurationParameters = {}) {}
|
||||
|
||||
get basePath(): string {
|
||||
return this.configuration.basePath || BASE_PATH;
|
||||
return this.configuration.basePath ?? BASE_PATH;
|
||||
}
|
||||
|
||||
get middleware(): Middleware[] {
|
||||
return this.configuration.middleware || [];
|
||||
return this.configuration.middleware ?? [];
|
||||
}
|
||||
|
||||
get username(): string | undefined {
|
||||
@@ -47,18 +47,12 @@ export class Configuration {
|
||||
|
||||
get apiKey(): ((name: string) => string) | undefined {
|
||||
const { apiKey } = this.configuration;
|
||||
if (!apiKey) {
|
||||
return undefined;
|
||||
}
|
||||
return typeof apiKey === 'string' ? () => apiKey : apiKey;
|
||||
return apiKey ? (typeof apiKey === 'string' ? () => apiKey : apiKey) : undefined;
|
||||
}
|
||||
|
||||
get accessToken(): ((name: string, scopes?: string[]) => string) | undefined {
|
||||
const { accessToken } = this.configuration;
|
||||
if (!accessToken) {
|
||||
return undefined;
|
||||
}
|
||||
return typeof accessToken === 'string' ? () => accessToken : accessToken;
|
||||
return accessToken ? (typeof accessToken === 'string' ? () => accessToken : accessToken) : undefined;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,31 +78,33 @@ export class BaseAPI {
|
||||
withPostMiddleware = (postMiddlewares: Array<Middleware['post']>) =>
|
||||
this.withMiddleware(postMiddlewares.map((post) => ({ post })));
|
||||
|
||||
protected request = <T>(requestOpts: RequestOpts): Observable<T> =>
|
||||
this.rxjsRequest(this.createRequestArgs(requestOpts)).pipe(
|
||||
protected request<T>(requestOpts: RequestOpts): Observable<T>
|
||||
protected request<T>(requestOpts: RequestOpts, responseOpts?: ResponseOpts): Observable<RawAjaxResponse<T>>
|
||||
protected request<T>(requestOpts: RequestOpts, responseOpts?: ResponseOpts): Observable<T | RawAjaxResponse<T>> {
|
||||
return this.rxjsRequest(this.createRequestArgs(requestOpts)).pipe(
|
||||
map((res) => {
|
||||
if (res.status >= 200 && res.status < 300) {
|
||||
return res.response as T;
|
||||
const { status, response } = res;
|
||||
if (status >= 200 && status < 300) {
|
||||
return responseOpts?.respone === 'raw' ? res : response;
|
||||
}
|
||||
throw res;
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
private createRequestArgs = (requestOpts: RequestOpts): RequestArgs => {
|
||||
let url = this.configuration.basePath + requestOpts.path;
|
||||
if (requestOpts.query !== undefined && Object.keys(requestOpts.query).length !== 0) {
|
||||
// only add the queryString to the URL if there are query parameters.
|
||||
// this is done to avoid urls ending with a '?' character which buggy webservers
|
||||
// do not handle correctly sometimes.
|
||||
url += '?' + queryString(requestOpts.query);
|
||||
}
|
||||
private createRequestArgs = ({ url: baseUrl, query, method, headers, body, responseType, progressSubscriber }: RequestOpts): RequestArgs => {
|
||||
// only add the queryString to the URL if there are query parameters.
|
||||
// this is done to avoid urls ending with a '?' character which buggy webservers
|
||||
// do not handle correctly sometimes.
|
||||
const url = `${this.configuration.basePath}${baseUrl}${query && Object.keys(query).length ? `?${queryString(query)}`: ''}`;
|
||||
|
||||
return {
|
||||
url,
|
||||
method: requestOpts.method,
|
||||
headers: requestOpts.headers,
|
||||
body: requestOpts.body instanceof FormData ? requestOpts.body : JSON.stringify(requestOpts.body),
|
||||
responseType: requestOpts.responseType || 'json',
|
||||
method,
|
||||
headers,
|
||||
body: body instanceof FormData ? body : JSON.stringify(body),
|
||||
responseType: responseType ?? 'json',
|
||||
progressSubscriber,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -157,24 +153,37 @@ export type HttpHeaders = { [key: string]: string };
|
||||
export type HttpQuery = Partial<{ [key: string]: string | number | null | boolean | Array<string | number | null | boolean> }>; // partial is needed for strict mode
|
||||
export type HttpBody = Json | FormData;
|
||||
|
||||
export interface RequestOpts {
|
||||
path: string;
|
||||
export interface RequestOpts extends AjaxRequest {
|
||||
query?: HttpQuery; // additional prop
|
||||
// the following props have improved types over AjaxRequest
|
||||
method: HttpMethod;
|
||||
headers?: HttpHeaders;
|
||||
query?: HttpQuery;
|
||||
body?: HttpBody;
|
||||
responseType?: 'json' | 'blob' | 'arraybuffer' | 'text';
|
||||
progressSubscriber?: Subscriber<ProgressEvent>;
|
||||
}
|
||||
|
||||
export const encodeURI = (value: any) => encodeURIComponent(String(value));
|
||||
export interface ResponseOpts {
|
||||
respone?: 'raw';
|
||||
}
|
||||
|
||||
const queryString = (params: HttpQuery): string => Object.keys(params)
|
||||
.map((key) => {
|
||||
const value = params[key];
|
||||
return (value instanceof Array)
|
||||
? value.map((val) => `${encodeURI(key)}=${encodeURI(val)}`).join('&')
|
||||
: `${encodeURI(key)}=${encodeURI(value)}`;
|
||||
})
|
||||
export interface OperationOpts {
|
||||
progressSubscriber?: Subscriber<ProgressEvent>;
|
||||
responseOpts?: ResponseOpts;
|
||||
}
|
||||
|
||||
// AjaxResponse with typed response
|
||||
export interface RawAjaxResponse<T> extends AjaxResponse {
|
||||
response: T;
|
||||
}
|
||||
|
||||
export const encodeURI = (value: any) => encodeURIComponent(`${value}`);
|
||||
|
||||
const queryString = (params: HttpQuery): string => Object.entries(params)
|
||||
.map(([key, value]) => value instanceof Array
|
||||
? value.map((val) => `${encodeURI(key)}=${encodeURI(val)}`).join('&')
|
||||
: `${encodeURI(key)}=${encodeURI(value)}`
|
||||
)
|
||||
.join('&');
|
||||
|
||||
// alias fallback for not being a breaking change
|
||||
@@ -8,7 +8,8 @@
|
||||
"rootDir": ".",
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
"dom",
|
||||
"es2017"
|
||||
],
|
||||
"typeRoots": [
|
||||
"node_modules/@types"
|
||||
Reference in New Issue
Block a user