-
Notifications
You must be signed in to change notification settings - Fork 11k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chore: add Ajv JSON Schema to api/v1 (#25601)
- Loading branch information
1 parent
7e8d6d2
commit 0b1073e
Showing
36 changed files
with
3,577 additions
and
296 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,104 @@ | ||
import Ajv from 'ajv'; | ||
import type { BannerPlatform, IBanner } from '@rocket.chat/core-typings'; | ||
|
||
const ajv = new Ajv({ | ||
coerceTypes: true, | ||
}); | ||
|
||
type BannersGetNew = { | ||
platform: BannerPlatform; | ||
bid: IBanner['_id']; | ||
}; | ||
|
||
const BannersGetNewSchema = { | ||
type: 'object', | ||
properties: { | ||
platform: { | ||
type: 'string', | ||
enum: ['1', '2'], | ||
}, | ||
bid: { | ||
type: 'string', | ||
}, | ||
}, | ||
required: ['platform', 'bid'], | ||
additionalProperties: false, | ||
}; | ||
|
||
export const isBannersGetNewProps = ajv.compile<BannersGetNew>(BannersGetNewSchema); | ||
|
||
type BannersId = { | ||
platform: BannerPlatform; | ||
}; | ||
|
||
const BannersIdSchema = { | ||
type: 'object', | ||
properties: { | ||
platform: { | ||
type: 'string', | ||
}, | ||
}, | ||
required: ['platform'], | ||
additionalProperties: false, | ||
}; | ||
|
||
export const isBannersIdProps = ajv.compile<BannersId>(BannersIdSchema); | ||
|
||
type Banners = { | ||
platform: BannerPlatform; | ||
}; | ||
|
||
const BannersSchema = { | ||
type: 'object', | ||
properties: { | ||
platform: { | ||
type: 'string', | ||
}, | ||
}, | ||
required: ['platform'], | ||
additionalProperties: false, | ||
}; | ||
|
||
export const isBannersProps = ajv.compile<Banners>(BannersSchema); | ||
|
||
type BannersDismiss = { | ||
bannerId: string; | ||
}; | ||
|
||
const BannersDismissSchema = { | ||
type: 'object', | ||
properties: { | ||
bannerId: { | ||
type: 'string', | ||
}, | ||
}, | ||
required: ['bannerId'], | ||
additionalProperties: false, | ||
}; | ||
|
||
export const isBannersDismissProps = ajv.compile<BannersDismiss>(BannersDismissSchema); | ||
|
||
export type BannersEndpoints = { | ||
/* @deprecated */ | ||
'banners.getNew': { | ||
GET: (params: { platform: BannerPlatform; bid: IBanner['_id'] }) => { | ||
GET: (params: BannersGetNew) => { | ||
banners: IBanner[]; | ||
}; | ||
}; | ||
|
||
'banners/:id': { | ||
GET: (params: { platform: BannerPlatform }) => { | ||
GET: (params: BannersId) => { | ||
banners: IBanner[]; | ||
}; | ||
}; | ||
|
||
'banners': { | ||
GET: (params: { platform: BannerPlatform }) => { | ||
GET: (params: Banners) => { | ||
banners: IBanner[]; | ||
}; | ||
}; | ||
|
||
'banners.dismiss': { | ||
POST: (params: { bannerId: string }) => void; | ||
POST: (params: BannersDismiss) => void; | ||
}; | ||
}; |
Oops, something went wrong.