List of Objects in Swagger - swagger

I need to display the model schema as a arrayList for "SourcePoints"
Current Body for my post method in swagger:
{
"PreferredTransforms": [
{
"Code": 0
}
],
"SourceCRS": {
"Code": 50015
},
"SourcePoints": [
{
"x": "7000000",
"y": "3100000",
"z": "0"
}
],
"TargetCRS": {
"Code": 50015
}
}
But i want multiple sourcePoints. ie like below structure should be available in my swagger page:
{
"PreferredTransforms": [
{
"Code": 0
}
],
"SourceCRS": {
"Code": 50015
},
"SourcePoints": [
{
"x": "10000",
"y": "20000",
"z": "40000"
},
{
"x": "40000",
"y": "50000",
"z": "60000"
}
],
"TargetCRS": {
"Code": 50015
}
}
My Pojo classes Look like this
CRSConversionResult.java
public class CRSConversionResult {
#JsonProperty("CriteriaMessage")
private String criteriaMessage;
#JsonProperty("ResultPoints")
private List<Point> resultPoints;
#JsonProperty("TransformName")
private String transformName;
#JsonProperty("TransformDescription")
private String transformDescription;
public List<Point> getResultPoints() {
return resultPoints;
}}
Point.java
#JsonIgnoreProperties(ignoreUnknown = true)
public class Point {
#JsonProperty("x")
private String x = "0";
#JsonProperty("y")
private String y = "0";
#JsonProperty("z")
private String z = "0";
public Point() {
}}
build.gradle file
compile("io.springfox:springfox-swagger2:2.5.0")
compile("io.springfox:springfox-swagger-ui:2.5.0")
Please help. Thanks in advance.

Related

Api Connect v10 map json message with object array to object using foreach or similar (map policy)

I'm new to API Connect, and I haven't been able to find the correct mapping to pass from an array of objects to an object, evaluating its content.
I explain:
I have as input a json like this:
{
"methodCall": {
"methodName": {
"$": "ThisIsTheMethodName"
},
"params": {
"param": {
"value": {
"array": {
"data": {
"value": {
"struct": {
"member": [
{
"name": {
"$": "message"
},
"value": {
"string": {
"$": "Some text to send to client"
}
}
},
{
"name": {
"$": "phone"
},
"value": {
"string": {
"$": "9876543120124"
}
}
},
{
"name": {
"$": "date"
},
"value": {
"string": {}
}
},
{
"name": {
"$": "appid"
},
"value": {
"string": {
"$": "Application Identificator"
}
}
},
{
"name": {
"$": "costCenter"
},
"value": {
"string": {
"$": "102030"
}
}
},
{
"name": {
"$": "filled"
},
"value": {
"string": {
"$": "filledString"
}
}
}
]
}
}
}
}
}
}
}
}
}
and I need to generate this json output from the mapping:
{
"phoneNumberSMS":"983849780",
"message":"Some text to send to client",
"date": "2022-10-04T15:30:00",
"appId":"Application Identificator",
"costCenter":"102030",
"filled":"filledString" }
I have tried with the following configuration, but without success:
On the YAML
actions:
- set: output.phoneNumberSMS
foreach: input.methodCall.params.param.value.array.data.value.struct.member.value.string
from:
- input.methodCall.params.param.value.array.data.value.struct.member.name.$
- input.methodCall.params.param.value.array.data.value.struct.member.value.string.$
values: |-
var retValue1 = '';
if($(input.methodCall.params.param.value.array.data.value.struct.member.name.$) == 'phone'){
retValue1=input.methodCall.params.param.value.array.data.value.struct.member.value.string.$;
}
retValue1;
I appreciate your help !!
I solve this in two phases of mapping:
Create an array called members, where each node is of type member, which has name and value properties.
This 'members' array is the receiver of the data coming from the request.
In the second phase of the mapping, I took the output variable from the previous mapping (of type members) and assigned it to message.body.
This with the aim of getting rid of the field names with a dollar symbol ($), so the mapping will not give any error for not recognizing it.

