Skip to content

Commit

Permalink
improve example
Browse files Browse the repository at this point in the history
  • Loading branch information
inkognitro committed Apr 21, 2024
1 parent daed546 commit 6f8134b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
15 changes: 8 additions & 7 deletions src/templates/ts/_example/authenticate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import {

export const authenticateEndpointId = {
method: 'post',
path: '/v1/authenticate',
path: '/v1/auth/authenticate',
};

type OkAuthenticateResponse = Response<StatusCode.OK, {accessToken: string}>;
type BadRequestAuthenticateResponse = Response<StatusCode.BAD_REQUEST>;
type OkAuthenticateResponse = Response<StatusCode.Ok, {accessToken: string}>;
type BadRequestAuthenticateResponse = Response<StatusCode.BadRequest>;

export type AuthenticateResponse =
| OkAuthenticateResponse
Expand All @@ -25,21 +25,22 @@ export type AuthenticateRequestResult = RequestResult<
AuthenticateResponse
>;

export type AuthenticateParams = {
export type AuthenticatePayload = {
emailOrUsername: string;
password: string;
};

export function authenticate(
requestHandler: RequestHandler,
params: AuthenticateParams,
payload: AuthenticatePayload,
config?: RequestExecutionConfig
): Promise<AuthenticateRequestResult> {
const request = createRequest({
endpointId: authenticateEndpointId,
contentType: 'application/json',
body: {
emailOrUsername: params.emailOrUsername,
password: params.password,
emailOrUsername: payload.emailOrUsername,
password: payload.password,
},
});
return requestHandler.execute(request, config);
Expand Down
1 change: 1 addition & 0 deletions src/templates/ts/_example/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './authenticate';
export * from './uploadFile';
3 changes: 3 additions & 0 deletions src/templates/ts/core/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export type Request<
Body extends object = any,
> = {
endpointId: EndpointId;
contentType: string;
url: string;
supportedSecuritySchemes: string[];
securityScheme: null | string;
Expand All @@ -52,6 +53,7 @@ export type Request<

type RequestCreationSettings = {
endpointId: EndpointId;
contentType: string;
supportedSecuritySchemes?: [];
urlParams?: UrlParameters;
headers?: {};
Expand All @@ -62,6 +64,7 @@ type RequestCreationSettings = {
export function createRequest(settings: RequestCreationSettings): Request {
return {
endpointId: settings.endpointId,
contentType: settings.contentType,
supportedSecuritySchemes: settings.supportedSecuritySchemes ?? [],
securityScheme: null,
url: createRequestUrl(settings.endpointId.path, settings.urlParams ?? {}),
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"@oas3/*": ["./oas3/*"]
},
"lib": [
"ES2021.String"
"ES2021.String",
"DOM"
],
"plugins": [
{ "transform": "typescript-transform-paths" },
Expand Down

0 comments on commit 6f8134b

Please sign in to comment.