Skip to content

Commit

Permalink
Make all params optional
Browse files Browse the repository at this point in the history
  • Loading branch information
razor-x committed Nov 2, 2023
1 parent 552271c commit da0adf4
Show file tree
Hide file tree
Showing 20 changed files with 96 additions and 89 deletions.
9 changes: 6 additions & 3 deletions generate-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ interface Endpoint {
resource: string | null
method: Method
requestFormat: 'params' | 'body'
isRequestParamOptional: boolean
}

type Method = 'GET' | 'POST'
Expand Down Expand Up @@ -147,6 +148,9 @@ const createEndpoint = (
method,
resource: deriveResource(endpointPath, method),
requestFormat: ['GET', 'DELETE'].includes(method) ? 'params' : 'body',
// UPSTREAM: This could be derived from the OpenAPI spec, however some endpoints require at least one param,
// and in the spec this currently looks as if params are optional.
isRequestParamOptional: true,
}
}

Expand Down Expand Up @@ -298,11 +302,10 @@ const renderClassMethod = ({
namespace,
resource,
path,
isRequestParamOptional,
}: Endpoint): string => `
async ${camelCase(name)}(
${requestFormat}${
requestFormat === 'params' ? '?' : ''
}: ${renderRequestType({
${requestFormat}${isRequestParamOptional ? '?' : ''}: ${renderRequestType({
name,
namespace,
})},
Expand Down
10 changes: 5 additions & 5 deletions src/lib/seam/connect/routes/access-codes-unmanaged.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export class SeamHttpAccessCodesUnmanaged {
}

async convertToManaged(
body: AccessCodesUnmanagedConvertToManagedBody,
body?: AccessCodesUnmanagedConvertToManagedBody,
): Promise<void> {
await this.client.request<AccessCodesUnmanagedConvertToManagedResponse>({
url: '/access_codes/unmanaged/convert_to_managed',
Expand All @@ -92,7 +92,7 @@ export class SeamHttpAccessCodesUnmanaged {
})
}

async delete(body: AccessCodesUnmanagedDeleteBody): Promise<void> {
async delete(body?: AccessCodesUnmanagedDeleteBody): Promise<void> {
await this.client.request<AccessCodesUnmanagedDeleteResponse>({
url: '/access_codes/unmanaged/delete',
method: 'post',
Expand All @@ -101,7 +101,7 @@ export class SeamHttpAccessCodesUnmanaged {
}

async get(
body: AccessCodesUnmanagedGetParams,
body?: AccessCodesUnmanagedGetParams,
): Promise<AccessCodesUnmanagedGetResponse['access_code']> {
const { data } = await this.client.request<AccessCodesUnmanagedGetResponse>(
{
Expand All @@ -114,7 +114,7 @@ export class SeamHttpAccessCodesUnmanaged {
}

async list(
body: AccessCodesUnmanagedListParams,
body?: AccessCodesUnmanagedListParams,
): Promise<AccessCodesUnmanagedListResponse['access_codes']> {
const { data } =
await this.client.request<AccessCodesUnmanagedListResponse>({
Expand All @@ -125,7 +125,7 @@ export class SeamHttpAccessCodesUnmanaged {
return data.access_codes
}

async update(body: AccessCodesUnmanagedUpdateBody): Promise<void> {
async update(body?: AccessCodesUnmanagedUpdateBody): Promise<void> {
await this.client.request<AccessCodesUnmanagedUpdateResponse>({
url: '/access_codes/unmanaged/update',
method: 'post',
Expand Down
16 changes: 8 additions & 8 deletions src/lib/seam/connect/routes/access-codes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export class SeamHttpAccessCodes {
}

async create(
body: AccessCodesCreateBody,
body?: AccessCodesCreateBody,
): Promise<AccessCodesCreateResponse['access_code']> {
const { data } = await this.client.request<AccessCodesCreateResponse>({
url: '/access_codes/create',
Expand All @@ -99,7 +99,7 @@ export class SeamHttpAccessCodes {
}

async createMultiple(
body: AccessCodesCreateMultipleBody,
body?: AccessCodesCreateMultipleBody,
): Promise<AccessCodesCreateMultipleResponse['access_codes']> {
const { data } =
await this.client.request<AccessCodesCreateMultipleResponse>({
Expand All @@ -110,7 +110,7 @@ export class SeamHttpAccessCodes {
return data.access_codes
}

async delete(body: AccessCodesDeleteBody): Promise<void> {
async delete(body?: AccessCodesDeleteBody): Promise<void> {
await this.client.request<AccessCodesDeleteResponse>({
url: '/access_codes/delete',
method: 'post',
Expand All @@ -119,7 +119,7 @@ export class SeamHttpAccessCodes {
}

async generateCode(
body: AccessCodesGenerateCodeBody,
body?: AccessCodesGenerateCodeBody,
): Promise<AccessCodesGenerateCodeResponse['generated_code']> {
const { data } = await this.client.request<AccessCodesGenerateCodeResponse>(
{
Expand All @@ -132,7 +132,7 @@ export class SeamHttpAccessCodes {
}

async get(
body: AccessCodesGetParams,
body?: AccessCodesGetParams,
): Promise<AccessCodesGetResponse['access_code']> {
const { data } = await this.client.request<AccessCodesGetResponse>({
url: '/access_codes/get',
Expand All @@ -143,7 +143,7 @@ export class SeamHttpAccessCodes {
}

async list(
body: AccessCodesListParams,
body?: AccessCodesListParams,
): Promise<AccessCodesListResponse['access_codes']> {
const { data } = await this.client.request<AccessCodesListResponse>({
url: '/access_codes/list',
Expand All @@ -154,7 +154,7 @@ export class SeamHttpAccessCodes {
}

async pullBackupAccessCode(
body: AccessCodesPullBackupAccessCodeBody,
body?: AccessCodesPullBackupAccessCodeBody,
): Promise<AccessCodesPullBackupAccessCodeResponse['backup_access_code']> {
const { data } =
await this.client.request<AccessCodesPullBackupAccessCodeResponse>({
Expand All @@ -165,7 +165,7 @@ export class SeamHttpAccessCodes {
return data.backup_access_code
}

async update(body: AccessCodesUpdateBody): Promise<void> {
async update(body?: AccessCodesUpdateBody): Promise<void> {
await this.client.request<AccessCodesUpdateResponse>({
url: '/access_codes/update',
method: 'post',
Expand Down
16 changes: 8 additions & 8 deletions src/lib/seam/connect/routes/acs-access-groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class SeamHttpAcsAccessGroups {
return SeamHttpAcsAccessGroups.fromClientSessionToken(token, options)
}

async addUser(body: AcsAccessGroupsAddUserBody): Promise<void> {
async addUser(body?: AcsAccessGroupsAddUserBody): Promise<void> {
await this.client.request<AcsAccessGroupsAddUserResponse>({
url: '/acs/access_groups/add_user',
method: 'post',
Expand All @@ -91,7 +91,7 @@ export class SeamHttpAcsAccessGroups {
}

async create(
body: AcsAccessGroupsCreateBody,
body?: AcsAccessGroupsCreateBody,
): Promise<AcsAccessGroupsCreateResponse['acs_access_group']> {
const { data } = await this.client.request<AcsAccessGroupsCreateResponse>({
url: '/acs/access_groups/create',
Expand All @@ -101,7 +101,7 @@ export class SeamHttpAcsAccessGroups {
return data.acs_access_group
}

async delete(body: AcsAccessGroupsDeleteBody): Promise<void> {
async delete(body?: AcsAccessGroupsDeleteBody): Promise<void> {
await this.client.request<AcsAccessGroupsDeleteResponse>({
url: '/acs/access_groups/delete',
method: 'post',
Expand All @@ -110,7 +110,7 @@ export class SeamHttpAcsAccessGroups {
}

async get(
body: AcsAccessGroupsGetParams,
body?: AcsAccessGroupsGetParams,
): Promise<AcsAccessGroupsGetResponse['acs_access_group']> {
const { data } = await this.client.request<AcsAccessGroupsGetResponse>({
url: '/acs/access_groups/get',
Expand All @@ -121,7 +121,7 @@ export class SeamHttpAcsAccessGroups {
}

async list(
body: AcsAccessGroupsListParams,
body?: AcsAccessGroupsListParams,
): Promise<AcsAccessGroupsListResponse['acs_access_groups']> {
const { data } = await this.client.request<AcsAccessGroupsListResponse>({
url: '/acs/access_groups/list',
Expand All @@ -132,7 +132,7 @@ export class SeamHttpAcsAccessGroups {
}

async listUsers(
body: AcsAccessGroupsListUsersParams,
body?: AcsAccessGroupsListUsersParams,
): Promise<AcsAccessGroupsListUsersResponse['acs_users']> {
const { data } =
await this.client.request<AcsAccessGroupsListUsersResponse>({
Expand All @@ -143,15 +143,15 @@ export class SeamHttpAcsAccessGroups {
return data.acs_users
}

async removeUser(body: AcsAccessGroupsRemoveUserBody): Promise<void> {
async removeUser(body?: AcsAccessGroupsRemoveUserBody): Promise<void> {
await this.client.request<AcsAccessGroupsRemoveUserResponse>({
url: '/acs/access_groups/remove_user',
method: 'post',
data: body,
})
}

async update(body: AcsAccessGroupsUpdateBody): Promise<void> {
async update(body?: AcsAccessGroupsUpdateBody): Promise<void> {
await this.client.request<AcsAccessGroupsUpdateResponse>({
url: '/acs/access_groups/update',
method: 'post',
Expand Down
8 changes: 4 additions & 4 deletions src/lib/seam/connect/routes/acs-credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export class SeamHttpAcsCredentials {
}

async create(
body: AcsCredentialsCreateBody,
body?: AcsCredentialsCreateBody,
): Promise<AcsCredentialsCreateResponse['acs_credential']> {
const { data } = await this.client.request<AcsCredentialsCreateResponse>({
url: '/acs/credentials/create',
Expand All @@ -93,7 +93,7 @@ export class SeamHttpAcsCredentials {
return data.acs_credential
}

async delete(body: AcsCredentialsDeleteBody): Promise<void> {
async delete(body?: AcsCredentialsDeleteBody): Promise<void> {
await this.client.request<AcsCredentialsDeleteResponse>({
url: '/acs/credentials/delete',
method: 'post',
Expand All @@ -102,7 +102,7 @@ export class SeamHttpAcsCredentials {
}

async get(
body: AcsCredentialsGetParams,
body?: AcsCredentialsGetParams,
): Promise<AcsCredentialsGetResponse['acs_credential']> {
const { data } = await this.client.request<AcsCredentialsGetResponse>({
url: '/acs/credentials/get',
Expand All @@ -113,7 +113,7 @@ export class SeamHttpAcsCredentials {
}

async list(
body: AcsCredentialsListParams,
body?: AcsCredentialsListParams,
): Promise<AcsCredentialsListResponse['acs_credentials']> {
const { data } = await this.client.request<AcsCredentialsListResponse>({
url: '/acs/credentials/list',
Expand Down
4 changes: 2 additions & 2 deletions src/lib/seam/connect/routes/acs-systems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export class SeamHttpAcsSystems {
}

async get(
body: AcsSystemsGetParams,
body?: AcsSystemsGetParams,
): Promise<AcsSystemsGetResponse['acs_system']> {
const { data } = await this.client.request<AcsSystemsGetResponse>({
url: '/acs/systems/get',
Expand All @@ -94,7 +94,7 @@ export class SeamHttpAcsSystems {
}

async list(
body: AcsSystemsListParams,
body?: AcsSystemsListParams,
): Promise<AcsSystemsListResponse['acs_systems']> {
const { data } = await this.client.request<AcsSystemsListResponse>({
url: '/acs/systems/list',
Expand Down
20 changes: 11 additions & 9 deletions src/lib/seam/connect/routes/acs-users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class SeamHttpAcsUsers {
return SeamHttpAcsUsers.fromClientSessionToken(token, options)
}

async addToAccessGroup(body: AcsUsersAddToAccessGroupBody): Promise<void> {
async addToAccessGroup(body?: AcsUsersAddToAccessGroupBody): Promise<void> {
await this.client.request<AcsUsersAddToAccessGroupResponse>({
url: '/acs/users/add_to_access_group',
method: 'post',
Expand All @@ -91,7 +91,7 @@ export class SeamHttpAcsUsers {
}

async create(
body: AcsUsersCreateBody,
body?: AcsUsersCreateBody,
): Promise<AcsUsersCreateResponse['acs_user']> {
const { data } = await this.client.request<AcsUsersCreateResponse>({
url: '/acs/users/create',
Expand All @@ -101,15 +101,17 @@ export class SeamHttpAcsUsers {
return data.acs_user
}

async delete(body: AcsUsersDeleteBody): Promise<void> {
async delete(body?: AcsUsersDeleteBody): Promise<void> {
await this.client.request<AcsUsersDeleteResponse>({
url: '/acs/users/delete',
method: 'post',
data: body,
})
}

async get(body: AcsUsersGetParams): Promise<AcsUsersGetResponse['acs_user']> {
async get(
body?: AcsUsersGetParams,
): Promise<AcsUsersGetResponse['acs_user']> {
const { data } = await this.client.request<AcsUsersGetResponse>({
url: '/acs/users/get',
method: 'post',
Expand All @@ -119,7 +121,7 @@ export class SeamHttpAcsUsers {
}

async list(
body: AcsUsersListParams,
body?: AcsUsersListParams,
): Promise<AcsUsersListResponse['acs_users']> {
const { data } = await this.client.request<AcsUsersListResponse>({
url: '/acs/users/list',
Expand All @@ -130,7 +132,7 @@ export class SeamHttpAcsUsers {
}

async removeFromAccessGroup(
body: AcsUsersRemoveFromAccessGroupBody,
body?: AcsUsersRemoveFromAccessGroupBody,
): Promise<void> {
await this.client.request<AcsUsersRemoveFromAccessGroupResponse>({
url: '/acs/users/remove_from_access_group',
Expand All @@ -139,23 +141,23 @@ export class SeamHttpAcsUsers {
})
}

async suspend(body: AcsUsersSuspendBody): Promise<void> {
async suspend(body?: AcsUsersSuspendBody): Promise<void> {
await this.client.request<AcsUsersSuspendResponse>({
url: '/acs/users/suspend',
method: 'post',
data: body,
})
}

async unsuspend(body: AcsUsersUnsuspendBody): Promise<void> {
async unsuspend(body?: AcsUsersUnsuspendBody): Promise<void> {
await this.client.request<AcsUsersUnsuspendResponse>({
url: '/acs/users/unsuspend',
method: 'post',
data: body,
})
}

async update(body: AcsUsersUpdateBody): Promise<void> {
async update(body?: AcsUsersUpdateBody): Promise<void> {
await this.client.request<AcsUsersUpdateResponse>({
url: '/acs/users/update',
method: 'post',
Expand Down
4 changes: 2 additions & 2 deletions src/lib/seam/connect/routes/action-attempts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export class SeamHttpActionAttempts {
}

async get(
body: ActionAttemptsGetParams,
body?: ActionAttemptsGetParams,
): Promise<ActionAttemptsGetResponse['action_attempt']> {
const { data } = await this.client.request<ActionAttemptsGetResponse>({
url: '/action_attempts/get',
Expand All @@ -94,7 +94,7 @@ export class SeamHttpActionAttempts {
}

async list(
body: ActionAttemptsListParams,
body?: ActionAttemptsListParams,
): Promise<ActionAttemptsListResponse['action_attempts']> {
const { data } = await this.client.request<ActionAttemptsListResponse>({
url: '/action_attempts/list',
Expand Down
Loading

0 comments on commit da0adf4

Please sign in to comment.