I used Extended Choice Parameter Script plugin and created a JSON editor with Array type as below:
disable_edit_json: true,
disable_properties: true,
disable_collapse: true,
theme: "jqueryui",
iconlib:"fontawesome4",
schema: {
"type": "object",
"title": "instances",
"properties": {
"instance": {
"type": "array",
"propertyOrder" : 1,
"format": "table",
"uniqueItems": true,
"items": {
"title": "instance",
"type": "object",
"properties": {
"url": {
"type": "string"
}
}
}
}
}
}
The parameter name is "ServerUrls". Using this I can pass one or many URLs to my Jenkins job, and I want to know the size of the array and access each of these parameter values from within a Groovy script. Conceptually something like ServerUrls.instance[0], ServerUrls.instance1 etc.
Just doing println params["ServerUrls"] throws an Exception.
Can someone please help?
It worked. The solution is as below, and it returns the value as JSON in a string format. It should be fairly easy to parse the JSON to obtain the internals of it.
def hardcoded_param = "ServerUrls"
def resolver = build.buildVariableResolver
def hardcoded_param_value = resolver.resolve(hardcoded_param)
println hardcoded_param_value
Related
I have a large number of APIs, each without a strong class definition for output, like this
Return Ok(New With {
.ServerDecryptPass = ServerDecryptPass,
.VmConnectionAdminDecryptPass = VmConnectionAdminDecryptPass,
.DockerHubDecryptPass = DockerHubDecryptPass,
.DockerRegistryDecryptPass = DockerRegistryDecryptPass,
.VmConnectionUserDecryptPass = VmConnectionUserDecryptPass
})
Swagger, of course, doesn't see anything for response type in this case
The simplest way to formalize this JSON result is creating a JSON schema, for example in this case it looks like
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"serverDecryptPass": {
"type": "object",
"properties": {
"item1": {
"type": "array",
"items": {
"type": "number"
}
},
"item2": {
"type": "null"
}
}
},
"vmConnectionAdminDecryptPass": {
...
}
I have a hundreds of APIs and I am searching for a simple way to formalize the output of the APIs in order to generate a frontend automatically from this backend API. I searched for a simple way to setup the attribute, ProducesResponseType, based on XML schema or maybe even an example of an API result.
What is a possible solution?
Using MarkLogic version 10.0-4.2, I am trying to validate a simple JSON record against a simple JSON schema.
JSON Schema:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"SourceSystemName": {
"type": "string"
},
"BatchDtTm": {
"type": "string"
},
"SubjectArea": {
"type": "string"
},
"DocumentType": {
"type": "string"
},
"LastUpdatedDt": {
"type": "string"
},
"required": [
"SourceSystemName",
"BatchDtTm",
"SubjectArea",
"DocumentType",
"LastUpdatedDt",
]
}
}
Code being run in Query Console:
let jsonRecord = {"SourceSystemName":"ODH","BatchDtTm":"09/17/21 08:51:48:472723","SubjectArea":"Customer","DocumentType":"Preference","LastUpdatedDt":"09/17/21 03:59:53:629707"};
xdmp.jsonValidate(jsonRecord, cts.doc('/schemas/NewSchema.json').toString());
When I run the above code, I get error
XDMP-JSVALIDATEBADSCHEMA: Invalid schema "": ""
I'm not really sure what is 'invalid' about my schema. Can someone offer some insight into what MarkLogic is viewing as 'invalid'?
The second parameter for $schema is supposed to be the URI of the schema document.
$schema URI of the JSON schema to use for validation.
You are attempting to pass in the stringified content.
Try:
xdmp.jsonValidate(jsonRecord, '/schemas/NewSchema.json');
And ensure that the schema document is inserted into the Schemas database, not the content database.
I'd like to use my JSON schemas to generate the documentation.
In the example below, I want to list all combinations ErrorNumber/ErrorMessage available in my output messages in JSON.
But I can't find a way on the object level, my attempts with "examples" or "enum" failed.
Does anyone have a solution?
{
"type": "object",
"required": [
"ErrorNumber",
"ErrorMessage"
],
"properties": {
"ErrorNumber": {
"$id": "#root/ErrorNumber",
"type": "integer"
},
"ErrorMessage": {
"$id": "#root/ErrorMessage",
"type": "string"
}
}
}
Did you mean to write "$ref" where you use "$id" in the example?
Where exactly did you have problems with enum? The following works fine for me with a draft-2020-12 Validator (and after removing your "$id"!):
{
// ... your JSON here ...
"enum": [
{"ErrorNumber": 200, "ErrorMessage": "OK"},
{"ErrorNumber": 404, "ErrorMessage": "Not found."}
// ...
]
}
Different approaches, in case you still can change that:
If your error numbers start at 0 and are contiguous, then an Array of messages might serve your purpose.
Alternatively an object with numerical keys might:
{
"200": "OK",
"404": "Not found."
}
BACKGROUND:
I have mockedup my issue here for reference:
https://jsonschemalint.com/#/version/draft-06/markup/json?gist=4c185903d7aeb13f6977852a09cf5462
and I am using this npm package: https://www.npmjs.com/package/jsonschema
CODE
//i read in JSON specified in files (the contents of which are below) and parse them into JSON objects. This process works fine.
var jsonDef = JSON.parse(schemaFile); //i store this jsonDef in my database as an object
var jsonObj = JSON.parse(objFile);
var jsonv = new JSONValidator();
var validateResult = jsonv.validate(jsonObj, jsonDef); //jsonDef is read from my database
//validateResult.valid is true
PROBLEM:
I have a general schema + metadata definition like so ("props" contains the actual object schema I want to validate)
schemaFile:
{
"name":"schoolDemo",
"displayName":"School Demo",
"propertiesKey":"assetId",
"props":{
"assetId": {
"type": "string"
},
"grade": {
"type": "number"
}
}
}
objFile:
{
"assetId": "75255972",
"grade": "A"
}
However, when I try to validate against the following user-input object, it succeeds. Shouldn't it fail because:
(1) there is no "properties" element in the initial metadata+schema definition? This field seems to be required based on the examples shown here: https://www.npmjs.com/package/jsonschema
(2) the type for grade is not a number
What am I doing wrong?
The validation is passing because the schema is not well formed ("properties" is missing).
Try this instead and then the validation will fail:
{
"name": "schoolDemo",
"displayName": "School Demo",
"propertiesKey": "assetId",
"properties": {
"assetId": {
"type": "string"
},
"grade": {
"type": "number"
}
}
}
I need a help regarding schema extraction by property.
For example i have a JSON schema:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "A simple address format",
"type": "object",
"properties": {
"street-name": { "type": "string" },
"locality":{ "type": "string" },
"region": { "type": "string" },
"postal-code": { "type": "int" },
"country-name": { "type": "string"}
},
"required": ["locality", "region", "country-name"]
}
I have an use case, where i need to extract the schema corresponding to each property and send to another service, where it will do validation against the value and save in database. Here is the sample object i need to send to another service.
{
"propertyName": "street-name",
"value": "19, Canton street",
**"schema": { "type": "string" }**
}
The questions is,
how we extract the schema for a particular property from a give JSON schema??
Given the property path, Is there any nodejs module exists to do this schema extraction? or if there is any other solutions exists ?
Because this is very simple scenario, but if we have array, anyOf, OneOf type its getting complicated;
Thanks in advance ! Please let me know if the question is not clear !
sadish