Invalid ReplaceNamedRangeContent request

I can successfully create a name range using batchUpdate api, however, replaceNameRangeContent gives the following error:
{ "error": { "code": 400, "message": "Invalid requests[0].replaceNamedRangeContent: Named range with ID kix.ydbik9q4xmna contains content that cannot be replaced.", "status": "INVALID_ARGUMENT" } }
The request for this was:
{ "requests": [ { "replaceNamedRangeContent": { "namedRangeId": "kix.ydbik9q4xmna", "text": "" } } ] }
Am I using the API properly? I created the name range giving start/endindex and naming it. It creates the NameRangeId that I used in the replace content post.
There was content in the index range above. However, below is a sample doc structure for an empty doc (with doc styles, etc. omitted). I tried a
{
"requests": [
{
"createNamedRange": {
"range": {
"startIndex": 1,
"endIndex": 2
},
"name": "ApplicantName"
}
}
]
}
followed by
{
"requests": [
{
"replaceNamedRangeContent": {
"namedRangeId": "kix.f7g9w0sr3kyp",
"text": "Applicant Name"
}
}
]
}
and get the same error. But when doing the create named range it would not accept any start/end index besides 1 and 2.
I must not understand the actual intent of named ranges!
Sample:
{
"title": "Test mule",
"body": {
"content": [
{
"endIndex": 1,
"sectionBreak": {
"sectionStyle": {
"columnSeparatorStyle": "NONE",
"contentDirection": "LEFT_TO_RIGHT",
"sectionType": "CONTINUOUS"
}
}
},
{
"startIndex": 1,
"endIndex": 2,
"paragraph": {
"elements": [
{
"startIndex": 1,
"endIndex": 2,
"textRun": {
"content": "\n",
"textStyle": {}
}
}
],
"paragraphStyle": {
"namedStyleType": "NORMAL_TEXT",
"direction": "LEFT_TO_RIGHT"
}
}
}
]
}
I can reproduce your error when creating a named range with "startIndex": 0
Mind that indices for paragraphs (and thus text) in Google Docs refer to the position of a character in the text and start with 1.
So if you create a name range specifying the indices correctly, you will not get the error mesage
{ "error": { "code": 400, "message": "Invalid requests[0].replaceNamedRangeContent: Named range with ID kix.ydbik9q4xmna contains content that cannot be replaced.", "status": "INVALID_ARGUMENT" } }
Sample request for creating named ranges:
{
"requests": [
{
"createNamedRange": {
"range": {
"startIndex": 5,
"endIndex": 7
},
"name": "test3"
}
}
]
}

How to provide string array (default values) in the swagger definition

Currently, my swagger definition has :
"MyAttribute": {
"type": "string",
"default": "item1",
"enum": [
"item1",
"item2"
],
"xml": {
"attribute": true
}
},
Swagger codegen generates this java code:
#XmlEnum(String.class)
public enum MyAttribute{
#XmlEnumValue("item1")
item1("item1"),
#XmlEnumValue("item2")
item2("item2");
private String value;
/**
* #param value the string representation of the map specification type attribute
*/
MyAttribute(final String value) {
this.value = value;
}
#Override
public String toString() {
return String.valueOf(value);
}
}
Now, I want to have a string array(with values) instead of enum.
I tried this (but shows errors on swagger website : http://editor.swagger.io/)
"MyAttribute": {
"type": "array",
"items": {
"type": "string",
"values": [
"item1",
"item2"
]
},
"xml": {
"attribute": true
}
}
How to achieve this?

Modifying cypher query

I have neo4j data as like as given below:
Here I have COUNTEY_PROVINCE relationship between country and province, PROVINCE_CITY relationship between province and city and COUNTRY_CITY relationship between country and city. When user call an api with country name, I want to return all province with city. To do this, I have run the following query:
MATCH path=(cn:Country { name: "Bangladesh" })-[:COUNTRY_PROVINCE]->(pv:Province)-[:PROVINCE_CITY]->(ct:City)
RETURN { x: nodes(path) }
And I have got the following result ( country, province, city ) :
{ x: nodes(path) }
{ "x": [ { "name": "Bangladesh"}, { "name": "Dhaka" }, { "name": "Dhaka" } ] }
{ "x": [ { "name": "Bangladesh"}, { "name": "Dhaka" }, { "name": "Narayanganj" } ] }
{ "x": [ { "name": "Bangladesh"}, { "name": "Sylhet" }, { "name": "Sylhet" } ] }
{ "x": [ { "name": "Bangladesh"}, { "name": "Khulna" }, { "name": "Khulna" } ] }
{ "x": [ { "name": "Bangladesh"}, { "name": "Khulna" }, { "name": "Jessore" } ] }
{ "x": [ { "name": "Bangladesh"}, { "name": "Chittagong" }, { "name": "Chittagong" } ] }
{ "x": [ { "name": "Bangladesh"}, { "name": "Chittagong" }, { "name": "Comilla" } ] }
Now my question is, how can I get country list with province and associate cities like :
[
{
country: {
name: "Bangladesh",
province: [
{
name: "Dhaka",
city: [
{ name: "Dhaka" },
{ name: "Narayanganj" }
]
},
{
name: "Sylhet",
city: [
{ name: "Sylhet" }
]
},
{
name: "Chittagong",
city: [
{ name: "Chittagong" },
{ name: "Comilla" }
]
},
{
name: "Khulna",
city: [
{ name: "Khulna" },
{ name: "Jessore" }
]
}
]
}
}
]
I simulated your scenario here.
Load the initial data set (Similar to the data set described in the question):
CREATE (c:Country {name:"Country A"})
CREATE (p1:Province {name:"Province A"})
CREATE (p2:Province {name:"Province B"})
CREATE (c1:City {name:"City A"})
CREATE (c2:City {name:"City B"})
CREATE (c3:City {name:"City C"})
CREATE (c4:City {name:"City D"})
CREATE (c)-[:COUNTRY_PROVINCE]->(p1)
CREATE (p1)-[:PROVINCE_CITY]->(c1)
CREATE (p1)-[:PROVINCE_CITY]->(c2)
CREATE (c)-[:COUNTRY_PROVINCE]->(p2)
CREATE (p2)-[:PROVINCE_CITY]->(c3)
CREATE (p2)-[:PROVINCE_CITY]->(c4)
The query:
MATCH (cn:Country { name: "Country A" })-[:COUNTRY_PROVINCE]->(pv:Province)-[:PROVINCE_CITY]->(ct:City)
WITH cn, pv, collect({name : ct.name}) as cities
RETURN {coutry : {name : cn.name, province : collect( distinct { name:pv.name, city :cities }) } }
The result:
{
"coutry":{
"name":"Country A",
"province":[
{
"name":"Province A",
"city":[
{
"name":"City B"
},
{
"name":"City A"
}
]
},
{
"name":"Province B",
"city":[
{
"name":"City D"
},
{
"name":"City C"
}
]
}
]
}
}
The above query uses the collect() function and the DISTINCT operator to achieve the desired format.
Well, if you're going to return the nodes of a path, that's obviously what you are going to get. You've got several options to do it differently :
Check out https://neo4j-contrib.github.io/neo4j-apoc-procedures/index32.html#_from_tojson, for example apoc.convert.toTree may get you very close to what you want.
Do it yourself. Send the query from any client application and process (+ format) the results yourself (in Java, Python, C#, ...)
...
Hope this helps.
Regards,
Tom

TFS 2017 Work item Extension not working

New to this TS scripting so a little help is requested,
I'm trying to create an extension that created a url from 4 work item fields.
example contribution:
{
"manifestVersion": 1,
"id": "tritech-tfsurl-control",
"version": "0.1.18",
"name": "tritech-tfsurl-control",
"scopes": [ "vso.work", "vso.work_write" ],
"description": "4 fields to a url",
"publisher": "TriTech-Software-Systems",
"icons": {
"default": "img/logo.png"
},
"targets": [
{
"id": "Microsoft.VisualStudio.Services"
}
],
"tags": [
"Work Item",
"Work Item control",
"Url",
"Url tfs server"
],
"content": {
"details": {
"path": "details.md"
}
},
"links": {
"home": {
"uri": "http://www.Tritech.com"
}
},
"branding": {
"color": "rgb(220, 235, 252)",
"theme": "light"
},
"files": [
{
"path": "img",
"addressable": true
},
{
"path": "index.html",
"addressable": true
}
],
"categories": [
"Plan and track"
],
"contributions": [
{
"id": "tfsurlcontrol-action",
"type": "ms.vss-work-web.work-item-form-control",
"description": "Work Item fields to create url from",
"targets": [
"ms.vss-work-web.work-item-form"
],
"properties": {
"name": "tfsurl-control",
"uri": "index.html",
"height": 90,
"inputs": [
{
"id": "PreviousTFSServer",
"description": "The TFS server url that has the work item.",
"type": "WorkItemField",
"properties": {
"workItemFieldTypes": [ "String" ]
},
"validation": {
"dataType": "String",
"isRequired": true
}
},
{
"id": "TFSCollection",
"description": "The original tfs collection name",
"type": "WorkItemField",
"properties": {
"workItemFieldTypes": [ "String" ]
},
"validation": {
"dataType": "String",
"isRequired": true
}
},
{
"id": "TfsTeamProject",
"description": "Original TFS project name",
"type": "WorkItemField",
"properties": {
"workItemFieldTypes": [ "String" ]
},
"validation": {
"dataType": "String",
"isRequired": true
}
},
{
"id": "TfsWorkItemId",
"description": "Original work item id",
"type": "WorkItemField" ,
"properties": {
"workItemFieldTypes": [ "Integer" ]
}
}
]
}
}
]
}
then in my App.ts file is this,
///<reference types="vss-web-extension-sdk" />
import { Controller } from "./control";
import * as ExtensionContracts from "TFS/WorkItemTracking/ExtensionContracts";
import { WorkItemFormService } from "TFS/WorkItemTracking/Services";
var control: Controller;
var provider = () => {
return {
onLoaded: (workItemLoadedArgs: ExtensionContracts.IWorkItemLoadedArgs) => {
control = new Controller();
}
}
};
VSS.register(VSS.getContribution().id, provider);
this is my Control.ts file,
`
private _initialize(): void {
this._inputs = VSS.getConfiguration().witInputs;
this._ServerFieldName = this._inputs["PreviousTFSServer"];
this._CollectionFieldName = this._inputs["TFSCollection"];
this._ProjectFieldName = this._inputs["TFSTeamProject"];
this._WorkItemIdFieldName = this._inputs["TfsWorkItemId"];
WitService.WorkItemFormService.getService().then(
(service) => {
Q.spread<any, any>(
[ service.getFieldValue(this._ServerFieldName),service.getFieldValue(this._CollectionFieldName),
service.getFieldValue(this._ProjectFieldName),service.getFieldValue(this._WorkItemIdFieldName)],
(server: string, collection: string, project:string, id: number) => {
this._view = new View(server,collection,project,id);
}, this._handleError
).then(null, this._handleError);
},
this._handleError);
}
private _handleError(error: string): void {
let errorView = new ErrorView(error);
}
}
`
Then I added a view.ts
export class View {
constructor(server: string, collection: string, project: string, id: number) {
// container div
if(server)
{
var Container = $("<div />");
var workItemUrl = $("<span></span>").text("Original work item");
var a = $("<a> </a>");
var url = 'server + "/" + collection + "/" + project + "/_workitemId?=" + String(id)'
a.attr("href", url );
a.attr("target", "_blank");
a.text("here.");
workItemUrl.append(a);
//$('body').empty().append(Container);
$(".events").append(workItemUrl);
}
}
}
<Input Id="PreviousTFSServer" Value="TriTech.Source.Server" />
<Input Id="TFSCollection" Value="TriTech.Source.Collection" />
<Input Id="TFSTeamProject" Value="TriTech.Source.Project" />
<Input Id="TfsWorkItemId" Value="TriTech.Source.Id" />
</Inputs>
</ControlContribution>
</Group>`
I started with the latest edition of the vsts-extension-ts-seed-simple-master package. Compiles and creates the extension but I'm not seeing any url or link.
What am I missing?
The WIT has been edited to use the extension.
Web debug shows it is being loaded,
{"id":"TriTech-Software-Systems.tritech-tfsurl-control.tritech-tfsurlcontrol-action","description":"Work Item fields to create url from","type":"ms.vss-work-web.work-item-form-control-group","targets":["ms.vss-work-web.work-item-form"],"properties":{"name":"tritech-tfsurl-control","uri":"index.html","height":90,"inputs":[{"id":"PreviousTFSServer","description":"The TFS server url that has the work item.","type":"WorkItemField","properties":{"workItemFieldTypes":["String"]},"validation":{"dataType":"String","isRequired":true}},{"id":"TFSCollection","description":"The original tfs collection name","type":"WorkItemField","properties":{"workItemFieldTypes":["String"]},"validation":{"dataType":"String","isRequired":true}},{"id":"TfsTeamProject","description":"Original TFS project name","type":"WorkItemField","properties":{"workItemFieldTypes":["String"]},"validation":{"dataType":"String","isRequired":true}},{"id":"TfsWorkItemId","description":"Original work item id","type":"WorkItemField","properties":{"workItemFieldTypes":["Integer"]}}],"::Attributes":16,"::Version":"0.1.20"}}
Thanks in advance.
I ended up using static values and got it working.
var Provider = () => {
this.ServerfieldName = "Source.Server";
this.CollectionfieldName = "Source.Collection";
this.ProjectfieldName = "Source.Project";
this.WorkItemIdfieldName = "Source.Id";
this._view = View;
return{
onLoaded: (WorkItemLoadedArgs: ExtensionContracts.IWorkItemLoadedArgs) => {
var deferred = Q.defer();
WorkItemFormService.getService().then(
(service) => {
Q.spread<any, any>(
[service.getFieldValue(this.ServerfieldName),service.getFieldValue(this.CollectionfieldName),
service.getFieldValue(this.ProjectfieldName),service.getFieldValue(this.WorkItemIdfieldName)],
(server: string, collection: string, project: string, workitemId: number) => {
var data =(`${server}/${collection}/${project}/_workitems#_a=edit&id=${workitemId}`);
if(server){
this._view = new View(data);
}
else{
$('body').empty().append("This is the original Work Item");
}
})
.catch(function (e) {deferred.reject(e)}
);
return deferred.promise; //.then(null);
}
)}
}
};
and used a view,
/// <reference path="../typings/index.d.ts" />
export class View {
constructor(public value:string) {
var Container = $("<div role='link'> </div>");
Container.addClass("Container");
Container.attr('tabindex', '0');
var rdiv = $("<div/>").addClass("rightDiv");
var ldiv = $("<div/>");
var help = $("<span></span>").text("Original Tfs work item ");
var a = $("<a> </a>");
a.attr("href", value);
a.attr("target", "_blank");
a.text("here.");
help.append(a);
ldiv.append(help);
Container.append(rdiv);
Container.append(ldiv);
$('body').empty().append(Container);
}
}

Resources