Skip to content

Commit 4e7e064

Browse files
committed
fix: add labels to remaining Joi schemas for stable OpenAPI names
Add explicit .label() calls to Joi schema definitions to eliminate lowercase and numeric-suffix schema names in the generated OpenAPI spec. - Add labels to DSN, envelope, attachment, and format fields in api.js - Add labels to OAuth2, export, outbox, and webhook schemas in schemas.js - Add unique labels to flag/label update responses in message-routes.js - Add format labels to template schemas in template-routes.js - Add state and baseScopes labels in account-routes.js Reduces lowercase schemas from 71 to 0 and numeric suffixes from 26 to 9 (remaining are structural collisions with identical schemas).
1 parent a9cffe1 commit 4e7e064

File tree

5 files changed

+229
-129
lines changed

5 files changed

+229
-129
lines changed

lib/api-routes/account-routes.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,8 @@ async function init(args) {
732732
.required()
733733
.valid('init', 'syncing', 'connecting', 'connected', 'authenticationError', 'connectError', 'unset', 'disconnected')
734734
.example('connected')
735-
.description('Account state'),
735+
.description('Account state')
736+
.label('AccountListState'),
736737
webhooks: Joi.string()
737738
.uri({
738739
scheme: ['http', 'https'],
@@ -995,7 +996,8 @@ async function init(args) {
995996
.trim()
996997
.valid(...['imap', 'api', 'pubsub'])
997998
.example('imap')
998-
.description('OAuth2 Base Scopes'),
999+
.description('OAuth2 Base Scopes')
1000+
.label('AccountBaseScopes'),
9991001

10001002
counters: accountCountersSchema,
10011003

lib/api-routes/message-routes.js

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ async function init(args) {
147147
.lowercase()
148148
.valid('html', 'plain', '*')
149149
.example('*')
150-
.description('Which text content to return, use * for all. By default text content is not returned.'),
150+
.description('Which text content to return, use * for all. By default text content is not returned.')
151+
.label('MessageTextType'),
151152

152153
webSafeHtml: Joi.boolean()
153154
.truthy('Y', 'true', '1')
@@ -310,9 +311,9 @@ async function init(args) {
310311
}),
311312

312313
contentType: Joi.string().lowercase().max(256).example('image/gif'),
313-
contentDisposition: Joi.string().lowercase().valid('inline', 'attachment'),
314+
contentDisposition: Joi.string().lowercase().valid('inline', 'attachment').label('MsgUploadContentDisposition'),
314315
cid: Joi.string().max(256).example('unique-image-id@localhost').description('Content-ID value for embedded images'),
315-
encoding: Joi.string().valid('base64').default('base64'),
316+
encoding: Joi.string().valid('base64').default('base64').label('MsgUploadEncoding'),
316317

317318
reference: Joi.string()
318319
.base64({ paddingRequired: false, urlSafe: true })
@@ -322,6 +323,7 @@ async function init(args) {
322323
.description(
323324
'References an existing attachment by its ID instead of providing new attachment content. If this field is set, the `content` field must not be included. If not set, the `content` field is required.'
324325
)
326+
.label('MsgUploadReference')
325327
}).label('UploadAttachment')
326328
)
327329
.description('List of attachments')
@@ -430,14 +432,14 @@ async function init(args) {
430432
response: {
431433
schema: Joi.object({
432434
flags: Joi.object({
433-
add: Joi.array().items(Joi.string()).example(['\\Seen', '\\Flagged']),
434-
delete: Joi.array().items(Joi.string()).example(['\\Draft']),
435-
set: Joi.array().items(Joi.string()).example(['\\Seen'])
435+
add: Joi.array().items(Joi.string().label('FlagEntry')).example(['\\Seen', '\\Flagged']).label('FlagAddList'),
436+
delete: Joi.array().items(Joi.string().label('FlagEntry')).example(['\\Draft']).label('FlagDeleteList'),
437+
set: Joi.array().items(Joi.string().label('FlagEntry')).example(['\\Seen']).label('FlagSetList')
436438
}).label('FlagUpdateResponse'),
437439
labels: Joi.object({
438-
add: Joi.array().items(Joi.string()).example(['Label1', 'Label2']),
439-
delete: Joi.array().items(Joi.string()).example(['Label3']),
440-
set: Joi.array().items(Joi.string()).example(['Label1'])
440+
add: Joi.array().items(Joi.string().label('LabelEntry')).example(['Label1', 'Label2']).label('LabelAddList'),
441+
delete: Joi.array().items(Joi.string().label('LabelEntry')).example(['Label3']).label('LabelDeleteList'),
442+
set: Joi.array().items(Joi.string().label('LabelEntry')).example(['Label1']).label('LabelSetList')
441443
}).label('LabelUpdateResponse')
442444
}).label('MessageUpdateResponse'),
443445
failAction: 'log'
@@ -510,16 +512,16 @@ async function init(args) {
510512
response: {
511513
schema: Joi.object({
512514
flags: Joi.object({
513-
add: Joi.array().items(Joi.string()).example(['\\Seen', '\\Flagged']),
514-
delete: Joi.array().items(Joi.string()).example(['\\Draft']),
515-
set: Joi.array().items(Joi.string()).example(['\\Seen'])
516-
}).label('FlagUpdateResponse'),
515+
add: Joi.array().items(Joi.string().label('BulkFlagEntry')).example(['\\Seen', '\\Flagged']).label('BulkFlagAddList'),
516+
delete: Joi.array().items(Joi.string().label('BulkFlagEntry')).example(['\\Draft']).label('BulkFlagDeleteList'),
517+
set: Joi.array().items(Joi.string().label('BulkFlagEntry')).example(['\\Seen']).label('BulkFlagSetList')
518+
}).label('BulkFlagUpdateResponse'),
517519
labels: Joi.object({
518-
add: Joi.array().items(Joi.string()).example(['Label1', 'Label2']),
519-
delete: Joi.array().items(Joi.string()).example(['Label3']),
520-
set: Joi.array().items(Joi.string()).example(['Label1'])
521-
}).label('LabelUpdateResponse')
522-
}).label('MessageUpdateResponse'),
520+
add: Joi.array().items(Joi.string().label('BulkLabelEntry')).example(['Label1', 'Label2']).label('BulkLabelAddList'),
521+
delete: Joi.array().items(Joi.string().label('BulkLabelEntry')).example(['Label3']).label('BulkLabelDeleteList'),
522+
set: Joi.array().items(Joi.string().label('BulkLabelEntry')).example(['Label1']).label('BulkLabelSetList')
523+
}).label('BulkLabelUpdateResponse')
524+
}).label('BulkMessageUpdateResponse'),
523525
failAction: 'log'
524526
}
525527
}
@@ -759,7 +761,9 @@ async function init(args) {
759761
moved: Joi.object({
760762
destination: Joi.string().required().example('Trash').description('Trash folder path').label('TrashPath'),
761763
message: Joi.string().required().example('AAAAAwAAAWg').description('Message ID in Trash').label('TrashMessageId')
762-
}).description('Present if message was moved to Trash')
764+
})
765+
.description('Present if message was moved to Trash')
766+
.label('MessageMovedToTrash')
763767
}).label('MessageDeleteResponse'),
764768
failAction: 'log'
765769
}
@@ -1281,7 +1285,8 @@ async function init(args) {
12811285
.valid('html', 'plain', '*')
12821286
.default('*')
12831287
.example('*')
1284-
.description('Which text content to return, use * for all. By default all contents are returned.'),
1288+
.description('Which text content to return, use * for all. By default all contents are returned.')
1289+
.label('TextSearchTextType'),
12851290
documentStore: documentStoreSchema.default(false)
12861291
}),
12871292

