How to create checklist in Configuration from VSCode extension - visual-studio-code

How do I create a checklist in configuration panel via extension.
I dont see an option to do this in documentation. Something like this:
Tried placing it hierarchically but UI seems to be different :
"apexPMD.rulefix.1": {
"type": "boolean",
"default": true,
"description": "If Else Statements Must use Braces"
},
"apexPMD.rulefix.2": {
"type": "boolean",
"default": true,
"description": "For Statements Must use Braces"
},
"apexPMD.rulefix.3": {
"type": "boolean",
"default": true,
"description": "While Statements Must use Braces"
},

Related

Task.Json triggers validation on invisible only fields

I am trying to create a Azure DevOps Pipelines Custom extension. I have a task.json where fields are visible on certain conditions.
For example:
{
"name": "actions",
"type": "picklist",
"label": "Actions",
"defaultValue": "Select",
"required": true,
"helpMarkDown": "Select an Action from the dropdown as per your requirement.",
"options": {
"New": "Add",
"Delete": "Delete"
}
},
{
"name": "backEndIPAddress",
"type": "string",
"label": "IP Address",
"required": true,
"defaultValue": "",
"helpMarkDown": "",
"visibleRule": "actions = New",
"validation": {
"expression": "isMatch(value,'^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?){0,15}$','IgnoreCase')",
"message": "Invalid IP Address. Please try again!"
}
}
The issue when the IPAddress field is hidden, the validation is still tried and it fails. How to ensure that the fields are validated only if they are visible?
A few options:
Set a default value for the input
Update the regex to include ^$| at the start to allow empty values ('require':true will take care of the requiredness)
Remember that there should be a default isIpV4Address(value: string) function so you don't have to specify the regex.
From the docs it looks like there is an upcoming when clause which will dictate when the set of rules should trigger, I suppose this may be causing the currently unwanted behavior.
See also:
https://github.com/Microsoft/vsts-tasks/blob/1d75fa8f66aa1cf7a9cb62946939f30f087b2969/docs/taskinputvalidation.md

Write initial settings to settings.json

I am looking for a way to write initial settings to settings.json for when my extension is installed.
I found WorkspaceConfiguration API, but that seems to retrieving/updating values at runtime.
I'm looking to get my settings + comments into the default settings file
e.g. How TSLint does it:
I hope I get your question correctly: I assume you mean the User Settings settings.json you can get via File>Preferences>User Settings.
If you know that TSLint does it, you can go to your extensions folder (windows: $USERFOLDER/.vscode/extensions), pick the extension (in my case it was the folder "eg2.tslint-0.6.7") and peek the files.
...
"contributes": {
"configuration": {
"type": "object",
"title": "TSLint",
"properties": {
"tslint.enable": {
"type": "boolean",
"default": true,
"description": "Control whether tslint is enabled for TypeScript files or not."
},
"tslint.rulesDirectory": {
"type": [
"string",
"array"
],
"items": {
"type": "string"
},
"description": "An additional rules directory",
"default": ""
},
"tslint.validateWithDefaultConfig": {
"type": "boolean",
"description": "Validate a file when there is only a default tslint configuration is found",
"default": false
},
"tslint.configFile": {
"type": "string",
"description": "The path to the rules configuration file",
"default": ""
},
"tslint.ignoreDefinitionFiles": {
"type": "boolean",
"default": true,
"description": "Control if TypeScript definition files should be ignored"
},
"tslint.exclude": {
"type": [
"string",
"array"
],
"items": {
"type": "string"
},
"description": "Configure glob patterns of file paths to exclude from linting"
},
"tslint.run": {
"type": "string",
"enum": [
"onSave",
"onType"
],
"default": "onType",
"description": "Run the linter on save (onSave) or on type (onType)"
},
"tslint.nodePath": {
"type": "string",
"default": "",
"description": "A path added to NODE_PATH when resolving the tslint module."
},
"tslint.autoFixOnSave": {
"type": "boolean",
"default": false,
"description": "Turns auto fix on save on or off."
}
}
}
...
Hope this helps

TFS 2015.3 custom build step not sending variables to the script

I've followed closely the design guidance found here, here and here, but I keep getting this PowerShell error:
Cannot process command because of one or more missing mandatory parameters: SourcePath FilePattern BuildRegex.
The relevant config data is below.
I've checked and double-checked to make sure that the variables are present in my task.json file. I've also looked at the config for other working tasks (e.g. VSBuild) and there's no significant difference in the variable declaration and PowerShell execution syntax.
What could be going wrong here? This is a very simple architecture—there's not much to break. But clearly something has done just that.
From task.json:
"inputs": [
{
"name": "SourcePath",
"type": "filePath",
"label": "Source path",
"defaultValue": "",
"required": true,
"helpMarkDown": "Path in which to search for version files (like AssemblyInfo.* files). NOTE: this is case sensitive for non-Windows systems."
},
{
"name": "FilePattern",
"type": "string",
"label": "File pattern",
"defaultValue": "AssemblyInfo.*",
"required": true,
"helpMarkDown": "File filter to replace version info. The version number pattern should exist somewhere in the file(s). Supports minimatch. NOTE: this is casese sensitive for non-Windows systems."
},
{
"name": "BuildRegEx",
"type": "string",
"label": "Build RegEx pattern",
"defaultValue": "\\d+\\.\\d+\\.\\d+\\.\\d+",
"required": true,
"helpMarkDown": "Regular Expression to extract version from build number. This is also the default replace RegEx (unless otherwise specified in Advanced settings)."
},
{
"name": "BuildRegExIndex",
"type": "string",
"label": "Build RegEx group index",
"defaultValue": "0",
"required": false,
"helpMarkDown": "Index of the group in the Build RegEx that you want to use as the version number. Leave as 0 if you have no groups.",
"groupName": "advanced"
},
{
"name": "ReplaceRegEx",
"type": "string",
"label": "RegEx replace pattern",
"defaultValue": "",
"required": false,
"helpMarkDown": "RegEx to replace with in files. Leave blank to use the Build RegEx Pattern.",
"groupName": "advanced"
},
{
"name": "ReplacePrefix",
"type": "string",
"label": "Prefix for replacements",
"defaultValue": "",
"required": false,
"helpMarkDown": "Prefix for the RegEx result string.",
"groupName": "advanced"
},
{
"name": "ReplaceSuffix",
"type": "string",
"label": "Suffix for replacements",
"defaultValue": "",
"required": false,
"helpMarkDown": "Suffix for the RegEx result string.",
"groupName": "advanced"
},
{
"name": "FailIfNoMatchFound",
"type": "boolean",
"label": "Fail if no target match found",
"defaultValue": "false",
"required": false,
"helpMarkDown": "Fail the build if no match is found for the replace RegEx in the target file(s).",
"groupName": "advanced"
}
],
"execution": {
"PowerShell3": {
"target": "VersionAssembly.ps1"
}
}
From VersionAssembly.ps1:
[CmdletBinding()]
param(
[string][Parameter(Mandatory=$True)][ValidateNotNullOrEmpty()] $SourcePath,
[string][Parameter(Mandatory=$True)][ValidateNotNullOrEmpty()] $FilePattern,
[string][Parameter(Mandatory=$True)][ValidateNotNullOrEmpty()] $BuildRegex,
[string]$BuildRegexIndex,
[string]$ReplaceRegex,
[string]$ReplacePrefix,
[string]$ReplaceSuffix,
[string]$FailIfNoMatchFound,
[string]$BuildNumber = $ENV:BUILD_BUILDNUMBER
)
Apparently I wasn't following closely enough... I missed the warning on this page:
Words of warning
Tasks can be versioned, use this to your advantage. All build definitions use the latest available version of a specific task, you can’t change this behavior from the web interface, so always assume the latest version is being used.
If you don’t change the version number of your task when updating it, the build agents that have previously used your task will not download the newer version because the version number is still the same. This means that if you change the behavior of your task, you should always update the version number!
Once I got that all straightened out, everything worked fine.
Possibly the examples accepting inputs in the param section are out of date. It appears that you now need to use the Vsts-task-lib commands from your PowerShell script to get the input parameters.
[CmdletBinding()]
param()
$myParam = Get-VstsInput -Name myParam -Require

json schema issue on required property

I need to write the JSON Schema based on the specification defined by http://json-schema.org/. But I'm struggling for the required/mandatory property validation. Below is the JSON schema that I have written where all the 3 properties are mandatory but In my case either one should be mandatory. How to do this?.
{
"id": "http://example.com/searchShops-schema#",
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "searchShops Service",
"description": "",
"type": "object",
"properties": {
"city":{
"type": "string"
},
"address":{
"type": "string"
},
"zipCode":{
"type": "integer"
}
},
"required": ["city", "address", "zipCode"]
}
If your goal is to tell that "I want at least one member to exist" then use minProperties:
{
"type": "object",
"etc": "etc",
"minProperties": 1
}
Note also that you can use "dependencies" to great effect if you also want additional constraints to exist when this or that member is present.
{
...
"anyOf": [
{ "required": ["city"] },
{ "required": ["address"] },
{ "required": ["zipcode"] },
]
}
Or use "oneOf" if exactly one property should be present

Swagger UI doesn't show embedded json properties model

I am using the swagger tool for documenting my Jersey based REST API (the swaggerui I am using was downloaded on June 2014 don't know if this issue has been fixed in later versions but as I made a lot of customization to its code so I don't have the option to download the latest without investing lot of time to customize it again).
So far and until now, all my transfer objects have one level deep properties (no embedded pojos). But now that I added some rest paths that are returning more complex objects (two levels of depth) I found that SwaggerUI is not expanding the JSON model schema when having embedded objects.
Here is the important part of the swagger doc:
...
{
"path": "/user/combo",
"operations": [{
"method": "POST",
"summary": "Inserts a combo (user, address)",
"notes": "Will insert a new user and a address definition in a single step",
"type": "UserAndAddressWithIdSwaggerDto",
"nickname": "insertCombo",
"consumes": ["application/json"],
"parameters": [{
"name": "body",
"description": "New user and address combo",
"required": true,
"type": "UserAndAddressWithIdSwaggerDto",
"paramType": "body",
"allowMultiple": false
}],
"responseMessages": [{
"code": 200,
"message": "OK",
"responseModel": "UserAndAddressWithIdSwaggerDto"
}]
}]
}
...
"models": {
"UserAndAddressWithIdSwaggerDto": {
"id": "UserAndAddressWithIdSwaggerDto",
"description": "",
"required": ["user",
"address"],
"properties": {
"user": {
"$ref": "UserDto",
"description": "User"
},
"address": {
"$ref": "AddressDto",
"description": "Address"
}
}
},
"UserDto": {
"id": "UserDto",
"properties": {
"userId": {
"type": "integer",
"format": "int64"
},
"name": {
"type": "string"
},...
},
"AddressDto": {
"id": "AddressDto",
"properties": {
"addressId": {
"type": "integer",
"format": "int64"
},
"street": {
"type": "string"
},...
}
}
...
The embedded objects are User and Address, their models are being created correctly as shown in the json response.
But when opening the SwaggerUI I can only see:
{
"user": "UserDto",
"address": "AddressDto"
}
But I should see something like:
{
"user": {
"userId": "integer",
"name": "string",...
},
"address": {
"addressId": "integer",
"street": "string",...
}
}
Something may be wrong in the code that expands the internal properties, the javascript console doesn't show any error so I assume this is a bug.
I found the solution, there is a a line of code that needs to be modified to make it work properly:
In the swagger.js file there is a getSampleValue function with a conditional checking for undefined:
SwaggerModelProperty.prototype.getSampleValue = function(modelsToIgnore) {
var result;
if ((this.refModel != null) && (modelsToIgnore[this.refModel.name] === 'undefined'))
...
I updated the equality check to (removing quotes):
modelsToIgnore[this.refModel.name] === undefined
After that, SwaggerUI is able to show the embedded models.