You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
wiki/backend/api/schemas/apiKey.ts

61 lines
1.4 KiB

import type { FastifyInstance } from 'fastify'
import { KEY_EXPIRATIONS } from '../../models/apiKeys.ts'
export async function registerSchemas(app: FastifyInstance): Promise<void> {
/**
* API KEY - Metadata only; the token itself exists once, in the create response
*/
app.addSchema({
$id: 'ApiKey',
type: 'object',
properties: {
id: {
type: 'string',
format: 'uuid'
},
name: {
type: 'string'
},
keyShort: {
type: 'string',
description: 'Last characters of the token, to tell keys apart. The token is not stored.'
},
groups: {
type: 'array',
description: 'IDs of the groups this key draws its permissions from.',
items: {
type: 'string',
format: 'uuid'
}
},
expiration: {
type: 'string',
format: 'date-time',
description: 'RFC 3339 Date Time'
},
isRevoked: {
type: 'boolean'
},
createdAt: {
type: 'string',
format: 'date-time',
description: 'RFC 3339 Date Time'
},
updatedAt: {
type: 'string',
format: 'date-time',
description: 'RFC 3339 Date Time'
}
}
})
/**
* API KEY EXPIRATION - The lifetimes a new key can be given
*/
app.addSchema({
$id: 'ApiKeyExpiration',
type: 'string',
enum: Object.keys(KEY_EXPIRATIONS)
})
}