67 lines
2.1 KiB
Handlebars
67 lines
2.1 KiB
Handlebars
|
// 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;
|
||
|
}
|