Skip to content

Commit 8078830

Browse files
committed
fix: stabilize Swagger model names for SDK generation
Set definitionPrefix to 'useLabel' so Swagger definitions use Joi label names instead of generic Model1/Model2 names that shift when schemas are added or removed. Rename duplicate .label() values across files to unique descriptive names (e.g., Authentication -> ImapAuthentication, SmtpAuthentication; TLS -> ImapTlsOptions, SmtpTlsOptions) and add missing labels to unlabeled payload/response schemas. Fix IMAPIndexer vs imapIndexer case collision that caused broken model references in generated SDKs on case-insensitive file systems. This ensures generated TypeScript SDKs have stable, descriptive type names across EmailEngine versions.
1 parent e89a924 commit 8078830

File tree

6 files changed

+37
-28
lines changed

6 files changed

+37
-28
lines changed

lib/api-routes/account-routes.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ async function init(args) {
368368
response: {
369369
schema: Joi.object({
370370
account: accountIdSchema.required()
371-
}),
371+
}).label('UpdateAccountResponse'),
372372
failAction: 'log'
373373
}
374374
}
@@ -568,7 +568,7 @@ async function init(args) {
568568
schema: Joi.object({
569569
account: accountIdSchema.required(),
570570
deleted: Joi.boolean().truthy('Y', 'true', '1').falsy('N', 'false', 0).default(true).description('Was the account deleted')
571-
}).label('DeleteRequestResponse'),
571+
}).label('DeleteAccountResponse'),
572572
failAction: 'log'
573573
}
574574
}

lib/api-routes/chat-routes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ async function init(args) {
510510
.description('Chat message to use')
511511
.label('ChatMessage')
512512
.required()
513-
})
513+
}).label('ChatTestPayload')
514514
}
515515
}
516516
});

lib/api-routes/message-routes.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -433,12 +433,12 @@ async function init(args) {
433433
add: Joi.array().items(Joi.string()).example(['\\Seen', '\\Flagged']),
434434
delete: Joi.array().items(Joi.string()).example(['\\Draft']),
435435
set: Joi.array().items(Joi.string()).example(['\\Seen'])
436-
}).label('FlagResponse'),
436+
}).label('FlagUpdateResponse'),
437437
labels: Joi.object({
438438
add: Joi.array().items(Joi.string()).example(['Label1', 'Label2']),
439439
delete: Joi.array().items(Joi.string()).example(['Label3']),
440440
set: Joi.array().items(Joi.string()).example(['Label1'])
441-
}).label('FlagResponse')
441+
}).label('LabelUpdateResponse')
442442
}).label('MessageUpdateResponse'),
443443
failAction: 'log'
444444
}
@@ -513,12 +513,12 @@ async function init(args) {
513513
add: Joi.array().items(Joi.string()).example(['\\Seen', '\\Flagged']),
514514
delete: Joi.array().items(Joi.string()).example(['\\Draft']),
515515
set: Joi.array().items(Joi.string()).example(['\\Seen'])
516-
}).label('FlagResponse'),
516+
}).label('FlagUpdateResponse'),
517517
labels: Joi.object({
518518
add: Joi.array().items(Joi.string()).example(['Label1', 'Label2']),
519519
delete: Joi.array().items(Joi.string()).example(['Label3']),
520520
set: Joi.array().items(Joi.string()).example(['Label1'])
521-
}).label('FlagResponse')
521+
}).label('LabelUpdateResponse')
522522
}).label('MessageUpdateResponse'),
523523
failAction: 'log'
524524
}
@@ -1083,7 +1083,7 @@ async function init(args) {
10831083
.unknown()
10841084
.meta({ swaggerHidden: true })
10851085
})
1086-
.label('SearchQuery')
1086+
.label('MessageSearchPayload')
10871087
.example({
10881088
search: {
10891089
unseen: true,

lib/api-routes/template-routes.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ async function init(args) {
411411
deleted: Joi.boolean().truthy('Y', 'true', '1').falsy('N', 'false', 0).default(true).description('Was the template deleted'),
412412
account: accountIdSchema.required(),
413413
id: Joi.string().max(256).required().example('AAABgS-UcAYAAAABAA').description('Template ID')
414-
}).label('DeleteTemplateRequestResponse'),
414+
}).label('DeleteTemplateResponse'),
415415
failAction: 'log'
416416
}
417417
}
@@ -480,7 +480,7 @@ async function init(args) {
480480
schema: Joi.object({
481481
deleted: Joi.boolean().truthy('Y', 'true', '1').falsy('N', 'false', 0).default(true).description('Were the templates flushed'),
482482
account: accountIdSchema.required()
483-
}).label('DeleteTemplateRequestResponse'),
483+
}).label('FlushTemplatesResponse'),
484484
failAction: 'log'
485485
}
486486
}

lib/schemas.js

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,9 @@ const settingsSchema = {
520520
const addressSchema = Joi.object({
521521
name: Joi.string().trim().empty('').max(256).example('Some Name').description('Display name for the email address'),
522522
address: Joi.string().email({ ignoreLength: false }).example('user@example.com').required().description('Email address')
523-
}).description('Email address with optional display name');
523+
})
524+
.description('Email address with optional display name')
525+
.label('EmailAddress');
524526

525527
// generate a list of boolean values
526528
const settingsQuerySchema = Object.fromEntries(
@@ -555,7 +557,7 @@ const imapSchema = {
555557
otherwise: Joi.optional()
556558
})
557559
.description('Authentication credentials for the IMAP server')
558-
.label('Authentication'),
560+
.label('ImapAuthentication'),
559561

560562
useAuthServer: Joi.boolean().example(false).description('Use external authentication server to retrieve credentials dynamically'),
561563

@@ -586,7 +588,7 @@ const imapSchema = {
586588
})
587589
.unknown()
588590
.description('Advanced TLS configuration options')
589-
.label('TLS'),
591+
.label('ImapTlsOptions'),
590592
resyncDelay: Joi.number().integer().example(RESYNC_DELAY).description('Delay in seconds between full mailbox resynchronizations').default(RESYNC_DELAY),
591593
disabled: Joi.boolean().example(false).description('Temporarily disable IMAP operations for this account'),
592594

@@ -642,7 +644,7 @@ const smtpSchema = {
642644
otherwise: Joi.optional()
643645
})
644646
.description('Authentication credentials for the SMTP server')
645-
.label('Authentication'),
647+
.label('SmtpAuthentication'),
646648

647649
useAuthServer: Joi.boolean().example(false).description('Use external authentication server to retrieve credentials dynamically'),
648650

@@ -664,7 +666,7 @@ const smtpSchema = {
664666
})
665667
.unknown()
666668
.description('Advanced TLS configuration options')
667-
.label('TLS')
669+
.label('SmtpTlsOptions')
668670
};
669671

670672
const oauth2AuthSchema = Joi.object({
@@ -756,7 +758,7 @@ const imapUpdateSchema = {
756758
otherwise: Joi.optional()
757759
})
758760
.description('Authentication credentials for the IMAP server')
759-
.label('Authentication'),
761+
.label('ImapUpdateAuthentication'),
760762

761763
useAuthServer: Joi.boolean().example(false).description('Use external authentication server to retrieve credentials dynamically'),
762764

@@ -769,7 +771,7 @@ const imapUpdateSchema = {
769771
})
770772
.unknown()
771773
.description('Advanced TLS configuration options')
772-
.label('TLS'),
774+
.label('ImapUpdateTlsOptions'),
773775
resyncDelay: Joi.number().integer().example(RESYNC_DELAY).description('Delay in seconds between full mailbox resynchronizations'),
774776

775777
disabled: Joi.boolean().example(false).description('Temporarily disable IMAP operations for this account'),
@@ -807,7 +809,7 @@ const smtpUpdateSchema = {
807809
otherwise: Joi.optional()
808810
})
809811
.description('Authentication credentials for the SMTP server')
810-
.label('Authentication'),
812+
.label('SmtpUpdateAuthentication'),
811813

812814
useAuthServer: Joi.boolean().example(false).description('Use external authentication server to retrieve credentials dynamically'),
813815

@@ -820,7 +822,7 @@ const smtpUpdateSchema = {
820822
})
821823
.unknown()
822824
.description('Advanced TLS configuration options')
823-
.label('TLS')
825+
.label('SmtpUpdateTlsOptions')
824826
};
825827

