I am using the Extended Choice Parameter Jenkins plugin. Used the Groovy script provided in the plugin web page, made some changes to it and currently having:
import org.boon.Boon;
def jsonEditorOptions = Boon.fromJson(/{
disable_edit_json: true,
disable_properties: true,
no_additional_properties: true,
disable_collapse: true,
disable_array_add: true,
disable_array_delete: true,
disable_array_reorder: true,
theme: "bootstrap2",
iconlib:"fontawesome4",
"schema":{
"title": "Environments",
"type": "array",
"format":"tabs",
"items": {
"title": "Environment",
"headerTemplate": "{{self.name}}",
"type": "object",
"properties": {
"name" : {
"title": "Environment",
"type": "string",
"readOnly": "true",
"propertyOrder" : 1
},
"Properties": {
"type": "array",
"format": "table",
"propertyOrder" : 2,
"items": {
"type": "object",
"properties": {
"URL" : {
"type": "string",
"readOnly": "true",
"propertyOrder" : 1
},
"User" : {
"type": "string",
"readOnly": "true",
"propertyOrder" : 2
},
"Password" : {
"type": "string",
"propertyOrder" : 3
}
}
}
}
}
}
},
startval: [
{
[
{
"name": "DEV",
"Properties": [
{
"URL": "host:port1",
"User": "user1",
"Password":""
}
]
},
{
"name": "TST",
"Properties": [
{
"URL": "host:port2,
"User": "user2",
"Password":""
}
]
}
]
}
]
}
}/);
return jsonEditorOptions;
I would like to know:
1) When building, based on a selection/input from the user, let's say: DEV. Then the values associated to DEV would be:
- URL: host:port1
- User: user1
- Password: 123456
How can these values (DEV, host:port1, user1, 123456) be obtained and passed as parameters in the Build steps?
2) Is there a way to mask the value of the field Password when it is being entered by the user?
Related
Need help to solve a swagger definiton schema using allOf and additionalProperties: false
Here my JSON Schema
"deliveryContact": {
"allOf": [
{
"type": "object",
"additionalProperties": false,
"properties": {
"name": {
"type": "string",
"maxLength": 1024
},
"phone": {
"type": "string",
"maxLength": 24
}
}
},
{
"$ref": "#/definitions/address"
}
]
},
"address": {
"type": "object",
"additionalProperties": false,
"properties": {
"address": {
"type": "string",
"maxLength": 1024
},
"postalCode": {
"type": "string",
"maxLength": 12
},
"city": {
"type": "string",
"maxLength": 512
},
"state": {
"type": "string",
"maxLength": 512
}
}
},
Sample data
delivery: {
address: 'my address',
postalCode: 'my postalCode',
city: 'my city',
state: 'my state',
name: 'my name',
phone: 'my phone'
},
I use AJV 6.10.0 to validate my data, but I think I have a wrong schema definition.
With Ajv options :
ajv = require('ajv')({
allErrors: true,
verbose: true,
removeAdditional: false,
});
Actually, I have 6 errors which warn of additional properties for each property
During validation of the first object in allOf (name and phone), validation found the error on (address, postalCode, city and state)
If I remove additionalProperties of the first allOf object (name, phone), during validation of address schema, the validation found the error on (name and phone)
How can I solve my schema definition
I managed to make it works, I have update your data structure to be more logical, see below :
JSON Schema
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"required": [
"delivery"
],
"properties": {
"delivery": {
"type": "object",
"additionalProperties": false,
"required": [
"name",
"phone",
"address"
],
"properties": {
"name": {
"type": "string",
"maxLength": 1024
},
"phone": {
"type": "string",
"maxLength": 24
},
"address": {
"$ref": "#/definitions/address"
}
}
}
},
"definitions": {
"address": {
"type": "object",
"additionalProperties": false,
"properties": {
"address": {
"type": "string",
"maxLength": 1024
},
"postalCode": {
"type": "string",
"maxLength": 12
},
"city": {
"type": "string",
"maxLength": 512
},
"state": {
"type": "string",
"maxLength": 512
}
}
}
}
}
Sample data
{
"delivery": {
"address": {
"address": "myaddress",
"postalCode": "mypostalCode",
"city": "mycity",
"state": "mystate"
},
"name": "myname",
"phone": "myphone"
}
}
If you want to test it, you can do that here : https://www.jsonschemavalidator.net/
This question already has an answer here:
Combining defintions in Swagger docs
(1 answer)
Closed 3 years ago.
I'm using ReDoc to visualize API documentation using an OpenAPI 2 (Swagger) JSON file. I'm trying to declare two request input parameters by including the first schema into the second one as follows:
...
"definitions": {
"list-request": {
"type": "object",
"properties": {
"token":{
"type": "string",
"format": "access-token",
"required": true
},
"userId":{
"type": "integer",
"required": true,
"format": "int32"
},
"mode": {
"type": "string",
"required": false,
"default": "lite",
"enum": [
"lite",
"detailed"
]
},
... // other peroperties
},
"xml": {
"name": "list-request"
}
},
"list-request-lite":{
"$ref": "#/definitions/list-request",
"properties":{
"mode": {
"type": "string",
"required": false,
"enum": ["lite"]
}
}
},
...
}
But it does not work - the list-request-lite schema just shows the mode property and none of the list-request schema properties are included. What am I doing wrong?
You need allOf to combine a $ref with other properties.
Also, the required properties need to be listed in the required array on the schema level. Individual properties don't have the required attribute.
"definitions": {
"list-request": {
"type": "object",
"properties": {
"token": {
"type": "string",
"format": "access-token"
},
"userId": {
"type": "integer",
"format": "int32"
},
"mode": {
"type": "string",
"default": "lite",
"enum": [
"lite",
"detailed"
]
}
},
"xml": {
"name": "list-request"
},
"required": [ // <---- required properties for this schema
"token",
"userId"
]
},
"list-request-lite": {
"allOf": [ // <---------
{
"$ref": "#/definitions/list-request"
},
{
"type": "object",
"properties": {
"mode": {
"type": "string",
"enum": ["lite"]
}
}
}
]
}
}
When calling my swagger.json from the swagger-ui I get an error:
Maximum call stack size exceeded
I guess it is because I have
Token which has an owner of Type User
User which has a Token of Type Token
When using the online-version of the swagger editior it can resolve the types. How can I configure swagger to resolve the types correctly?
The full swagger.json
{
"swagger": "2.0",
"info": {
"description": "Descr",
"version": "1.0.0",
"title": "Skeleton"
},
"host": "1.1.1.1:11",
"basePath": "/api",
"tags": [{
"name": "auth"
}
],
"schemes": ["http"],
"paths": {
"/auth/local": {
"post": {
"tags": ["auth"],
"summary": "Authenticates User",
"description": "This auths only local users",
"operationId": "authenticateUser",
"consumes": ["application/json"],
"produces": ["application/json"],
"parameters": [{
"in": "body",
"name": "body",
"required": false,
"schema": {
"$ref": "#/definitions/Credentials"
}
}
],
"responses": {
"200": {
"description": "successful operation",
"schema": {
"$ref": "#/definitions/AuthResponse"
}
}
}
}
},
"/auth/ldap": {
"post": {
"tags": ["auth"],
"operationId": "authenticateLdapUser",
"produces": ["application/json"],
"parameters": [{
"in": "body",
"name": "body",
"required": false,
"schema": {
"$ref": "#/definitions/Credentials"
}
}
],
"responses": {
"default": {
"description": "successful operation"
}
}
}
}
},
"definitions": {
"AuthResponse": {
"type": "object",
"properties": {
"issued": {
"type": "string",
"format": "date-time"
},
"responseType": {
"type": "string",
"enum": ["RESPONSE", "ERROR", "UNAUTHORIZED", "OK"]
},
"responseDescription": {
"type": "string"
},
"accessToken": {
"$ref": "#/definitions/Token"
},
"resourceName": {
"type": "string"
}
}
},
"Note": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int32"
},
"content": {
"type": "string"
},
"modified": {
"type": "string",
"format": "date-time"
}
}
},
"Token": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"expirationDate": {
"type": "string",
"format": "date-time"
},
"issued": {
"type": "string",
"format": "date-time"
},
"expired": {
"type": "boolean"
},
"owner": {
"$ref": "#/definitions/User"
}
}
},
"User": {
"type": "object",
"properties": {
"username": {
"type": "string"
},
"password": {
"type": "string"
},
"email": {
"type": "string"
},
"displayName": {
"type": "string"
},
"notes": {
"type": "array",
"items": {
"$ref": "#/definitions/Note"
}
},
"accessToken": {
"$ref": "#/definitions/Token"
}
}
},
"Credentials": {
"type": "object",
"properties": {
"user": {
"type": "string"
},
"password": {
"type": "string"
}
}
}
}
}
I have the same problem and I removed format: date-time and the error is gone.
Still I don't know what causes the error. But without that format everything goes ok.
In FastAPI which uses Swagger UI, I was receiving the same error. I updated the FastAPI package to get the last version of Swagger UI and then set the value of 'syntaxHighlight' to False, like below:
app = FastAPI(swagger_ui_parameters={'syntaxHighlight': False})
Just search how you can set this param directly in Swagger UI. This may fix your issue.
Swagger file is working as expected with warnig.
{
'swagger': "2.0",
"info": {
"version": "3.0",
"title": "Sample Service",
},
"schemes": [ "http" ],
"host": "sampleservice.azurewebsites.net",
"paths": {
"/": {
"post": {
"summary": "Sample service",
"description": "sample service",
"parameters": [
{
"name": "Input",
"in": "body",
"description": "valid input",
"schema": {
"type": "object",
"properties": {
"MainAttr-1": {
"required": [ "Attr-1" ],
"type": "object",
"properties": {
"Attr-1": {
"description": "Attr-1",
"required": true,
"type": "string"
},
"Attr-2": {
"description": "Attr-2",
"required": false,
"type": "string"
},
"Attr-3": {
"description": "Attr-3",
"required": false,
"type": "boolean"
},
"Attr-4": {
"description": "Attr-4",
"required": false,
"type": "boolean"
},
"Attr-5": {
"description": "Attr-5",
"required": false,
"type": "string"
}
}
},
"MainAttr-2": {
"type": "array",
"items": {
"type": "object",
"required": [ "Attr-1", "Attr-3", "Attr-5", "Attr-8" ],
"properties": {
"Attr-1": {
"description": "Attr-1",
"required": true,
"type": "string"
},
"Attr-2": {
"description": "Attr-2",
"required": false,
"type": "string"
},
"Attr-3": {
"description": "Attr-3",
"required": true,
"type": "boolean"
},
"Attr-4": {
"description": "Attr-4",
"required": false,
"type": "boolean"
},
"Attr-5": {
"description": "Attr-5",
"required": true,
"type": "string"
},
"Attr-6": {
"description": "Attr-6",
"required": false,
"type": "string"
},
"Attr-7": {
"description": "Attr-7",
"required": false,
"type": "string"
},
"Attr-8": {
"description": "Attr-8",
"required": true,
"type": "string"
}
}
}
}
}
}
}
],
"responses": {
"200": {
"description": "success"
}
}
}
}
}
}
Issue-1) Warning should be removed
Issue-2) Attr-3 in "MainAttr-2" is boolean type attribute and it is required. But when i am selecting 'false' from the dropdown, it is treating as invalid input. It treats only 'true' as valid input. (Any Boolean attribute which is required behaving like this)
Due this warning i am unable to deliver the code.
Thanks in advance.
In the beginning, change 'swagger' to "swagger". JSON requires double quotes around strings.
Remove extra comma at the end of:
"title": "Sample Service",
Remove the required attribute from ALL property definitions (Attr-1 to Attr-8) and use the required list at the object level instead (under MainAttr-1 and MainAttr-2).
"MainAttr-1": {
"required": [ "Attr-1" ], <-- list the required properties in this array
"type": "object",
"properties": {
"Attr-1": {
"description": "Attr-1",
"required": true, <-- remove this
"type": "string"
},
Other than that your spec is fine.
Is it possible to specify the "response" based on the "consumes" option on Swagger?
My API can return "json" or "text" and I'd like that the "example value", when the response's status is 200 changes if the user selects from Response Content Type the option application/json or text/plain.
This is a piece of my swagger.json file:
{
"swagger": "2.0",
"produces": [
"application/json",
"text/plain"
],
"consumes" : [
"application\/json"
],
"paths": {
"/writer/1/": {
"get": {
"summary": "Get all writers",
"description": "Writer description.",
"tags": [
"writer"
],
"responses": {
"200": {
"description" : "successful operation",
"schema" : {
"$ref" : "#\/definitions\/writerResponse"
}
},
}
}
}
"definitions": {
"writerResponse": {
"properties": {
"meta": {
"type" :"object",
"schema" : {
"$ref" : "#\/definitions\/metaDefinition"
}
},
"data": {
"type" :"array",
"items": {
"$ref" : "#\/definitions\/writer"
}
}
}
},
"writer": {
"properties": {
"id": {
"type": "integer",
"description": "writer id.",
"example": "1477"
},
"short": {
"type": "string",
"description": "short description.",
"example": "short example"
},
"modified": {
"type": "string",
"description": "modified description.",
"example": "2016-05-21 22:58:36"
}
}
},
}
This is an example of the JSON output when user selects application/json:
{
"meta": {
"total": "1234",
"last_page": "967",
"per_page": "4000",
"current_page": "1",
"next_page_url": "http://localhost/api/<ws>/1?page=2",
"prev_page_url": "http://localhost/api/<ws>/1?page=1",
"from": "1",
"to": "4000"
},
"data": [
{
"id": "1",
"short": "TEST1",
"modified": "2011-03-07 14:17:23"
},
{
"id": "5",
"short": "TEST2",
"modified": "2015-05-26 12:39:45"
}
]
}
And this is the output when the user selects text/plain:
id|short|modified
1|TEST1|2011-03-07 14:17:23
5|TEST2|2015-05-26 12:39:45