lib/api-routes/template-routes.js

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,11 @@ async function init(args) {
9393
.example('Something about the template')
9494
.description('Optional description of the template')
9595
.label('TemplateDescription'),
96-
format: Joi.string().valid('html', 'markdown').default('html').description('Markup language for HTML ("html" or "markdown")'),
96+
format: Joi.string()
97+
.valid('html', 'markdown')
98+
.default('html')
99+
.description('Markup language for HTML ("html" or "markdown")')
100+
.label('TemplateFormat'),
97101
content: Joi.object({
98102
subject: templateSchemas.subject,
99103
text: templateSchemas.text,
@@ -176,7 +180,12 @@ async function init(args) {
176180
.example('Something about the template')
177181
.description('Optional description of the template')
178182
.label('TemplateDescription'),
179-
format: Joi.string().empty('').valid('html', 'markdown').default('html').description('Markup language for HTML ("html" or "markdown")'),
183+
format: Joi.string()
184+
.empty('')
185+
.valid('html', 'markdown')
186+
.default('html')
187+
.description('Markup language for HTML ("html" or "markdown")')
188+
.label('TemplateUpdateFormat'),
180189
content: Joi.object({
181190
subject: templateSchemas.subject,
182191
text: templateSchemas.text,
@@ -277,7 +286,11 @@ async function init(args) {
277286
.example('Something about the template')
278287
.description('Optional description of the template')
279288
.label('TemplateDescription'),
280-
format: Joi.string().valid('html', 'markdown').default('html').description('Markup language for HTML ("html" or "markdown")'),
289+
format: Joi.string()
290+
.valid('html', 'markdown')
291+
.default('html')
292+
.description('Markup language for HTML ("html" or "markdown")')
293+
.label('TemplateListFormat'),
281294
created: Joi.date().iso().example('2021-02-17T13:43:18.860Z').description('The time this template was created'),
282295
updated: Joi.date().iso().example('2021-02-17T13:43:18.860Z').description('The time this template was last updated')
283296
}).label('AccountTemplate')
@@ -345,15 +358,23 @@ async function init(args) {
345358
.example('Something about the template')
346359
.description('Optional description of the template')
347360
.label('TemplateDescription'),
348-
format: Joi.string().valid('html', 'markdown').default('html').description('Markup language for HTML ("html" or "markdown")'),
361+
format: Joi.string()
362+
.valid('html', 'markdown')
363+
.default('html')
364+
.description('Markup language for HTML ("html" or "markdown")')
365+
.label('TemplateResponseFormat'),
349366
created: Joi.date().iso().example('2021-02-17T13:43:18.860Z').description('The time this template was created'),
350367
updated: Joi.date().iso().example('2021-02-17T13:43:18.860Z').description('The time this template was last updated'),
351368
content: Joi.object({
352369
subject: templateSchemas.subject,
353370
text: templateSchemas.text,
354371
html: templateSchemas.html,
355372
previewText: templateSchemas.previewText,
356-
format: Joi.string().valid('html', 'markdown').default('html').description('Markup language for HTML ("html" or "markdown")')
373+
format: Joi.string()
374+
.valid('html', 'markdown')
375+
.default('html')
376+
.description('Markup language for HTML ("html" or "markdown")')
377+
.label('TemplateContentFormat')
357378
}).label('RequestTemplateContent')
358379
}).label('AccountTemplateResponse'),
359380
failAction: 'log'

0 commit comments

Comments
 (0)