anax icon indicating copy to clipboard operation
anax copied to clipboard

Update Service Definition docs to clarify userInputs property types

Open joewxboy opened this issue 4 years ago • 2 comments

The Service Definition documentation at https://github.com/open-horizon/anax/blob/master/docs/service_def.md needs additional clarification in the userInputs section.

It currently states in part:

The list of variables that condition the behavior of the service implementation in the container image(s). These variables are typed; string, int, float, boolean, list of strings and MAY have a default value.

What is unclear, and will result in vague error messages like the one below, is when a developer attempts to create a userInput entry of type "boolean" with a defaultValue of true or false.

Error: failed to unmarshal json input file command.json: json: cannot unmarshal bool into Go struct field UserInput.userInput.defaultValue of type string

We need to clearly specify that the defaultValue should also be a string, even though the type field is NOT "string".

Here's a suggested replacement:

The list of variables that condition the behavior of the service implementation in the container image(s). These variables are typed; string, int, float, boolean, list of strings and MAY have a default value. If the defaultValue property is present, it MUST be populated with a string value, even if the value of the "type" property is NOT a string. For example:

    {
      "name": "HZN_GPS_PORT",
      "label": "REST API port",
      "type": "int",
      "defaultValue": "8080"
    },
    {
      "name": "HZN_USE_GPS",
      "label": "Use GPS hardware, or not",
      "type": "boolean",
      "defaultValue": "true"
    },
    {
      "name": "HZN_LAT",
      "label": "Manually user-specified North latitude, or 0.0 when using other means",
      "type": "float",
      "defaultValue": "0.0"
    }

joewxboy avatar Jun 11 '21 20:06 joewxboy

@joewxboy , it is really a good suggestion, Thanks

xauthulei avatar Jul 06 '21 09:07 xauthulei

could i work on this? thank you

unnati914 avatar Aug 09 '21 13:08 unnati914

This clarification was merged in 2021. I like the examples that @joewxboy provided however. There are useful UserInput examples in this issue which demonstrate the typed use cases (as "string values")

Aha - looks like we document examples here: https://www.ibm.com/docs/en/eam/4.4?topic=devices-cpu-event-streams-service https://open-horizon.github.io/docs/developing/cpu_msg_example.html

johnwalicki avatar Oct 03 '22 00:10 johnwalicki