Adding Template
This commit is contained in:
parent
8e98496fa7
commit
031e21b9c9
67
lib/templates/openApiSchema.handlebars
Normal file
67
lib/templates/openApiSchema.handlebars
Normal file
@ -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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user