Skip to content

seges/openapi-node-function-template

Repository files navigation

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!

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

Release notes

1.6.1

  • make previous change defensive

1.6.0

  • exposed ability to exclude or obscure headers from logging

1.5.1

  • version fix of 1.5.0

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

Variable Default value Description
NODE_ENV
SSL false
http__port 4000
http__request_id_header X-Request-Id
http__ssl__key_file $(cwd)/ca/key.pem
http__ssl__cert_file $(cwd)/ca/cert.pem
openapi__single_operation_id singleHandler
openapi__filename
openapi__url
service__namespace default-ns
request__body__size 1mb
logger__name defaultLogger
logger__level info
logger__excluded_headers authorization,token comma separated list of headers to exclude from logging
logger__obscured_headers authorization,token comma separated list of headers to obscure in logging

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

About

OpenAPI 3 function template for OpenFaas based on Node.js

Resources

License

Stars

Watchers

Forks

Packages

No packages published