Component .spec file api parameter type

Forum to discuss the new web client version of Servoy.

Component .spec file api parameter type

Postby steve1376656734 » Mon Sep 18, 2023 3:41 pm

I have an API call in my component that has an argument that can be 1 of two custom types. In my appbar_server.js file I document this as:
Code: Select all
/**
* Adds the given item to the Menu
*
* @param {CustomType<mycomponents-appbar.MenuItem>|CustomType<mycomponents-appbar.SubMenuItem>} item
* @param {String} [menuId] optional - Add the item to the submenu of the given menuId
* @param {Number} [index] optional - Index where the item will be inserted
*
* @return {Boolean}
*
* @SuppressWarnings(nls)
*/
function addItem(item, menuId, index) {
   .
   .
   .
}

I don't seem to be able to find the correct syntax for specifying this in the .spec file. My "api" section has the method defined as:
Code: Select all
      "addItem": {
         "returns": "boolean",
         "parameters": [
            {
               "name": "item",
               "type": "MenuItem|SubMenuItem"
            },
            {
               "name": "menuId",
               "type":"string",
               "optional":true
            },
            {
               "name": "index",
               "type": "int",
               "optional": true
            }
         ]
      },

However, this causes an error in the developer console:
Code: Select all
WARN org.sablo.specification.WebObjectSpecification - Unknown type name 'MenuItem|SubMenuItem' encountered while parsing spec mycomponents-appbar

How should I specify that the argument can be of type MenuItem or SubMenuItem?
Steve
SAN Developer
There are 10 types of people in the world - those that understand binary and those that don't
steve1376656734
 
Posts: 338
Joined: Fri Aug 16, 2013 2:38 pm
Location: Ashford, UK

Re: Component .spec file api parameter type

Postby Andrei Costescu » Mon Sep 18, 2023 4:26 pm

That is not currently supported in the .spec file.

If it's just a server-side call, maybe it would be enough to make it an "object"; it's not the same thing, but it might work for your case.
Otherwise you can have 2 different methods instead of 1, so 1 for each of the custom types as argument.
Andrei Costescu
Servoy
Andrei Costescu
 
Posts: 1018
Joined: Tue Jun 26, 2007 3:14 pm

Re: Component .spec file api parameter type

Postby steve1376656734 » Mon Sep 18, 2023 4:37 pm

I will make it two separate methods for now so that I can keep the type checking in Servoy and I will add a feature request to support multiple types.

Thanks
Steve
Steve
SAN Developer
There are 10 types of people in the world - those that understand binary and those that don't
steve1376656734
 
Posts: 338
Joined: Fri Aug 16, 2013 2:38 pm
Location: Ashford, UK


Return to Servoy NGClient

Who is online

Users browsing this forum: No registered users and 2 guests