~shreyasminocha/rice-dining-api

2d120e3d1538279622d9ad2f4504cadaf91e936c — Shreyas Minocha 1 year, 10 months ago 1658fbb
Add docs

Resolves https://todo.sr.ht/~shreyasminocha/rice-dining-api/3
3 files changed, 111 insertions(+), 1 deletions(-)

M README.md
A src/docs.js
M src/index.js
M README.md => README.md +8 -1
@@ 1,9 1,16 @@
# [Rice Dining](https://dining.rice.edu) API

A REST API for accessing Rice servery menus.
A [REST API](https://dining.rice.edu.bzin.ga) for accessing Rice servery menus.

## Examples

- [Seibel daily menu](https://dining.rice.edu.bzin.ga/seibel-servery)
- [North full week menu](https://dining.rice.edu.bzin.ga/north-servery/full-week-menu)

## API

See [`/`](https://dining.rice.edu.bzin.ga) for OpenAPI-compatible specification.

`servery` is one of:

- `west-servery`

A src/docs.js => src/docs.js +98 -0
@@ 0,0 1,98 @@
const serverySchema = {
	type: 'string',
	enum: ['west-servery', 'seibel-servery', 'baker-kitchen', 'north-servery'],
};

const menuSchema = {
	type: 'array',
	items: {
		type: 'object',
		properties: {
			item: { type: 'string', example: 'Fiesta Rice' },
			tags: { type: 'array', items: { type: 'string', example: 'vegan' } },
		},
	},
};

const docs = {
	openapi: '3.0.0',
	info: {
		title: 'Rice Dining API',
		version: '0.1.0',
	},
	servers: [
		{ url: 'https://dining.rice.edu.bzin.ga' },
	],
	paths: {
		'/{servery}': {
			get: {
				summary: 'Get the current daily menu',
				parameters: [
					{
						name: 'servery',
						in: 'path',
						required: true,
						schema: serverySchema,
					},
				],
				responses: {
					'200': {
						description: 'OK',
						content: {
							'application/json': {
								schema: {
									type: 'array',
									items: {
										type: 'object',
										properties: {
											meal: { type: 'string', example: 'Lunch' },
											menu: menuSchema,
										},
									},
								},
							},
						},
					},
					'404': { description: 'Not found' },
					'500': { description: 'Unexpected error' },
				},
			},
		},
		'/{servery}/full-week-menu': {
			get: {
				summary: 'Get the current weekly menu',
				parameters: [
					{
						name: 'servery',
						in: 'path',
						required: true,
						schema: serverySchema,
					},
				],
				responses: {
					'200': {
						description: 'OK',
						content: {
							'application/json': {
								schema: {
									type: 'array',
									items: {
										type: 'object',
										properties: {
											meal: { type: 'string', example: 'Monday Lunch' },
											menu: menuSchema,
										},
									},
								},
							},
						},
					},
					'404': { description: 'Not found' },
					'500': { description: 'Unexpected error' },
				},
			},
		},
	},
};

export default docs;

M src/index.js => src/index.js +5 -0
@@ 2,10 2,15 @@ import Koa from 'koa';
import Router from 'koa-router';
import { HTTPError } from 'got';
import { getDailyMenu, getFullWeekMenu } from './scrape.js';
import docs from './docs.js';

const app = new Koa();
const router = new Router();

router.get('/', (ctx) => {
	ctx.body = docs;
});

router.get('/:servery', async (ctx) => {
	const { servery } = ctx.params;