Optional Array in Add-On Configuration Option

For an add-on I am developing, I would like to add an array (or list?) of n elements to the options in the config to configure additional hosts.
I am following the structure given in the example with the logins, but changed it to additional_hosts (see here for my full config):

options:
 [...]
 additional_hosts:
    - hostname: "ds.example.com"
      service: "http://192.168.1.2"
    - hostname: "fritz.example.com"
      service: "http://192.168.1.1"
schema:
  [...]
  additional_hosts:
    - hostname: str?
      service: str?

Now this works fine for testing and developing. In the final version, I want to make the whole additional_hosts array optional though, so the user does not have to define any additional hosts in the config. I tried simply removing the additional_hosts array from the options section and just leave it in the schema. Since the hostname and service are optional there, I thought this might work. Nevertheless, I cannot save the config since it is missing an entry for additional_hosts.

Does anyone have an idea on how to make this array optional?

Thanks a lot for your help.

What i understood so far schema config of add-ons;

  • options are visible to user
  • schema is how the options are validated

So, you should have both of them.

1 Like

Thanks for your reply. I think you are partly correct: Options are what is visible to the user by being added to the options as a standard. This will lead to the option fields being visible in the Configuration section of the add-on. Nevertheless, you can also configure optional parameters by just defining them in the Schema section and add a ? behind the data type. You can see that in this example with the not_needed parameter.
In the Add-On Configuration tab, those options are then hidden and only shown once you activate the Show unused optional configuration options flag.

So what I want to do is exactly that, but with an array and not just a simple string.

Yep, got it now, thanks. Not sure about solution though :slight_smile:

I had the exact same issue and I know this is a year old but unsure if you ever solved the problem

I thought I would post in-case others have not

The trick is to provide an empty list in the options config:

options:
 [...]
 additional_hosts: []
schema:
  [...]
  additional_hosts:
    - hostname: str
      service: str

That will do what you want

1 Like