Skip to content

Commit a9cffe1

Browse files
committed
fix: resolve OpenAPI spec validation errors for token restrictions
Replace .allow(false).default(false) with .empty(Joi.valid('', false)) .allow(null).default(null) on token restriction schemas (referrers, addresses, rateLimit). The false sentinel produced invalid OpenAPI: type "array" with default: false and enum: [false]. Using .empty() converts false inputs to undefined (then defaulted to null), maintaining backward compatibility for API consumers that send false to clear restrictions. Runtime code uses truthiness checks so null behaves identically to false. Also replace notifyFrom .default('now') with .default(null) since 'now' is not a valid date-time value. The runtime already treats any falsy notifyFrom as "use current time". These changes eliminate all 5 OpenAPI validation errors, allowing SDK generation without --skip-validate-spec.
1 parent 8078830 commit a9cffe1

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

lib/api-routes/account-routes.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ async function init(args) {
195195

196196
logs: Joi.boolean().example(false).description('Store recent logs').default(false),
197197

198-
notifyFrom: accountSchemas.notifyFrom.default('now'),
198+
notifyFrom: accountSchemas.notifyFrom.default(null),
199199
syncFrom: accountSchemas.syncFrom.default(null),
200200

201201
proxy: settingsSchema.proxyUrl,
@@ -630,7 +630,7 @@ async function init(args) {
630630

631631
payload: Joi.object({
632632
flush: Joi.boolean().truthy('Y', 'true', '1').falsy('N', 'false', 0).default(false).description('Only flush the account if true'),
633-
notifyFrom: accountSchemas.notifyFrom.default('now'),
633+
notifyFrom: accountSchemas.notifyFrom.default(null),
634634
imapIndexer: accountSchemas.imapIndexer,
635635
syncFrom: accountSchemas.syncFrom
636636
}).label('RequestFlush')

lib/schemas.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,10 +1489,10 @@ const oauthCreateSchema = {
14891489
const tokenRestrictionsSchema = Joi.object({
14901490
referrers: Joi.array()
14911491
.items(Joi.string())
1492-
.empty('')
1492+
.empty(Joi.valid('', false))
14931493
.single()
1494-
.allow(false)
1495-
.default(false)
1494+
.allow(null)
1495+
.default(null)
14961496
.example(['*web.domain.org/*', '*.domain.org/*', 'https://domain.org/*'])
14971497
.label('ReferrerAllowlist')
14981498
.description('HTTP referrer patterns that are allowed to use this token (wildcards supported)'),
@@ -1503,25 +1503,26 @@ const tokenRestrictionsSchema = Joi.object({
15031503
cidr: 'optional'
15041504
})
15051505
)
1506-
.empty('')
1506+
.empty(Joi.valid('', false))
15071507
.single()
1508-
.allow(false)
1509-
.default(false)
1508+
.allow(null)
1509+
.default(null)
15101510
.example(['1.2.3.4', '5.6.7.8', '127.0.0.0/8'])
15111511
.label('AddressAllowlist')
15121512
.description('IP addresses or CIDR ranges allowed to use this token'),
15131513
rateLimit: Joi.object({
15141514
maxRequests: Joi.number().integer().min(1).example(20).description('Maximum requests allowed in the time window'),
15151515
timeWindow: Joi.number().integer().min(1).example(2).description('Time window duration in seconds')
15161516
})
1517-
.allow(false)
1518-
.default(false)
1517+
.empty(Joi.valid('', false))
1518+
.allow(null)
1519+
.default(null)
15191520
.example({ maxRequests: 20, timeWindow: 2 })
15201521
.label('AddressRateLimit')
15211522
.description('Rate limiting configuration for this token')
15221523
})
1523-
.empty('')
1524-
.allow(false)
1524+
.empty(Joi.valid('', false))
1525+
.allow(null)
15251526
.label('TokenRestrictions')
15261527
.description('Security restrictions for API token usage');
15271528

0 commit comments

Comments
 (0)