1.5.1 • Published 3 years ago

openapi-node-function-template v1.5.1

Weekly downloads
5
License
MIT
Repository
github
Last release
3 years ago

OpenAPI 3 function template

Build Status OpenFaaS OpenAPInpm version npm downloads

Do you want to build a microservice based on OpenAPI 3 specification? Do you hate writing all the boilerplate endpoint code? Or do you need your neat serverless function? Running on OpenFaaS or another serverless provider?

You came to the right place.

OpenAPI Node Function Template is a single dependency along your OpenAPI 3 specification file you actually need in order to run your service!

  • :white_check_mark: generated OpenAPI 3 REST endpoint
  • :white_check_mark: validated inputs based on the provided schemas
  • :white_check_mark: flexible middlewares
  • :white_check_mark: follows OpenFaaS template but it is not bound to it
  • :white_check_mark: running as standalone NodeJS server
  • :white_check_mark: works on top of Express
  • :white_check_mark: uses fantastic OpenAPI Backend project

Release notes

1.5.0

  • passing request fields from OpenAPI Backend Context as part of FunctionEvent
  • passing also raw Context if necessary
  • documented FunctionEvent

1.4.0

1.3.0

  • support for flexible middleware injections

1.2.0

  • upgraded OpenAPI Backend to 2.3.0

Operation handler

Your operation handler for an endpoint looks like this:

export default async (message, context) => {
  context.status(200).succeed({ "nice": "json" });
}

Where message is of type FunctionEvent and context is of type FunctionContext.

Environment configuration

VariableDefault valueDescription
NODE_ENV
SSLfalse
http__port4000
http__request_id_headerX-Request-Id
httpsslkey_file$(cwd)/ca/key.pem
httpsslcert_file$(cwd)/ca/cert.pem
openapi__single_operation_idsingleHandler
openapi__filename
openapi__url
service__namespacedefault-ns
requestbodysize1mb
logger__namedefaultLogger
logger__levelinfo

Examples

Develop

Prepare .npmrc

Create .npmrc in the root:

save-exact=true
prefix=/home/developer/.npm-global

Use Docker for development

docker-compose up -d dev docker-compose exec dev zsh

Publish

npm login registry.npmjs.org npm publish