In task.json "Required" can have a expression or not? - azure-pipelines-build-task

In Task.json, for each input field the required field can be kept. This verify the field is mandatory or not.
I want to make a field required = true if the above field has a value "ABCD" and required = false if the above field value is something else. How can I achieve this ? In both case I have to show the field.
Can I add Expression to evaluate
{
"name": "path",
"type": "string",
"label": "Path",
"required": "false",
"validation": {
"expression":"isMatch(value,'^$|\\.(?i:)(?:png|jpeg)$','IgnoreCase')",
"message": "Choose a valid file."
},
"helpMarkDown": "Provide a path"
},

We need define the value of field 1 in the task.json file, then select the field 1 value to configure the field value, we can refer to power shell task to do this.
Task.json Sample:
"inputs": [
{
"name": "targetPath1",
"type": "radio",
"label": "targetPath",
"required": false,
"defaultValue": "filePath",
"helpMarkDown": "Target script type: File Path or path",
"options": {
"filePath": "File Path",
"path": "Path"
}
},
{
"name": "filePath",
"type": "filePath",
"label": "Script Path",
"visibleRule": "targetType = filePath",
"required": true,
"defaultValue": "",
"helpMarkDown": ""
},
{
"name": "path",
"type": "filePath",
"label": "Path",
"visibleRule": "targetType = filePath",
"required": true,
"defaultValue": "",
"helpMarkDown": ""
}
{
"name": "path1",
"type": "filePath",
"label": "Path1",
"visibleRule": "targetType = filePath",
"required": false,
"defaultValue": "",
"helpMarkDown": ""
}
]
Then we can use it in the task.ts file and set the expression.
In addition, if you do not want to change the field 2 name, we can define the same field 2 in the different json files and use it in the task.ts field.

Adding expression to required field is not yet achieved. Is this allowed? How it can be.
My alternate solution was to have two different input entries with same label and mutually opposite visibleRule. So in the code I should have same visibleRule condition to be checked before accessing the user input.
Example:
"inputs": [
{
"name": "targetPath1",
"type": "radio",
"label": "targetPath",
"defaultValue": "filePath",
"helpMarkDown": "Target script type: File Path or path",
"options": {
"filePath": "File Path",
"path": "Path"
}
},
{
"name": "filePath1",
"type": "filePath",
"label": "Script Path",
"visibleRule": "targetType = filePath",
"required": true,
"helpMarkDown": "If the user selects the "File Path" above then Script Path will be a mandatory field"
},
{
"name": "filePath2",
"type": "filePath",
"label": "Script Path",
"visibleRule": "targetType = path",
"required": false,
"helpMarkDown": "If the user selects the "File Path" above then Script Path will be a optional field"
}
]
While accessing these fields inside the code.
var path;
var targetPath = tl.getInput("targetPath1");
If(targetPath == "filePath")
path = tl.getInput("filePath1");
If(targetPath == "path")
path = tl.getInput("filePath2");

Related

How can I write the user's input to a variable in Node.js discord?

I'm developing a discord bot that will announce to a specific channel. Here is the code for the command:
export const ANNOUNCE_COMMAND = {
"name": "announceit",
"description": "Announce to the specified channel",
"options": [
{
"type": 7,
"name": "channel",
"description": "Channel to announce to",
"required": true
},
{
"type": 3,
"name": "announcement",
"description": "Text to announce to specified channel",
"required": true
},
{
"type": 3,
"name": "password",
"description": "The password to send the announcement. This is to stop members from using this command",
"required": true
}
]
}
How can I get the user's input and write it to a variable, and then use export to send it to "./app.js"? Variables should be named "announcement", "channel", and "password"

No operations defined in spec! && Resolver error Cannot read properties of undefined (reading 'api')