826828
const oauth2UpdateSchema = {
@@ -1076,7 +1078,7 @@ const licenseSchema = Joi.object({
10761078
.allow(false)
10771079
.label('LicenseDetails'),
10781080
suspended: Joi.boolean().example(false).description('Whether email operations are suspended due to license issues')
1079-
});
1081+
}).label('LicenseInfo');
10801082

10811083
const lastErrorSchema = Joi.object({
10821084
response: Joi.string().example('Token request failed').description('Human-readable error message'),
@@ -1099,7 +1101,10 @@ const lastErrorSchema = Joi.object({
10991101
})
11001102
.description('Raw error response from the OAuth2 server')
11011103
.unknown()
1102-
}).description('Details about the failed OAuth2 token request')
1104+
.label('OAuthTokenErrorResponse')
1105+
})
1106+
.description('Details about the failed OAuth2 token request')
1107+
.label('OAuthTokenRequestError')
11031108
}).label('AccountErrorEntry');
11041109

11051110
const templateSchemas = {
@@ -1286,7 +1291,7 @@ const accountSchemas = {
12861291
.description(
12871292
'Override global IMAP indexing strategy for this account. "full" tracks all changes including deletions, "fast" only detects new messages.'
12881293
)
1289-
.label('IMAPIndexer')
1294+
.label('AccountImapIndexer')
12901295
};
12911296

12921297
const googleProjectIdSchema = Joi.string().trim().allow('', false, null).max(256).example('project-name-425411').description('Google Cloud Project ID');
@@ -1565,7 +1570,9 @@ const outboxEntrySchema = Joi.object({
15651570
envelope: Joi.object({
15661571
from: Joi.string().email().allow('').example('sender@example.com'),
15671572
to: Joi.array().items(Joi.string().email().required().example('recipient@example.com'))
1568-
}).description('SMTP envelope information'),
1573+
})
1574+
.description('SMTP envelope information')
1575+
.label('OutboxEnvelope'),
15691576

15701577
subject: Joi.string()
15711578
.allow('')

workers/api.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,8 @@ Include your token in requests using one of these methods:
921921

922922
security: [{ bearerAuth: [] }],
923923

924+
definitionPrefix: 'useLabel',
925+
924926
cors: !!CORS_CONFIG,
925927
cache: {
926928
expiresIn: 7 * 24 * 60 * 60 * 1000
@@ -5771,7 +5773,7 @@ Include your token in requests using one of these methods:
57715773
.default(false)
57725774
.example(true)
57735775
.description('Should connection use TLS. Usually true for port 465')
5774-
.label('TLS'),
5776+
.label('GatewayTlsOptions'),
57755777

57765778
lastError: lastErrorSchema.allow(null)
57775779
}).label('GatewayResponse'),
@@ -5848,7 +5850,7 @@ Include your token in requests using one of these methods:
58485850
.default(false)
58495851
.example(true)
58505852
.description('Should connection use TLS. Usually true for port 465')
5851-
.label('TLS')
5853+
.label('GatewayCreateTlsOptions')
58525854
}).label('CreateGateway')
58535855
},
58545856

@@ -5934,7 +5936,7 @@ Include your token in requests using one of these methods:
59345936
.falsy('N', 'false', 0, '')
59355937
.example(true)
59365938
.description('Should connection use TLS. Usually true for port 465')
5937-
.label('TLS')
5939+
.label('GatewayUpdateTlsOptions')
59385940
}).label('UpdateGateway')
59395941
},
59405942

@@ -6002,7 +6004,7 @@ Include your token in requests using one of these methods:
60026004
schema: Joi.object({
60036005
gateway: Joi.string().max(256).required().example('example').description('Gateway ID'),
60046006
deleted: Joi.boolean().truthy('Y', 'true', '1').falsy('N', 'false', 0).default(true).description('Was the gateway deleted')
6005-
}).label('DeleteRequestResponse'),
6007+
}).label('DeleteGatewayResponse'),
60066008
failAction: 'log'
60076009
}
60086010
}
@@ -6154,7 +6156,7 @@ Include your token in requests using one of these methods:
61546156
}).label('SignatureResponseItem')
61556157
)
61566158
.label('SignatureEntries')
6157-
}).label('AccountTokenResponse'),
6159+
}).label('AccountSignaturesResponse'),
61586160
failAction: 'log'
61596161
}
61606162
}

0 commit comments

Comments
 (0)