Manifest

The manifest is a Lua table containing all of the endpoint and model definitions. It is also where you can define the security model, and set up handlers for startup and various other events, such as new Profile creation.

Note

The manifest will automatically be loaded from main.lua at the root of your project. See a sample here.

Model

All model objects that will be used for client code generation, request parameters, and response objects, must be defined here.

The anatomy of a model object is as such:

  • description - (string) A description of the model object
  • properties - (table) A list of properties for this object. This follows two formats:
    • (property name) - Basic types
      • description
      • type
    • (property name) - Arrays or custom types
      • description
      • type
      • model

Valid Property Types:

  • "string"
  • "number"
  • "integer"
  • "boolean"
  • "object"
  • "array"

Example code:

    --example_model.lua
    return {
        description = "A model object representing a several example properties.",
        properties = {
            message = {
                description = "A simple string message.",
                type = "string"
            },
            message_array = {
                description = "An array of messages.",
                type = "array",
                model = "string"        
            },
            some_other_model = {
                description = "Some other model. Must also be defined in manifest.",
                type = "object",
                model = "some_other_model"
            }
        }
    }

    --main.lua
    local manifest = {}
    manifest.model = {}
    manifest.model.example = require "example_model"
    manifest.model.some_other_model = require "some_other_model"
    return manifest

It is also possible to create a Pagination of any of your model objects here as well! This will allow you to fetch subsets of larger data sets when you want to stagger their retrieval from the client side.

    --main.lua
    local pagination = require "namazu.pagination"
    ...
    manifest.model.example = require "example_model"
    manifest.model.pagination_of_example = pagination.manifest_for("example")

HTTP

The manifest's HTTP definitions are your custom endpoint definitions. Everything that you define here will be found in DefaultApi in the generated client code, as well as tell Elements which endpoint handler functions to call when the client makes a request.

-- <Path to handler> = <operations table>
manifest.http = {
    ["example_endpoints"] = require "example_endpoints_operations"
}

Example operations table

Example endpoint handler

Startup

Runs the specified scripts whenever Elements launches. This will include restarts made for code changes.

-- Assumes startup.lua exists and has a function "run"

manifest.startup = {
    ["startup"] = {
        operations = {
            run = {
                method = "run"
            }
        }
    }
}

Note

If your startup script creates a new resource, you should check if it has already been created before creating a new one.

Events

Events allow you to add special functionality to certain Elements events.

Currently supported events:

  • "com.namazustudios.elements.service.profile.created" - a new Profile creation event
  • More coming soon!
-- Example for handling a new Profile creation event
manifest.event = {
    ["com.namazustudios.elements.service.profile.created"] = {
        { module = "new_profile_event_handler", method = "on_new_profile" }
    }
}

Security

local auth = require "namazu.elements.auth"
...
manifest.security = auth.default_security_manifest()