Actions

Advanced parameters

This example builds on the previous “Hello world" with typed input and output parameters example with more robust input and output parameter declarations by using a multi-line format for declaration.

This example:

  • shows how to declare input and output parameters on the action ‘hello_world’ using a multi-line grammar.

Manifest File

If we want to do more than declare the type (i.e., ‘string’, ‘integer’, ‘float’, etc.) of the input parameter, we can use the multi-line grammar.

Example: input and output parameters with explicit types and descriptions

package:
  name: hello_world_package
  ... # Package keys omitted for brevity
  actions:
    hello_world_advanced_parms:
      function: src/hello_plus.js
      runtime: nodejs@6
      inputs:
        name:
          type: string
          description: name of person
          default: unknown person
        place:
          type: string
          description: location of person
          value: the Shire
        children:
          type: integer
          description: Number of children
          default: 0
        height:
          type: float
          description: height in meters
          default: 0.0
      outputs:
        greeting:
          type: string
          description: greeting string
        details:
          type: string
          description: detailed information about the person

Deploying

$ wskdeploy -m docs/examples/manifest_hello_world_advanced_parms.yaml

Invoking

$ wsk action invoke hello_world_package/hello_world_advanced_parms --blocking

Result

The invocation should return an ‘ok’ with a response that includes this result:

"result": {
    "details": "You have 0 children and are 0 m. tall.",
    "greeting": "Hello, unknown person from the Shire"
},

Discussion

  • Describing the input and output parameter types, descriptions, defaults and other data:
    • enables tooling to validate values users may input and prompt for missing values using the descriptions provided.
    • allows verification that outputs of an Action are compatible with the expected inputs of another Action so that they can be composed in a sequence.
  • The ‘name’ input parameter was assigned the ‘default’ key's value “unknown person”.
  • The ‘place’ input parameter was assigned the ‘value’ key's value “the Shire”.

Source code

The manifest file for this example can be found here:

Specification

For convenience, the Actions and Parameters grammar can be found here: