Main Content

validateFunctionSignaturesJSON

Validate functionSignatures.json files

Description

validateFunctionSignaturesJSON displays validation messages for the functionSignatures.json file in the current folder. Validation messages indicate the location of any invalid code and the reason the code is invalid. The line number in the message is a hyperlink that you can click to go directly to that line in the Editor.

JSON syntax errors in the functionSignatures.json file impact validation of the file. If validateFunctionSignaturesJSON reports JSON syntax errors, correct these errors and then revalidate the file.

For information on creating a functionSignatures.json file, see Customize Code Suggestions and Completions.

example

validateFunctionSignaturesJSON(filenames) validates the functionSignatures.json files in filenames. Use this syntax to validate function signature files in multiple folders.

T = validateFunctionSignaturesJSON(___) returns a table of results. You can use this syntax with any of the input argument combinations in the previous syntaxes.

Examples

collapse all

Create the myFunc function in your current working folder.

function myFunc(reqA,reqB,varargin)
    NV1 = true;
    NV2 = 'Default';
    posA = [];
    
    if nargin > 3
        if rem(nargin,2)
            posA = varargin{1};
            V = varargin(2:end);
        else
            V = varargin;
        end
        for n = 1:2:size(V,2)
            switch V{n}
                case 'Name1'
                    NV1 = V{n+1};
                case 'Name2'
                    NV2 = V{n+1}
                otherwise
                    error('Error.')
            end
        end
    end
end

Create the following function signature file, as functionSignatures.json, in your current working folder. It contains three validation issues.

  1. A property (attribute) is incorrect in the first argument object. The property should be "name" instead of "argument".

  2. The argument object for in3 is in the incorrect order. You must specify positional arguments before name-value pairs.

  3. There is an unnecessary comma after the last argument object. A comma in this position is a JSON syntax error.

{
  "_schemaVersion": "1.0.0",
  "myFunc":
  {
     "inputs":
     [
        {"argument":"input1",  "kind":"required", "type":["numeric"], "purpose":"ID of item"},
        {"name":"input2",  "kind":"positional", "type":["numeric"], "purpose":"# Items"},
        {"name":"Name1", "kind":"namevalue", "type":["logical","scalar"],"purpose":"Option"},
        {"name":"in3",  "kind":"positional", "type":["numeric"], "purpose":"Input Value"},
        {"name":"Name2", "kind":"namevalue", "type":["char", "choices={'Default','Choice1','Choice2'}"]},
     ]
  }
}

Validate the functionSignatures.json file. The validation function does not report the first two validation issues because it encounters a JSON syntax error.

validateFunctionSignaturesJSON
functionSignatures.json
=======================
L 12 (C 6-7): JSON syntax error at line 12, column 6 (character 551): expected value but found ']'.

Remove the extra comma at the end of line 12 and, to view the remaining validation issues, revalidate the file.

validateFunctionSignaturesJSON
functionSignatures.json
=======================
L 7 (C 10-19): Invalid attribute "argument".
L 10 (C 32-43): "positional" argument must appear before all "namevalue" and "flag" arguments.

Correct the remaining issues.

{
  "_schemaVersion": "1.0.0",
  "myFunc":
  {
     "inputs":
     [
        {"name":"input1",  "kind":"required", "type":["numeric"], "purpose":"ID of item"},
        {"name":"input2",  "kind":"positional", "type":["numeric"], "purpose":"# Items"},
        {"name":"in3",  "kind":"positional", "type":["numeric"], "purpose":"Input Value"},
        {"name":"Name1", "kind":"namevalue", "type":["logical","scalar"],"purpose":"Option"},
        {"name":"Name2", "kind":"namevalue", "type":["char", "choices={'Default','Choice1','Choice2'}"]}
     ]
  }
}

Revalidate the functionSignatures.json file.

validateFunctionSignaturesJSON
validateFunctionSignaturesJSON completed without producing any messages.

Input Arguments

collapse all

Absolute or relative path to functionSignatures.json files, specified as a character vector, cell array of character vectors, or string array.

Example: ["ProjectA/functionSignatures.json" "ProjectB/functionSignatures.json"]

Example: 'myFolder/functionSignatures.json'

Version History

Introduced in R2018b