const {openapi} = require('apf');
const Koa = require('koa');
const Router = require('koa-router');
const app = new Koa();
const router = new Router();
const swagger = openapi({
router: router,
info: require('./package.json'),
});
swagger.api.addSchema('containerCreate', openapi.props({
id: {type: 'string'},
state: {
type: 'string',
enum: ['Online', 'Attached', 'Detached', 'Unknown'],
'x-rbx-field-type': ['state', 'live'],
},
}));
swagger.addEndpoint({
method: 'get',
url: '/resource/:id',
handler: async (ctx) => {
ctx.body = await ctx.backend.containerShow(ctx.params.id);
},
responses: {
200: {
description: 'resource state',
content: {
'application/json': {
schema: openapi.refComp('container'),
},
},
},
},
});
router.stack
.map(route => route.methods.map(method => `AGENT ${method} ${route.path}`)
.forEach(v => console.log(v)));
app
.use(router.routes())
.use(router.allowedMethods());