Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let R = require('ramda');
- // JSON.stringify(crudOpenApiEndpoints({ single: 'app' }))
- function crudOpenApiEndpoints ({ single, plural = single + 's', id = 'id', type = 'integer' }) {
- let up = (s) => s[0].toUpperCase() + s.substring(1);
- let $ref = `#/definitions/${up(single)}`;
- let resp = R.merge({ description: 'OK' });
- let responses = { 204: resp({}) }; // empty non-GET response
- let idPar = { name: id, in: 'path', required: true, type };
- let bodyPar = { name: single, in: 'body', required: true, schema: { $ref } };
- return {
- [`/${plural}`]: {
- get: {
- responses: {
- 200: resp({
- // schema: { type: 'array', items: { $ref } },
- schema: { $ref: `#/definitions/${up(plural)}` },
- }),
- },
- },
- post: {
- parameters: [bodyPar],
- responses,
- },
- },
- [`/${plural}/{id}`]: {
- get: {
- parameters: [idPar],
- responses: {
- 200: resp({
- schema: { $ref },
- }),
- },
- },
- delete: {
- parameters: [idPar],
- responses,
- },
- put: {
- parameters: [idPar, bodyPar],
- responses,
- },
- },
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement