Skip to content

Commit 469afb9

Browse files
feat(ts): strict checks during deserialization (box/box-codegen#484) (#185)
1 parent 3bd6076 commit 469afb9

File tree

272 files changed

+16894
-969
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

272 files changed

+16894
-969
lines changed

.codegen.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "engineHash": "5012b13", "specHash": "d5769a1", "version": "0.5.4" }
1+
{ "engineHash": "3d5462a", "specHash": "d5769a1", "version": "0.5.4" }

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/box/jwtAuth.generated.ts

Lines changed: 97 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,10 +318,51 @@ export function serializeJwtConfigAppSettingsAppAuth(
318318
};
319319
}
320320
export function deserializeJwtConfigAppSettingsAppAuth(
321-
val: any
321+
val: SerializedData
322322
): JwtConfigAppSettingsAppAuth {
323+
if (!sdIsMap(val)) {
324+
throw new BoxSdkError({
325+
message: 'Expecting a map for "JwtConfigAppSettingsAppAuth"',
326+
});
327+
}
328+
if (val.publicKeyID == void 0) {
329+
throw new BoxSdkError({
330+
message:
331+
'Expecting "publicKeyID" of type "JwtConfigAppSettingsAppAuth" to be defined',
332+
});
333+
}
334+
if (!sdIsString(val.publicKeyID)) {
335+
throw new BoxSdkError({
336+
message:
337+
'Expecting string for "publicKeyID" of type "JwtConfigAppSettingsAppAuth"',
338+
});
339+
}
323340
const publicKeyId: string = val.publicKeyID;
341+
if (val.privateKey == void 0) {
342+
throw new BoxSdkError({
343+
message:
344+
'Expecting "privateKey" of type "JwtConfigAppSettingsAppAuth" to be defined',
345+
});
346+
}
347+
if (!sdIsString(val.privateKey)) {
348+
throw new BoxSdkError({
349+
message:
350+
'Expecting string for "privateKey" of type "JwtConfigAppSettingsAppAuth"',
351+
});
352+
}
324353
const privateKey: string = val.privateKey;
354+
if (val.passphrase == void 0) {
355+
throw new BoxSdkError({
356+
message:
357+
'Expecting "passphrase" of type "JwtConfigAppSettingsAppAuth" to be defined',
358+
});
359+
}
360+
if (!sdIsString(val.passphrase)) {
361+
throw new BoxSdkError({
362+
message:
363+
'Expecting string for "passphrase" of type "JwtConfigAppSettingsAppAuth"',
364+
});
365+
}
325366
const passphrase: string = val.passphrase;
326367
return {
327368
publicKeyId: publicKeyId,
@@ -339,10 +380,44 @@ export function serializeJwtConfigAppSettings(
339380
};
340381
}
341382
export function deserializeJwtConfigAppSettings(
342-
val: any
383+
val: SerializedData
343384
): JwtConfigAppSettings {
385+
if (!sdIsMap(val)) {
386+
throw new BoxSdkError({
387+
message: 'Expecting a map for "JwtConfigAppSettings"',
388+
});
389+
}
390+
if (val.clientID == void 0) {
391+
throw new BoxSdkError({
392+
message:
393+
'Expecting "clientID" of type "JwtConfigAppSettings" to be defined',
394+
});
395+
}
396+
if (!sdIsString(val.clientID)) {
397+
throw new BoxSdkError({
398+
message: 'Expecting string for "clientID" of type "JwtConfigAppSettings"',
399+
});
400+
}
344401
const clientId: string = val.clientID;
402+
if (val.clientSecret == void 0) {
403+
throw new BoxSdkError({
404+
message:
405+
'Expecting "clientSecret" of type "JwtConfigAppSettings" to be defined',
406+
});
407+
}
408+
if (!sdIsString(val.clientSecret)) {
409+
throw new BoxSdkError({
410+
message:
411+
'Expecting string for "clientSecret" of type "JwtConfigAppSettings"',
412+
});
413+
}
345414
const clientSecret: string = val.clientSecret;
415+
if (val.appAuth == void 0) {
416+
throw new BoxSdkError({
417+
message:
418+
'Expecting "appAuth" of type "JwtConfigAppSettings" to be defined',
419+
});
420+
}
346421
const appAuth: JwtConfigAppSettingsAppAuth =
347422
deserializeJwtConfigAppSettingsAppAuth(val.appAuth);
348423
return {
@@ -358,10 +433,29 @@ export function serializeJwtConfigFile(val: JwtConfigFile): SerializedData {
358433
['boxAppSettings']: serializeJwtConfigAppSettings(val.boxAppSettings),
359434
};
360435
}
361-
export function deserializeJwtConfigFile(val: any): JwtConfigFile {
436+
export function deserializeJwtConfigFile(val: SerializedData): JwtConfigFile {
437+
if (!sdIsMap(val)) {
438+
throw new BoxSdkError({ message: 'Expecting a map for "JwtConfigFile"' });
439+
}
440+
if (!(val.enterpriseID == void 0) && !sdIsString(val.enterpriseID)) {
441+
throw new BoxSdkError({
442+
message: 'Expecting string for "enterpriseID" of type "JwtConfigFile"',
443+
});
444+
}
362445
const enterpriseId: undefined | string =
363446
val.enterpriseID == void 0 ? void 0 : val.enterpriseID;
447+
if (!(val.userID == void 0) && !sdIsString(val.userID)) {
448+
throw new BoxSdkError({
449+
message: 'Expecting string for "userID" of type "JwtConfigFile"',
450+
});
451+
}
364452
const userId: undefined | string = val.userID == void 0 ? void 0 : val.userID;
453+
if (val.boxAppSettings == void 0) {
454+
throw new BoxSdkError({
455+
message:
456+
'Expecting "boxAppSettings" of type "JwtConfigFile" to be defined',
457+
});
458+
}
365459
const boxAppSettings: JwtConfigAppSettings = deserializeJwtConfigAppSettings(
366460
val.boxAppSettings
367461
);

src/managers/authorization.generated.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ export function serializeAuthorizeUserQueryParamsResponseTypeField(
366366
return val;
367367
}
368368
export function deserializeAuthorizeUserQueryParamsResponseTypeField(
369-
val: any
369+
val: SerializedData
370370
): AuthorizeUserQueryParamsResponseTypeField {
371371
if (!sdIsString(val)) {
372372
throw new BoxSdkError({

src/managers/chunkedUploads.generated.ts

Lines changed: 86 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import { readByteStream } from '../internal/utils.js';
4040
import { reduceIterator } from '../internal/utils.js';
4141
import { Hash } from '../internal/utils.js';
4242
import { bufferLength } from '../internal/utils.js';
43+
import { BoxSdkError } from '../box/errors.js';
4344
import { sdIsEmpty } from '../serialization/json.js';
4445
import { sdIsBoolean } from '../serialization/json.js';
4546
import { sdIsNumber } from '../serialization/json.js';
@@ -833,10 +834,51 @@ export function serializeCreateFileUploadSessionRequestBody(
833834
};
834835
}
835836
export function deserializeCreateFileUploadSessionRequestBody(
836-
val: any
837+
val: SerializedData
837838
): CreateFileUploadSessionRequestBody {
839+
if (!sdIsMap(val)) {
840+
throw new BoxSdkError({
841+
message: 'Expecting a map for "CreateFileUploadSessionRequestBody"',
842+
});
843+
}
844+
if (val.folder_id == void 0) {
845+
throw new BoxSdkError({
846+
message:
847+
'Expecting "folder_id" of type "CreateFileUploadSessionRequestBody" to be defined',
848+
});
849+
}
850+
if (!sdIsString(val.folder_id)) {
851+
throw new BoxSdkError({
852+
message:
853+
'Expecting string for "folder_id" of type "CreateFileUploadSessionRequestBody"',
854+
});
855+
}
838856
const folderId: string = val.folder_id;
857+
if (val.file_size == void 0) {
858+
throw new BoxSdkError({
859+
message:
860+
'Expecting "file_size" of type "CreateFileUploadSessionRequestBody" to be defined',
861+
});
862+
}
863+
if (!sdIsNumber(val.file_size)) {
864+
throw new BoxSdkError({
865+
message:
866+
'Expecting number for "file_size" of type "CreateFileUploadSessionRequestBody"',
867+
});
868+
}
839869
const fileSize: number = val.file_size;
870+
if (val.file_name == void 0) {
871+
throw new BoxSdkError({
872+
message:
873+
'Expecting "file_name" of type "CreateFileUploadSessionRequestBody" to be defined',
874+
});
875+
}
876+
if (!sdIsString(val.file_name)) {
877+
throw new BoxSdkError({
878+
message:
879+
'Expecting string for "file_name" of type "CreateFileUploadSessionRequestBody"',
880+
});
881+
}
840882
const fileName: string = val.file_name;
841883
return {
842884
folderId: folderId,
@@ -853,9 +895,33 @@ export function serializeCreateFileUploadSessionForExistingFileRequestBody(
853895
};
854896
}
855897
export function deserializeCreateFileUploadSessionForExistingFileRequestBody(
856-
val: any
898+
val: SerializedData
857899
): CreateFileUploadSessionForExistingFileRequestBody {
900+
if (!sdIsMap(val)) {
901+
throw new BoxSdkError({
902+
message:
903+
'Expecting a map for "CreateFileUploadSessionForExistingFileRequestBody"',
904+
});
905+
}
906+
if (val.file_size == void 0) {
907+
throw new BoxSdkError({
908+
message:
909+
'Expecting "file_size" of type "CreateFileUploadSessionForExistingFileRequestBody" to be defined',
910+
});
911+
}
912+
if (!sdIsNumber(val.file_size)) {
913+
throw new BoxSdkError({
914+
message:
915+
'Expecting number for "file_size" of type "CreateFileUploadSessionForExistingFileRequestBody"',
916+
});
917+
}
858918
const fileSize: number = val.file_size;
919+
if (!(val.file_name == void 0) && !sdIsString(val.file_name)) {
920+
throw new BoxSdkError({
921+
message:
922+
'Expecting string for "file_name" of type "CreateFileUploadSessionForExistingFileRequestBody"',
923+
});
924+
}
859925
const fileName: undefined | string =
860926
val.file_name == void 0 ? void 0 : val.file_name;
861927
return {
@@ -873,8 +939,25 @@ export function serializeCreateFileUploadSessionCommitRequestBody(
873939
};
874940
}
875941
export function deserializeCreateFileUploadSessionCommitRequestBody(
876-
val: any
942+
val: SerializedData
877943
): CreateFileUploadSessionCommitRequestBody {
944+
if (!sdIsMap(val)) {
945+
throw new BoxSdkError({
946+
message: 'Expecting a map for "CreateFileUploadSessionCommitRequestBody"',
947+
});
948+
}
949+
if (val.parts == void 0) {
950+
throw new BoxSdkError({
951+
message:
952+
'Expecting "parts" of type "CreateFileUploadSessionCommitRequestBody" to be defined',
953+
});
954+
}
955+
if (!sdIsList(val.parts)) {
956+
throw new BoxSdkError({
957+
message:
958+
'Expecting array for "parts" of type "CreateFileUploadSessionCommitRequestBody"',
959+
});
960+
}
878961
const parts: readonly UploadPart[] = sdIsList(val.parts)
879962
? (val.parts.map(function (itm: SerializedData): UploadPart {
880963
return deserializeUploadPart(itm);

0 commit comments

Comments
 (0)