Add OpenAPI schema generation and validation for API routes
This commit is contained in:
1 parent
5d822e6c7e
commit
5ce5664b29
25 files changed
+2019
-52
No files matched your search
@@ -0,0 +1,34 @@
|
||||
import type { ApiAuth } from '@/openapi/operation';
|
||||
|
||||
export const securitySchemes = {
|
||||
bearerAuth: {
|
||||
type: 'http' as const,
|
||||
scheme: 'bearer',
|
||||
bearerFormat: 'JWT',
|
||||
description: 'Token returned by POST /api/auth/login.',
|
||||
},
|
||||
shareToken: {
|
||||
type: 'apiKey' as const,
|
||||
in: 'header' as const,
|
||||
name: 'x-umami-share-token',
|
||||
description: 'Signed token returned by a share endpoint.',
|
||||
},
|
||||
shareContext: {
|
||||
type: 'apiKey' as const,
|
||||
in: 'header' as const,
|
||||
name: 'x-umami-share-context',
|
||||
description: 'Required context header when authenticating with a share token.',
|
||||
},
|
||||
};
|
||||
|
||||
export function getSecurityRequirements(auth: ApiAuth) {
|
||||
if (auth === 'none') {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (auth === 'bearer-or-share') {
|
||||
return [{ bearerAuth: [] }, { shareToken: [], shareContext: [] }];
|
||||
}
|
||||
|
||||
return [{ bearerAuth: [] }];
|
||||
}
|
||||
Reference in new issue
Block a user