From 031e21b9c9b767919bc774e3c24e33ef2ae3af6c Mon Sep 17 00:00:00 2001 From: Martin Karkowski Date: Mon, 24 Aug 2020 23:10:11 +0200 Subject: [PATCH] Adding Template --- lib/templates/openApiSchema.handlebars | 67 ++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 lib/templates/openApiSchema.handlebars diff --git a/lib/templates/openApiSchema.handlebars b/lib/templates/openApiSchema.handlebars new file mode 100644 index 0000000..e98e81d --- /dev/null +++ b/lib/templates/openApiSchema.handlebars @@ -0,0 +1,67 @@ +// Automatic Genearted File for Backendclass "{{className}}" +// To update run `npm run build:backend` + +import { nopeDispatcher } from "../nopeDispatcher" +import { Operation } from "express-openapi"; + +export default function (_dispatcher: nopeDispatcher) { + + let operations = { + {{method}} + }; + + // Function to Parse the Inputs + const parseParams = (req) => { + return [{{#each params}}req.body.{{name}}{{#unless @last}}, {{/unless}}{{/each}}] + } + + // Define the Action. + async function {{method}}(req, res, next) { + // Transform the Operation to the Callback of the Dispatcher. + const result = await _dispatcher.performCall<{{{returnType.simplifiedSubType}}}>('{{baseUri}}/{{methodUri}}', parseParams(req)) + // Finish the Task. + res.status(200).json(result) + } + + // Define the apiDoc for this specific Funtion + POST.apiDoc = { + {{#if methodDescription}}summary: '{{methodDescription}}',{{/if}} + {{#if operationId}}operationId: '{{operationId}}',{{/if}}{{#if operationId}}operationId: '{{operationId}}',{{/if}} + operationId: '{{operationId}}', + parameters: [ + {{#if useDefaultParameters}} + { + name: "body", + in: "body", + description: "Body of the Message", + required: true, + schema: {{{inputSchema}}} + } + {{/if}} + {{#if useCustomParameters}} + {{useCustomParameters}} + {{/if}} + ], + responses: { + {{#if hasReturnType}} + 200: { + {{#if resultDescription}}description: '{{resultDescription}}',{{/if}} + schema: {{{outputSchema}}} + }, + {{/if}} + {{#unless hasReturnType}} + 200: { + {{#if resultDescription}}description: '{{resultDescription}}',{{/if}} + }, + {{/unless}} + default: { + description: 'An error occurred', + schema: { + additionalProperties: true + } + } + } + } as Operation; + + return operations; +} \ No newline at end of file