-
-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #365 from ageddesi/dev
v0.20.0 candidate
- Loading branch information
Showing
9 changed files
with
675 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { Request, Response } from 'express'; | ||
import * as core from 'express-serve-static-core'; | ||
import { getQtyFromRequest } from '../../../utils/route-utils'; | ||
import facts from '../data/facts'; | ||
|
||
module.exports = function (app: core.Express) { | ||
/** | ||
* @openapi | ||
* '/facts/random': | ||
* get: | ||
* tags: | ||
* - Facts | ||
* summary: Get a random fact from the database | ||
* responses: | ||
* '200': | ||
* description: OK | ||
* schema: | ||
* type: object | ||
* example: { fact: '', category: ''} | ||
*/ | ||
app.get('/facts/random', (req: Request, res: Response) => { | ||
const fact = facts[Math.floor(Math.random() * facts.length)]; | ||
res.json(fact); | ||
}); | ||
|
||
/** | ||
* @openapi | ||
* '/facts/{qty}': | ||
* get: | ||
* tags: | ||
* - Facts | ||
* summary: Get a list of all facts from the database | ||
* parameters: | ||
* - in: path | ||
* name: qty | ||
* description: The amount of results you would like returned | ||
* default: 10 | ||
* type: number | ||
* responses: | ||
* '200': | ||
* description: OK | ||
* schema: | ||
* type: array | ||
* items: | ||
* type: object | ||
* example: { fact: '', category: ''} | ||
*/ | ||
app.get('/facts/:qty', (req: Request, res: Response) => { | ||
const qty = getQtyFromRequest(req); | ||
res.json(qty >= facts.length ? facts : facts.slice(0, qty)); | ||
}); | ||
}; |
Oops, something went wrong.