I have this error in my node JS in swagger-ui-express I don`t know how to fix it
enter image description here
this is the code in the index.js file
in this code I`am tryin to call the json file that I make and call it swagger.json
const swaggerUi = require('swagger-ui-express'), swaggerDocument = require('./swagger.json')
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument))
that the pic of the beggin of the code
enter image description here
but I`am think that the error is here in this json file
"paths": {
"/api/category": {
"tages": [
"Category"
],
"summery": [
"Get all Categories"
],
"parameters": [
{
"name": "categoryName",
"in": "query",
"required": false,
"description": "Category name",
"type": "string"
},
{
"name": "page",
"in": "query",
"required": false,
"description": "Page Number",
"type": "integer",
"default": 1
},
{
"name": "PageSize",
"in": "query",
"required": false,
"type": "integer",
"default": 10
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/ServiceResponse"
}
}
}
},
"post": {
"tages": [
"Category"
],
"summery": "Create Category API",
"parameters": [
{
"name": "categoryName",
"in": "formDate",
"descripition": "Category Name",
"required": true,
"type": "string"
},
{
"name": "CategoryDescription",
"in": "formDate",
"descripition": "Category Description",
"type": "string"
},
{
"name": "Category Image",
"in": "formDate",
"descripition": "Category Image",
"type": "file"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/ServiceResponse"
}
}
}
}
},
There are some typos and syntax errors:
The "/api/category" path is missing the "get": node that would wrap the GET operation definition. It should look like this:
"paths": {
"/api/category": {
"get": {
"tags": ...
"tages" should be "tags".
"summery": [...] should be replaced with:
"summary": "Get all Categories",
"in": "formDate" should be "in": "formData" ("a" at the end).
"descripition" should be "description".
Paste your OpenAPI JSON into https://editor.swagger.io - it will show all errors.

Swagger OpenAPI describing string array in multipart request

I need to describe a multipart query that has an array of strings. But I ran into a problem, in the query, the array elements are combined into one string instead of being separate string items. I am using OpenApi 3.0.3
"multipart/form-data": {
"schema": {
"type": "object",
"required": ["image"],
"properties": {
"image": {
"type": "string",
"format": "base64",
"description": "Banner image `1920x90, 2mb`"
},
"name": {
"type": "string",
"example": "Docs banner",
"description": "Banner name"
},
"link": {
"type": "string",
"description": "Banner link"
},
"page[]": {
"type": "array",
"items": {
"type": "string"
},
"example": ["HOME", "LIVE", "CHANNELS"],
"enum":[
"HOME",
"LIVE",
"CHANNELS",
"ARTISTS",
"DISCOVER",
"MYLIST",
"PROGRAM",
"PLAYER"
],
"description":"Banner pages"
}
}
}
}
What I received: page: [ 'HOME,LIVE,CHANNELS' ]
What I expect: page: [ 'HOME','LIVE','CHANNELS' ]
It's not very clear where exactly do you receive page: [ 'HOME,LIVE,CHANNELS' ], but looks like in enum there are possible values for items of your array. Try this:
"multipart/form-data": {
"schema": {
"type": "object",
"required": ["image"],
"properties": {
"image": {
"type": "string",
"format": "base64",
"description": "Banner image `1920x90, 2mb`"
},
"name": {
"type": "string",
"example": "Docs banner",
"description": "Banner name"
},
"link": {
"type": "string",
"description": "Banner link"
},
"page[]": {
"type": "array",
"items": {
"type": "string",
"enum":[
"HOME",
"LIVE",
"CHANNELS",
"ARTISTS",
"DISCOVER",
"MYLIST",
"PROGRAM",
"PLAYER"
],
"example": "HOME"
},
"example": [ "HOME", "LIVE", "CHANNELS" ],
"description":"Banner pages"
}
}
}
}
You can look for more details at the specification for adding examples.
This structure allows you to send multiple string enum items for page element, screenshot from swagger editor is below:

How to get value to description field defined for a property defined in loopback model

I have the following model definition in a loopback project:
`
{
"name": "Program",
"base": "PersistedModel",
"properties": {
"sId": {
"type": "string",
"required": true,
"length": 20
},
"Category": {
"type": "string",
"length": 255,
"description": "Category"
},
"ProgramName": {
"type": "string",
"length": 255,
"description": "Program Name"
},
"Program_Status": {
"type": "string",
"length": 255,
"description": "Program Status"
}
},
"validations": [],
"relations": {
"account": {
"type": "belongsTo",
"model": "Account",
"foreignKey": "Account__c",
"primaryKey": "sId"
},
},
"methods": {}
}
`
I want to get value of description defined in field name in any other model. Is there anyway in loopback or express.js to get it?
It's only possible via javascript code. I'm afraid there isn't a way to access json files properties from another json file.
In yourOtherModel.js
module.exports = function(yourOtherModel){
var programProps = yourOtherModel.app.models.Program.properties;
//Your props
var programDescription = programProps.Category.description;
}

angular-formly input label not showing

I have a frustrating issue with the type set as input I cant see the label. Its works fine if I use type as select. This is my code:
{
"type": "input",
"key": "firstName",
"templateOptions": {
"type": "text",
"placeholder": "jane doe",
"label": "First name"
}
},
that doesn't show the label but this does:
{
"key": "transportation",
"type": "select",
"templateOptions": {
"label": "How do you get around in the city",
"valueProp": "name",
"options": [
{
"name": "Car"
},
{
"name": "Helicopter"
}
]
}
}
Any help would be appreciated ?

Resources