-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add specification to version service
- Loading branch information
1 parent
22a85ad
commit 3cb981b
Showing
3 changed files
with
55 additions
and
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,49 @@ | ||
import { Router } from "express"; | ||
import { Request, Response } from "express-serve-static-core"; | ||
import Metadata from "../../metadata"; | ||
import { StatusCode } from "status-code-enum"; | ||
import specification, { Tag } from "../../middleware/specification"; | ||
import { versionResponseSchema } from "./version-schema"; | ||
|
||
const versionRouter = Router(); | ||
|
||
/** | ||
* @api {get} /version/android/ GET /version/android/ | ||
* @apiGroup Version | ||
* @apiDescription Get the latest Android app version. | ||
* | ||
* @apiSuccess (200: Success) {Json} version The latest Android app version. | ||
* @apiSuccessExample Example Success Response | ||
* HTTP/1.1 200 OK | ||
* { | ||
* "version": "2024.1.1" | ||
* } | ||
*/ | ||
versionRouter.get( | ||
"/android/", | ||
specification({ | ||
method: "get", | ||
path: "/version/android/", | ||
tag: Tag.VERSION, | ||
summary: "Gets the current android version", | ||
responses: { | ||
[StatusCode.SuccessOK]: { | ||
description: "The current version", | ||
schema: versionResponseSchema, | ||
}, | ||
}, | ||
}), | ||
async (_, res) => { | ||
const androidVersion = await Metadata.load("androidVersion"); | ||
res.status(StatusCode.SuccessOK).send({ version: androidVersion }); | ||
}, | ||
); | ||
|
||
versionRouter.get("/android/", async (_: Request, res: Response) => { | ||
const androidVersion = await Metadata.load("androidVersion"); | ||
res.status(StatusCode.SuccessOK).send({ version: androidVersion }); | ||
}); | ||
|
||
/** | ||
* @api {get} /version/ios/ GET /version/ios/ | ||
* @apiGroup Version | ||
* @apiDescription Get the latest iOS app version. | ||
* | ||
* @apiSuccess (200: Success) {Json} version The latest iOS app version. | ||
* @apiSuccessExample Example Success Response | ||
* HTTP/1.1 200 OK | ||
* { | ||
* "version": "2024.1.1" | ||
* } | ||
*/ | ||
versionRouter.get("/ios/", async (_: Request, res: Response) => { | ||
const iosVersion = await Metadata.load("iosVersion"); | ||
res.status(StatusCode.SuccessOK).send({ version: iosVersion }); | ||
}); | ||
versionRouter.get( | ||
"/ios/", | ||
specification({ | ||
method: "get", | ||
path: "/version/ios/", | ||
tag: Tag.VERSION, | ||
summary: "Gets the current ios version", | ||
responses: { | ||
[StatusCode.SuccessOK]: { | ||
description: "The current version", | ||
schema: versionResponseSchema, | ||
}, | ||
}, | ||
}), | ||
async (_, res) => { | ||
const iosVersion = await Metadata.load("iosVersion"); | ||
res.status(StatusCode.SuccessOK).send({ version: iosVersion }); | ||
}, | ||
); | ||
|
||
export default versionRouter; |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { z } from "zod"; | ||
|
||
export const versionResponseSchema = z | ||
.object({ | ||
version: z.string().openapi({ description: "The version", example: "2024.2.4" }), | ||
}) | ||
.openapi("VersionResponse"); |